File size: 565 Bytes
31ea9b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @title SafeToken
/// @notice Solidity >=0.8 checked arithmetic (reverts on overflow/underflow).
contract SafeToken {
    mapping(address => uint256) public balanceOf;

    constructor(uint256 initial) {
        balanceOf[msg.sender] = initial;
    }

    // SAFE: 0.8 reverts on underflow/overflow automatically.
    function transfer(address to, uint256 value) external {
        require(to != address(0), "zero address");
        balanceOf[msg.sender] -= value;
        balanceOf[to] += value;
    }
}