FT Contract (ERC20)
ERC20
Last updated
ERC20
Last updated
//SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint);
function transfer(address recipient, uint amount) external returns (bool);
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
function approve(address spender, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
// ======================================================
// OPTIONAL
// ======================================================
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "./IERC20.sol";
contract ERC20 is IERC20 {
//constant
uint8 constant public decimals = 18;
//attribute
string public name;
string public symbol;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
constructor(string memory _name, string memory _symbol, uint256 _totalSupply) {
name = _name;
symbol = _symbol;
uint amount = _totalSupply * 1 ether;
totalSupply = amount;
balanceOf[msg.sender] = amount;
emit Transfer(address(0), msg.sender, amount);
}
function transfer(address to, uint256 amount) external virtual returns (bool success) {
_transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) external virtual returns (bool success) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) external virtual returns (bool success) {
uint currentAllowance = allowance[sender][msg.sender];
require(currentAllowance >= amount, "ERC20: insufficient allownace");
_approve(sender, msg.sender, currentAllowance - amount);
_transfer(sender, recipient, amount);
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer sender the zero address");
require(recipient != address(0), "ERC20: transfer recipient the zero address");
require(balanceOf[sender] >= amount, "ERC20: transfer amount exceeds balance");
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _approve(address owner, address spender, uint256 amount) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
allowance[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
balanceOf[account] += amount;
totalSupply += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
require(balanceOf[account] >= amount, "ERC20: burn amount exceeds balance");
balanceOf[account] -= amount;
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
contract Ownable {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
address private _owner;
modifier onlyOwner() {
require(owner() == msg.sender, "Ownable: caller is not the owner");
_;
}
constructor() {
_transferOwnership(msg.sender);
}
function owner() public view returns (address) {
return _owner;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
//SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "./ERC20.sol";
import "./Ownable.sol";
contract RedCatCoin is ERC20, Ownable {
constructor(string memory _name, string memory _symbol, uint _totalSupply) ERC20(_name, _symbol, _totalSupply) {
}
function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}
function burn(address account, uint256 amount) external onlyOwner {
_burn(account, amount);
}
}
https://testnet.bscscan.com/address/0x8963a186664c23f48a5e670eee76459714c4d49b