0

我创建了一个 ERC23 代币并使用在线 remix solidity 编译器将其部署在 etherscan 上,一切似乎都很好,etherscan 跟踪器显示余额为 2 亿,但是无论我使用什么钱包,余额都显示为 0。你能发现问题吗? 以下是我使用的确切代码:

pragma solidity ^0.4.0;

contract Token {
    string internal _symbol;
    string internal _name;
    uint8 internal _decimals;
    uint internal _totalSupply = 200000000;
    mapping (address => uint) internal _balanceOf;
    mapping (address => mapping (address => uint)) internal _allowances;

function Token(string symbol, string name, uint8 decimals, uint totalSupply) public {
    _symbol = symbol;
    _name = name;
    _decimals = decimals;
    _totalSupply = totalSupply;
    }

function name() public constant returns (string) {
    return _name;
}

function symbol() public constant returns (string) {
    return _symbol;
}

function decimals() public constant returns (uint8) {
    return _decimals;
}

function totalSupply() public constant returns (uint) {
    return _totalSupply;
}

function balanceOf(address _addr) public constant returns (uint);
function transfer(address _to, uint _value) public returns (bool);
event Transfer(address indexed _from, address indexed _to, uint _value);

}

interface ERC20 {
    function transferFrom(address _from, address _to, uint 
_value) public returns (bool);
    function approve(address _spender, uint _value) public 
returns (bool);
    function allowance(address _owner, address _spender) public 
constant returns (uint);
    event Approval(address indexed _owner, address indexed 
_spender, uint _value);
}

interface ERC223 {
    function transfer(address _to, uint _value, bytes _data) public returns (bool);
    event Transfer(address indexed from, address indexed to, uint value, bytes indexed data);

}

contract ERC223ReceivingContract {
    function tokenFallback(address _from, uint _value, bytes 
    _data) public;
}

contract Maya_Coin is Token("MAYP", "Maya Preferred", 18, 200000000 * 10 ** 18), ERC20, ERC223 {

function MyFirstToken() public {
    _balanceOf[msg.sender] = _totalSupply;
}

function totalSupply() public constant returns (uint) {
    return _totalSupply;
}

function balanceOf(address _addr) public constant returns (uint) {
    return _balanceOf[_addr];
}

function transfer(address _to, uint _value) public returns (bool) {
    if (_value > 0 && 
        _value <= _balanceOf[msg.sender] &&
        !isContract(_to)) {
        _balanceOf[msg.sender] -= _value;
        _balanceOf[_to] += _value;
        Transfer(msg.sender, _to, _value);
        return true;
    }
    return false;
}

function transfer(address _to, uint _value, bytes _data) public returns (bool) {
    if (_value > 0 && 
        _value <= _balanceOf[msg.sender] &&
        isContract(_to)) {
        _balanceOf[msg.sender] -= _value;
        _balanceOf[_to] += _value;
        ERC223ReceivingContract _contract = ERC223ReceivingContract(_to);
            _contract.tokenFallback(msg.sender, _value, _data);
        Transfer(msg.sender, _to, _value, _data);
        return true;
    }
    return false;
}

function isContract(address _addr) returns (bool) {
    uint codeSize;
    assembly {
        codeSize := extcodesize(_addr)
    }
    return codeSize > 0;
}

function transferFrom(address _from, address _to, uint _value) public returns (bool) {
    if (_allowances[_from][msg.sender] > 0 &&
        _value > 0 &&
        _allowances[_from][msg.sender] >= _value &&
        _balanceOf[_from] >= _value) {
        _balanceOf[_from] -= _value;
        _balanceOf[_to] += _value;
        _allowances[_from][msg.sender] -= _value;
        Transfer(_from, _to, _value);
        return true;
    }
    return false;
}

function approve(address _spender, uint _value) public returns (bool) {
    _allowances[msg.sender][_spender] = _value;
    Approval(msg.sender, _spender, _value);
    return true;
}

function allowance(address _owner, address _spender) public constant returns (uint) {
    return _allowances[_owner][_spender];
}

}

4

1 回答 1

0

好吧,你可以调用这个方便的函数来拥有所有的令牌。:-)(其他任何人都可以调用它!)

function MyFirstToken() public {
    _balanceOf[msg.sender] = _totalSupply;
}

您可能打算将此作为构造函数,但名称不匹配。试试这个:

function Maya_Coin() public {
    _balanceOf[msg.sender] = _totalSupply;
}

或者更好的是,升级到最新版本的 Solidity 编译器,不再犯这个错误:

pragma solidity ^0.4.24;

// ...

constructor() public {
    _balanceOf[msg.sender] = _totalSupply;
}
于 2018-08-28T07:09:24.313 回答