0

我尝试在 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);
}
4

1 回答 1

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

在此处输入图像描述

于 2017-12-17T18:25:17.740 回答