以太坊ERC20令牌合同在通过重新部署的合同地址添加到钱包时返回0.00令牌余额

时间:2017-12-17 11:02:48

标签: token ethereum wallet smartcontracts remix

我尝试在混音编辑器中创建一个ERC20令牌智能合约,如下所示。

我能够部署智能合约并保留所有变量,但是当我将合同添加到wallet.ethereum.org合约页面(在监视令牌下)时,令牌余额显示为enter image description here 0令牌符号,名称,小数位都正确注册。

CODE SNIPPET:

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);
}

1 个答案:

答案 0 :(得分:1)

您在部署合同时未设置余额。我相信您打算使用FuncToken作为构造函数。

我清理了合同(我在这里使用0.4.17),部署它,然后导入Mist。现在看起来不错。

pragma solidity ^0.4.17;
//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 PerlToken(){
        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);
}

enter image description here