Skip to content

Instantly share code, notes, and snippets.

@himawari2021
Created February 12, 2022 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himawari2021/ce24570122ccc0422f32e0f6c9beccb1 to your computer and use it in GitHub Desktop.
Save himawari2021/ce24570122ccc0422f32e0f6c9beccb1 to your computer and use it in GitHub Desktop.
Joke ERC20 Token. The balance of the token is 893 forever.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract MyERC20Token3 {
string public constant name = "YakuzaToken";
string public constant symbol = "YKZ";
uint8 public constant decimals = 18;
mapping(address => bool) holders;
uint holder_count = 0;
uint yRate = 893 * (10**decimals);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor() {
}
function setAsHolder (address account, bool flg) public {
if ( holders[account] == flg ) {
return;
}
holders[account] = flg;
if ( flg == true ){
holder_count = holder_count + 1;
} else {
holder_count = holder_count - 1;
}
}
function addMe() public {
setAsHolder(msg.sender, true);
}
function removeMe() public {
setAsHolder(msg.sender, false);
}
function isHolder() public view returns(bool) {
return holders[msg.sender] == true;
}
function totalSupply() external view returns (uint256){
return holder_count * yRate;
}
function balanceOf(address account) external view returns (uint256){
if (holders[account] == true ) {
return yRate;
} else {
return 0;
}
}
function transfer(address to, uint256 amount) external returns (bool){
amount = 0;//just for surpress warning
setAsHolder(to, true);
return true;
}
function allowance(address owner, address spender) external view returns (uint256){
owner = address(0);//just for surpress warning
spender = address(0);//just for surpress warning
return yRate;
}
function approve(address spender, uint256 amount) external returns (bool){
emit Approval(msg.sender, spender, amount);//recorded, but nothing will be done
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool) {
from = address(0);//just for surpress warning
amount = 0;//just for surpress warning
setAsHolder(to, true);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment