Fungible token precompile

Explain the fungible token precompile

The fungible token precompile allows conversions between native coins and ERC20 tokens. Read up on EVM assets vs native coinsto understand what a native coin is.

If a native coin doesn't have an ERC20 representation, then a "fungible token mapping" must be created for it. That can be done via the Cosmos msg MsgCreateFunToken.

nibid tx evm create-funtoken \
--bank-denom unibi \
--from validator \
--gas auto \
--gas-adjustment 1.5 \
-y | tx

You can verify if a fungible token mapping exists for a native coin by querying for fungible token mappings for a specific denom.

nibid q evm funtoken unibi | jq

Convert from native coin to ERC20

There are two mechanisms for converting from a native coin to ERC20:

  1. Cosmos msg MsgConvertCoinToEvm

  2. IFunToken.sendToEvm precompile call

The MsgConvertCoinToEvm msg can be called via command line:

The IFunToken.sendToEvm precompile call can be called via another EVM smart contract or directly via ethers.js:

Convert from ERC20 to native coin

Likewise, an ERC20 token can be converted back to a native coin if it has a fungible token mapping. The only mechanism to do this is via the IFunToken.sendToBank precompile call.

Last updated

Was this helpful?