Address Conversion

MANTRA Chain uses the Bech32 address format, which contains a human-readable format for encoding addresses (addresses start with mantra1).

This format is used to represent addresses in a way that is more user-friendly and less error-prone than traditional hexadecimal formats (addresses start with 0x). You can find Bech32 details in the BIP-0173.

MANTRA Chain also supports EVM module, which is compatible with the Ethereum Virtual Machine (EVM) and uses the standard hexadecimal address format. With the same private key, you can derive both EVM address and Bech32 address with coin type 60.

PLEASE BE CAUTION: You can convert and use the address only if the key type is cosmos.evm.crypto.v1.ethsecp256k1.PubKey (check Auth Information in mantrascan address page). Otherwise, EVM wallets cannot derive the address, which means you can never use the address.

In order to convert between a Bech32 format address and an EVM format address, we provide the following sample codes below:

Using the CLI

Download the latest binary from MANTRA Chain Releases page

Bech32 to EVM address

Basic command:

$ mantrachaind debug addr mantra19nj8hate4y2w0va698uygf2jj4y6xq42k8a7ed

Belows are outputs of the above command:

Address: [44 228 123 245 121 169 20 231 179 186 41 248 68 37 82 149 73 163 2 170]
Address (hex): 2CE47BF579A914E7B3BA29F84425529549A302AA
Bech32 Acc: mantra19nj8hate4y2w0va698uygf2jj4y6xq42k8a7ed
Bech32 Val: mantravaloper19nj8hate4y2w0va698uygf2jj4y6xq42juus4g
Bech32 Con: mantravalcons19nj8hate4y2w0va698uygf2jj4y6xq42x00vef

Command with better output:

output:

EVM address to Bech32

The prefix 0x is needed to be removed:

outputs:

Rust Implementation

Check test cases for examples of how to use the functions.

JavaScript Implementation

Test cases

Python Implementation

From mantra1 to 0x

Vice versa, from 0x to mantra1

Last updated