我尝试在 remix 编辑器中创建 ERC20 代币智能合约,如下所示。
我能够部署智能合约并且所有变量都保留,但是当我将合约添加到 wallet.ethereum.org 合约页面(在监视令牌下)时,令牌余额显示为0,而令牌符号、名称、小数位都正确注册。
代码片段:
pragma solidity ^0.4.19;
//import './IERC20.sol';
//contract FuncToken is IERC20 {
interface IERC20 {
function totalsupply() constant returns(uint256 total);
function balanceof(address _owner)constant returns(uint256 balance);
function transfer(address to, uint256 value)returns(bool success);
function transferfrom(address from,address to,uint256 _value) returns(bool success);
function approve(address spender,uint256 value)returns(bool success);
function allowance(address owner,address spender)constant returns(uint256 remaining);
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
contract PerlToken{
uint public constant _totalSupply=100000;
string public constant symbol="perl";
string public constant name="PERL Token";
uint8 public constant decimals=3;
mapping(address=>uint256) balances;
mapping(address=>mapping(address =>uint256)) allowed;
function FuncToken(){
balances[msg.sender]=_totalSupply;
}
function totalsupply() constant returns(uint256 total){
return _totalSupply;
}
function balanceof(address _owner)constant returns(uint256 balance){
return balances[_owner];
}
function transfer(address to, uint256 value)returns(bool success){
require(
balances[msg.sender]>=_value && _value>0
);
balances[msg.sender] -=_value;
balances[_to] +=+_value;
Transfer(msg.sender,_to,_value);
return true;
}
function transferfrom(address from,address to,uint256 _value) returns(bool success){
require(
allowed[_from][msg.sender]>=_value
&& balances[_from]>=_value
&& _value>0
);
balances[_from]-=_value;
balances[_to]+= _value;
allowed[_from][msg.sender]-=_value;
Transfer(_from,_to,_value);
return true;
}
function approve(address spender,uint256 value)returns(bool success){
allowed[msg.sender][_spender]=_value;
Approval(msg.sender,_spender,_value);
return true;
}
function allowance(address owner,address spender)constant returns(uint256 remaining){
allowed[_owner][_spender];
}
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}