728x90
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";
contract Token {
using SafeMath for uint256;
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _totalSupply) public {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _totalSupply;
balanceOf[msg.sender] = totalSupply;
}
function transfer(address _to, uint256 _value) public {
require(balanceOf[msg.sender] >= _value && _value > 0, "Insufficient balance");
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
}
function approve(address _spender, uint256 _value) public {
allowance[msg.sender][_spender] = _value;
}
function transferFrom(address _from, address _to, uint256 _value) public {
require(balanceOf[_from] >= _value && allowance[_from][msg.sender] >= _value && _value > 0, "Insufficient balance or allowance");
balanceOf[_from] = balanceOf[_from].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
}
}
728x90
'호그와트' 카테고리의 다른 글
웹 fuzzer 응애 (0) | 2023.01.05 |
---|---|
간단한 시뮬레이션을 구성하는 방법 (0) | 2023.01.04 |
난 몰러요 그런 거 나는 잘 몰러유~ (0) | 2023.01.04 |
Put my sneakers on (0) | 2023.01.03 |
2023년이 왔어요 (0) | 2023.01.03 |