0

I'm trying to test a custom ERC-20 token using Metamask and Hardhat.

After deploying my ERC-20 coin and minting some to one of the HardHat default accounts I try to add the token to Metamask. It is correctly able to fetch both the decimals of the token and the symbol, however it shows a balance of 0. (I've verified using Hardhat scripts that the balance of the given account is in fact NOT 0 (balanceOf returns 10))

Implementation of custom coin:

pragma solidity ^0.8.7;

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

contract BobCoin is ERC20 {
  constructor() ERC20("BobCoin", "BOB") {
  }

  function mint(address to, uint256 amount) public {
    _mint(to, amount);
  }
}

1 Answer 1

0

Are you sure your Metamask is connecting to the right network?

add hardhat network to Metamask

And import the test account?

import account to Metamask

3
  • Yes. I have double checked the account# and RPC url. It is able to connect to the RPC and it shows the correct ETH balance of 1000, as well as it is able to read the decimals/symbol of the ERC-20 contract.
    – Rudi
    Commented Jan 31, 2023 at 23:31
  • Maybe you can double check with Remix IDE, using the "At Address" option to the deployed contract address (instead of "Deploy" another), and call balance directly to see what comes out? I usually use it as a tool to do quick checks...
    – prc
    Commented Feb 1, 2023 at 19:24
  • I did a check by creating my own script using ethers.js and connecting to the blockchain that way, got the correct result there
    – Rudi
    Commented Feb 1, 2023 at 19:37

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.