帮我写一个erc20 合约
时间: 2023-03-06 14:08:03 浏览: 135
ERC20合约调用demo
我可以为您提供一个erc20 合约的范例,您可以根据您的需求进行修改:pragma solidity ^0.5.11;contract ERC20 {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply; event Transfer(address indexed _from, address indexed _to, uint256 _value); constructor(
uint256 initialSupply,
string memory tokenName,
uint8 decimalUnits,
string memory tokenSymbol
) public {
_balances[msg.sender] = initialSupply;
totalSupply = initialSupply;
name = tokenName;
symbol = tokenSymbol;
decimals = decimalUnits;
} function balanceOf(address tokenOwner) public view returns (uint256 balance) {
return _balances[tokenOwner];
} function transfer(address to, uint256 tokens) public returns (bool success) {
_balances[msg.sender] = _balances[msg.sender].sub(tokens);
_balances[to] = _balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
} function approve(address spender, uint256 tokens) public returns (bool success) {
_allowed[msg.sender][spender] = tokens;
return true;
} function transferFrom(address from, address to, uint256 tokens) public returns (bool success) {
_balances[from] = _balances[from].sub(tokens);
_balances[to] = _balances[to].add(tokens);
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(tokens);
emit Transfer(from, to, tokens);
return true;
} function allowance(address tokenOwner, address spender) public view returns (uint256 remaining) {
return _allowed[tokenOwner][spender];
}
}
阅读全文