Skip to main content
Tutorial GitHub Repository This tutorial demonstrates how to convert between a hex-based ERC20 token address and a Cosmos coin denom.

Prerequisites

Project Setup

First, create a new directory for your project.
Next, initialize the project and create an index.js file in a src directory.

Development

For this tutorial, assume that you have an ERC20 token address 0x5E5f1a92eECA58053E8364630b66763aa6265Ab0 that you want to convert to a Cosmos coin denom, and then convert it back to an ERC20 token address. First, initialize the variable for the chain’s REST endpoint and the ERC20 token address.
src/index.js

ERC20 to Cosmos Denom

To actually do the conversion, use the REST’s /minievm/evm/v1/denoms/{contractAddress} endpoint.
src/index.js
If the address is a valid ERC20 token address, the response just returns the token’s Cosmos coin denom.

Cosmos Denom to ERC20 Address

To convert a Cosmos coin denom back to an ERC20 token address, use the REST’s /minievm/evm/v1/contracts/by_denom?denom={denom} endpoint.
src/index.js
If the denom is a valid Cosmos coin denom, the response just returns the token’s ERC20 token address.
The full code for the script, including the section to actually call the function is as follows:
src/index.js
If you run this script, you should see the following output: