0

I'm building an ERC20 token using OpenZeppelin's ERC20 contract. My token constructor looks like this:

    constructor()
        ERC20(
            "Token",
            "TKN"
        )
        Ownable()
    {
        require(msg.sender != address(0), "Cannot deploy from zero address");
        _mint(msg.sender, 18000000000000);
    }

When I try to deploy this contract to my local Ganache testnet using truffle, I receive the following error:

ERC20: mint to the zero address

Upon further investigation, I found that this error is thrown inside the ERC20 contract provided by OpenZeppelin. That's why I added that require statement in the constructor.

Weirdly, the constructor does not fail, which means msg.sender is not the Zero address. So why can't I mint the token?

(Solidity ^0.8.0)

2
  • 1
    Can you perhaps post a link to the entire contract? – hrkrshnn Jun 2 at 12:03
  • @hrkrshnn I figured it out, the problem is that I was minting tokens for miners and Ganache provides a 0 address for block.coinbase – Jake Jun 3 at 15:34

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.