Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Created October 22, 2021 16:36
Show Gist options
  • Save z0r0z/d2d4386daa319b2c29fe8ca63f24c9ba to your computer and use it in GitHub Desktop.
Save z0r0z/d2d4386daa319b2c29fe8ca63f24c9ba to your computer and use it in GitHub Desktop.
token.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.9;
contract Token {
uint256 totalSupply;
string public name;
string public symbol;
address public owner;
mapping(address => uint256) balanceOf;
mapping(address => mapping(address => uint256)) allowance;
event Transfer(address indexed from, address indexed to, uint256 indexed value);
event Approval(address indexed from, address indexed to, uint256 indexed value);
constructor(string memory name_, string memory symbol_, uint256 supply) {
name = name_;
symbol = symbol_;
totalSupply = supply;
balanceOf[msg.sender] = supply;
owner = msg.sender;
emit Transfer(address(0), msg.sender, supply);
}
function approve(address spender, uint256 value) external {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
}
function transfer(address to, uint256 value) external returns (bool) {
balanceOf[msg.sender] -= value;
balanceOf[to] += value;
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external returns (bool) {
allowance[from][msg.sender] -= value;
balanceOf[msg.sender] -= value;
balanceOf[to] += value;
emit Transfer(from, to, value);
return true;
}
function mint(address to, uint256 value) external {
require(msg.sender == owner, "!owner");
balanceOf[to] += value;
totalSupply += value;
emit Transfer(address(0), to, value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment