Search code examples
solidityhardhat

Get chain name in hardhat (not chainId)


In hardhat, you can get the chainId by calling await getChainId(). However, I'm looking for the chain name. Is there a way to get the chain name without explicitly creating a mapping myself?

EDIT: You can only use this getChainId functionality with hardhat-deploy


Solution

  • Hardhat core package doesn't include any map from chainId to the chain name.

    But:

    • They have a mapping in the Etherscan integration package (GitHub source).
    • You can define the map in your application according to the EIP-155 where the list of chain IDs was first introduced, or the expanded list (anyone can add to this list - GitHub).