Skip to content

Instantly share code, notes, and snippets.

@guaerjia
Created August 25, 2021 02:22
Show Gist options
  • Save guaerjia/5fb4a16b4189133ecd497b22b1c3c5d3 to your computer and use it in GitHub Desktop.
Save guaerjia/5fb4a16b4189133ecd497b22b1c3c5d3 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
pragma solidity ^0.6.0;
import "./erc20.sol";
contract pcCoin is ERC20 {
address public _owner;
uint256 _totalSupply;
mapping(address=>uint256) _balances;
mapping(address=>mapping(address=>uint256)) _approves;
event Transfer(address indexed _tran, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
constructor(uint256 totalSupply) public {
_totalSupply = totalSupply;
_owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == _owner);
_;
}
function airDrop(address _to, uint256 _value) onlyOwner public {
require(_to != address(0) && _value > 0);
_balances[_to] += _value;
_totalSupply += _value;
}
function totalSupply() override public view returns(uint256 totalSupply) {
totalSuppy = totalSupply;
return totalSupply;
}
function balanceOf(address _owner) override public view returns(uint balance) {
require(_owner != address(0), "owner should not be empty!"); // address(0) 空地址
return _balances[_owner];
}
function transfer(address _to, uint _value) override public returns(bool success) {
require(_to != address(0), "_to should not be empty!");
require(_balances[msg.sender] >= _value || _value > 0, "value should be valid!!");
_balances[msg.sender] -= _value;
_balances[_to] += _value;
success = true;
emit Transfer(msg.sender, _to, _value);
return success;
}
function transferFrom(address _from, address _to, uint _value) override public returns(bool success) {
require(_from != address(0) && _to != address(0));
require(_approves[_from][msg.sender] >= _value);
_approves[_from][msg.sender] -= _value;
_balances[_to] += _value;
emit Transfer(_from, _to, _value);
success = true;
return success;
}
function approve(address _spender, uint _value) override public returns(bool success) {
require(_spender != address(0));
require(_balances[msg.sender] >= _value || _value>0);
_approves[msg.sender][_spender] += _value;
_balances[msg.sender] -= _value;
emit Approval(msg.sender, _spender, _value);
success = true;
return success;
}
function allowance(address _owner, address _spender) override public view returns(uint remaining) {
remaining = _approves[_owner][_spender];
return remaining;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment