0

I set up a private chain using geth v1.8.27, then deployed an erc20 contract in solidity 0.5.0 complied using the 0.5.7+commit.6da8b019 version of compiler. After the transaction was mined, I tried to get the name, symbol, decimals and totalSupply of the token on the geth console, but it failed to return the correct results and had some errors shown as follows.

> mytoken.name()
Error: new BigNumber() not a base 16 number: 
    at L (bignumber.js:3:2876)
    at bignumber.js:3:8435
    at a (bignumber.js:3:389)
    at web3.js:1110:23
    at web3.js:1634:20
    at web3.js:826:16
    at map (<native code>)
    at web3.js:825:12
    at web3.js:4080:18

> mytoken.symbol()
Error: new BigNumber() not a base 16 number: 
    at L (bignumber.js:3:2876)
    at bignumber.js:3:8435
    at a (bignumber.js:3:389)
    at web3.js:1110:23
    at web3.js:1634:20
    at web3.js:826:16
    at map (<native code>)
    at web3.js:825:12
    at web3.js:4080:18

> mytoken.decimals()
0
> mytoken.totalSupply()
0

I am sure that the contract was deployed successfully as I can get the transaction and transaction receipt as shown below.

> eth.getTransaction('0xc84f6d43522c591144a0c17e1cc5eb9b9cae6beb2f7cf4cf64422ed169c34c9c')
{
  blockHash: "0x4c7b65d82f3c7393aa9c4aa4f17217efa6313e815f6085acb0f8266bbef9dfe6",
  blockNumber: 7,
  from: "0xf930743f095eb3ea24af041b77db5a3af873be1b",
  gas: 4700000,
  gasPrice: 1000000000,
  hash: "0xc84f6d43522c591144a0c17e1cc5eb9b9cae6beb2f7cf4cf64422ed169c34c9c",
  input: "0x60806040526040518060400160405280600781526020017f4d79546f6b656e000000000000000000000000000000000000000000000000008152506000908051906020019061004f92919061012c565b506040518060400160405280600381526020017f4d595400000000000000000000000000000000000000000000000000000000008152506001908051906020019061009b92919061012c565b506006600260006101000a81548160ff021916908360ff160217905550600260009054906101000a900460ff1660ff16600a0a600a026003553480156100e057600080fd5b50600354600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506101d1565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061016d57805160ff191683800117855561019b565b8280016001018555821561019b579182015b8281111561019a57825182559160200191906001019061017f565b5b5090506101a891906101ac565b5090565b6101ce91905b808211156101ca5760008160009055506001016101b2565b5090565b90565b610b17806101e06000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c8063313ce56711610066578063313ce5671461022557806370a082311461024957806395d89b41146102a1578063a9059cbb14610324578063dd62ed3e1461038a57610093565b806306fdde0314610098578063095ea7b31461011b57806318160ddd1461018157806323b872dd1461019f575b600080fd5b6100a0610402565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100e05780820151818401526020810190506100c5565b50505050905090810190601f16801561010d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101676004803603604081101561013157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104a4565b604051808215151515815260200191505060405180910390f35b610189610596565b6040518082815260200191505060405180910390f35b61020b600480360360608110156101b557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105a0565b604051808215151515815260200191505060405180910390f35b61022d61080b565b604051808260ff1660ff16815260200191505060405180910390f35b61028b6004803603602081101561025f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610822565b6040518082815260200191505060405180910390f35b6102a961086b565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102e95780820151818401526020810190506102ce565b50505050905090810190601f1680156103165780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103706004803603604081101561033a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061090d565b604051808215151515815260200191505060405180910390f35b6103ec600480360360408110156103a057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a64565b6040518082815260200191505060405180910390f35b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561049a5780601f1061046f5761010080835404028352916020019161049a565b820191906000526020600020905b81548152906001019060200180831161047d57829003601f168201915b5050505050905090565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600354905090565b600081600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156105ee57600080fd5b81600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561067757600080fd5b81600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b6000600260009054906101000a900460ff16905090565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109035780601f106108d857610100808354040283529160200191610903565b820191906000526020600020905b8154815290600101906020018083116108e657829003601f168201915b5050505050905090565b600081600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561095b57600080fd5b81600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490509291505056fea165627a7a723058206f9b0d896518b57f7f765d43ec152a6e2e75aec83758e7ed9e9bf98bb153a1280029",
  nonce: 0,
  r: "0x42280d7a7dffad5eefef9a15b586121be89966b98fdc32df04ad81926203ad70",
  s: "0x38253019b0553ae69f20e3c9927acc64e90e84c7f0454c3aaf1e027253404345",
  to: null,
  transactionIndex: 0,
  v: "0x38",
  value: 0
}

> eth.getTransactionReceipt('0xc84f6d43522c591144a0c17e1cc5eb9b9cae6beb2f7cf4cf64422ed169c34c9c')
{
  blockHash: "0x4c7b65d82f3c7393aa9c4aa4f17217efa6313e815f6085acb0f8266bbef9dfe6",
  blockNumber: 7,
  contractAddress: "0x5634f118ddf2f3a2e372d92e7dc3fdb86b70b2d9",
  cumulativeGasUsed: 939517,
  from: "0xf930743f095eb3ea24af041b77db5a3af873be1b",
  gasUsed: 939517,
  logs: [],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  root: "0x7d936d96dddb1e859cc05eebf83e5907dbec8aa27951bceddc932ca5ceb05322",
  to: null,
  transactionHash: "0xc84f6d43522c591144a0c17e1cc5eb9b9cae6beb2f7cf4cf64422ed169c34c9c",
  transactionIndex: 0
}

After that, I rewrote the erc20 contract in solidity 0.4.0 (almost the same except some differences in argument data types, event invocation prefix "emit" and the constructor), compiled it using the 0.4.20+commit.3155dd80 version of compiler and tried to deploy it on the same private chain. It succeeded. The two contracts are pasted below.

The Contract in solidity 0.5.0

pragma solidity ^0.5.0;

contract MyToken{
    string private _name = "MyToken";
    string private _symbol = "MYT";
    uint8 private _decimals = 6;
    uint256 private _totalSupply = 10 * (10 ** uint256(_decimals));
    mapping(address=>uint256) private _balances;
    mapping(address=>mapping(address=>uint256)) private _allowances;

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);

    constructor() public{
        _balances[msg.sender] = _totalSupply;
    }

    function name() public view returns (string memory name){
        name = _name;
    }

    function symbol() public view returns (string memory symbol){
        symbol = _symbol;
    }

    function decimals() public view returns (uint8 decimals){
        decimals = _decimals;
    }

    function totalSupply() public view returns (uint256 totalSupply){
        totalSupply = _totalSupply;
    }

    function balanceOf(address _owner) public view returns (uint256 balance){
        balance = _balances[_owner];
    }

    function transfer(address _to, uint256 _value) public returns (bool success){
        require(_balances[msg.sender] >= _value);
        _balances[msg.sender] -= _value;
        _balances[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
        success = true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){
        require(_balances[_from] >= _value);
        require(_allowances[_from][msg.sender] >= _value);
        _balances[_from] -= _value;
        _allowances[_from][msg.sender] -= _value;
        _balances[_to] += _value;
        emit Transfer(_from, _to, _value);
        success = true;
    }

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

    function allowance(address _owner, address _spender) public view returns (uint256 remaining){
        remaining = _allowances[_owner][_spender];
    }
}

The Contract in solidity 0.4.0

pragma solidity ^0.4.0;

contract MyToken{
    string private _name = "MyToken";
    string private _symbol = "MYT";
    uint8 private _decimals = 6;
    uint256 private _totalSupply = 10 * (10 ** uint256(_decimals));
    mapping(address=>uint256) private _balances;
    mapping(address=>mapping(address=>uint256)) private _allowances;

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);

    function MyToken(){
        _balances[msg.sender] = _totalSupply;
    }

    function name() public view returns (string name){
        name = _name;
    }

    function symbol() public view returns (string symbol){
        symbol = _symbol;
    }

    function decimals() public view returns (uint8 decimals){
        decimals = _decimals;
    }

    function totalSupply() public view returns (uint256 totalSupply){
        totalSupply = _totalSupply;
    }

    function balanceOf(address _owner) public view returns (uint256 balance){
        balance = _balances[_owner];
    }

    function transfer(address _to, uint256 _value) public returns (bool success){
        require(_balances[msg.sender] >= _value);
        _balances[msg.sender] -= _value;
        _balances[_to] += _value;
        Transfer(msg.sender, _to, _value);
        success = true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){
        require(_balances[_from] >= _value);
        require(_allowances[_from][msg.sender] >= _value);
        _balances[_from] -= _value;
        _allowances[_from][msg.sender] -= _value;
        _balances[_to] += _value;
        Transfer(_from, _to, _value);
        success = true;
    }

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

    function allowance(address _owner, address _spender) public view returns (uint256 remaining){
        remaining = _allowances[_owner][_spender];
    }
}

Could anyone give me some ideas how to solve this problem?

  • Have you enabled the new constantinople opcodes in your private chain? Since a recent solc 0.5.xx it uses the new shift opcodes and contracts will fail with invalid opcodes in blockchains without them. – Ismael May 5 at 19:59
  • Thank you! I got it. – NUCKevin May 7 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.