Search code examples
ethereumsoliditytruffleerc20

ERC20 Token successfully deploy without owner


I have deployed my ERC20 token contract onto the Rospten network, when I checked on the Etherscan and I can't see my account appear in the Holder list. Why is that ?

0x88BAcDE95d741729aaF399e75ac14dB971f72f30

Please advise

Snapshot

ERC20 Token source code


Solution

  • Etherscan determines token balances by watching for the Transfer event. In your constructor function:

    constructor()
        public
    {
        totalSupply_ = INITIAL_SUPPLY;
        balances[msg.sender] = totalSupply_;
    }
    

    you are assigning the totalSupply_ to msg.sender's balance, but without emitting an event Etherscan is unaware of this.

    The typical way to handle a token minting event is to show the transfer as originating from 0x00. Add the following line to the constructor and the balance should display properly on Etherescan and other block explorers.

    emit Transfer(address(0), msg.sender, totalSupply_);