2

Given this contract using Openzeppelin lib:

contract Token is StandardToken, Ownable {

    string public name = "";
    string public symbol = "";
    uint8 public decimals = 18;

    constructor(string _name, string _symbol, uint256 _supply, address creator) public {
        owner = creator;
        name = _name;
        symbol = _symbol;
        totalSupply_ = _supply;
        balances[owner] = totalSupply_;
        Transfer(0x0, owner, balances[owner]);
    }

truffle(rinkeby)> Token.at('0xdc190d1ac0355bc3b9b4bba96738484cd07690ea').balanceOf.call('0xD587f68bE865c8a4F34CC2a53150dE0DA5771957'); BigNumber { s: 1, e: 2, c: [ 665 ] }

Metamask and Coinbase wallet report 0 balance when you add it as a custom token with the owner address.

Running truffle console, the owner is indeed correct and running balanceOf reports correct balance.

Is it a problem because it is assigned in the constructor and there is no transfer tx? So the problem is with the wallets or in my code?

The code passes all truffle tests for balances etc before deployed.

Note that this contract is deployed from a "mother" contract that's why owner is not msg.sender but why would that be a problem?

Tried updating with a Transfer event to be compatible with the ERC20 protocol but didn't change anything.

14
  • Are you sure you are checking token balance and not Ether balance? Also, OpenZeppelin doesn't have a variable tokenURI_ as far as I know. Commented Oct 3, 2018 at 9:43
  • tokenURI is my addition but irrelevant. Yes I am checking from truffle console balanceOf(address) on the contract and it's above 0. Then I add it as a custom token in both Metamask and Coinbase Wallet and the balance is zero.
    – arisalexis
    Commented Oct 3, 2018 at 9:50
  • What network are you using? i guess you're sure that the network you use is the same? One thing you could try is emit a custom Event in the constructor with value of balances[owner] and see what it gives you. Commented Oct 3, 2018 at 9:58
  • Could you share truffle.js and command which you use to run truffle console?
    – Aquila
    Commented Oct 3, 2018 at 10:09
  • 1
    @arisalexis The amount transfered is very small it is possible that Metamask will not show such small value. I cannot check coinbase.
    – Ismael
    Commented Oct 4, 2018 at 17:35

1 Answer 1

1

Turns out that invoking the above constructor with a normal number from web3js 1.0 converts the uint initial_supply to a much smaller number.

Calling it with web3.utils.toWei(number,"ether") is working.

Metamask and coinbase wallet were reporting 0 because the number was too small.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.