Created
March 1, 2022 18:37
-
-
Save qnxdev/52fe33ec960219d10038499a00530e51 to your computer and use it in GitHub Desktop.
My Test Token Contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.12; | |
contract MyTestToken { | |
mapping(address => uint) public balances; | |
mapping(address => mapping(address => uint)) public allowance; | |
uint public totalSupply = 10000 * 10 ** 18; | |
string public name = 'My Test Token'; | |
string public symbol = 'MTT'; | |
uint public decimals = 18; | |
event Transfer(address indexed from, address indexed to, uint amount); | |
event Approval(address indexed owner, address indexed spender, uint amount); | |
constructor() { | |
balances[msg.sender] = totalSupply; | |
} | |
function balanceOf(address owner) public view returns(uint) { | |
return balances[owner]; | |
} | |
function transfer(address to, uint amount) public returns(bool) { | |
require(balanceOf(msg.sender) >= amount, 'Balance too low'); | |
balances[to] += amount; | |
balances[msg.sender] -= amount; | |
emit Transfer(msg.sender, to, amount); | |
return true; | |
} | |
function transferFrom(address from, address to, uint amount) public returns(bool){ | |
require(balanceOf(from) >= amount, 'Balance too low'); | |
require(allowance[from][msg.sender] >= amount, 'Allowance too low'); | |
balances[to] += amount; | |
balances[from] -= amount; | |
emit Transfer(from, to, amount); | |
return true; | |
} | |
function approve(address spender, uint amount) public returns(bool) { | |
allowance[msg.sender][spender] = amount; | |
emit Approval(msg.sender, spender, amount); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment