Created custom ERC20 contract, balanceOf msg.sender is zero

Advertisements

I’ve created a ERC20 contract in Remix:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(string memory name, string memory symbol) ERC20(name, symbol) {
        _mint(msg.sender, 1002000);
    }
}

Then I deployed it:

But the balance of msg.sender is zero:

Does anyone know what’s wrong?

>Solution :

I just tried your code and it works perfectly like intended.

It is important, that you compile the correct contract using Remix, see my attached picture. You need to choose the contract "MyToken". I guess you could have deployed the contract "ERC20 – @openzeppelin/contracts/token/ERC20/ERC20.sol" which would lead to the behaviour you mentioned.

compile "MyToken" in Remix

Leave a ReplyCancel reply