IBC ERC-20 function is to associate the native token in Cosmos ecosystem with the ERC-20 token in OKTC ecosystem through Cosmos IBC cross-chain protocol to realize asset cross-chain conversion. It mainly includes two parts.
a. Cross-chaining the native token from Cosmos ecosystem to OKTC, becoming OKTC EVM ERC-20 token and participating in OKTC EVM ecosystem; at the same time, this OKTC ERC-20 token can be returned to Cosmos ecosystem chain via the IBC cross-chaining protocol in its original way, converting it into cosmos native token.
b. The OKTC native EVM ERC-20 token is cross-chained to Cosmos ecosystem as a native token; at the same time, you can also return this cosmos native token to OKTC via the IBC cross-chain protocol in its original way and become an EVM ERC-20 token.
Note the distinction between the above two cases. The token in one is the native token from other cosmos chains outside of OKTC; the token in two is the ERC-20 token that already exists on OKTC, not from the automatic deployment in one.
To transfer the native token from Cosmos ecosystem to OKTC as ERC-20 token through IBC, you need to deploy the corresponding ERC-20 contract on OKTC. This ERC-20 contract has two sources:
Automatic deployment within the OKTC chain
OKTC has a built-in IBC ERC-20 contract that implements the necessary interfaces required. If the OKTC ERC-20 module parameter enable_auto_deployment=true
and the IBC comes across the chain with a cosmos native token, the contract is automatically deployed and the mapping of that ibc token (from the cosmos native token) to the contract address is maintained, converting the native token into an equal number of ERC-20 tokens to the target account.
Manual deployment by the project owner/user
If the project owner has personalized functional requirements for the ERC-20 contract, they can write their own contract code, deploy it to OKTC, and implement the mapping relationship between IBC token and ERC-20 contract by initiating a TokenMappingProposal. At this point, please make sure to refer to the built-in contract and strictly implement the following in order to achieve this function accurately:
mint_by_okc_module
send_to_ibc
__OKCSendToIbc
By default, the cosmos native token from IBC cross-chain to OKTC will remain as ibc token in OKTC, but denom will change to ibc/xxxxx
as per IBC protocol rules.
OKTC will convert the IBC token to ERC-20 token only in the following two cases:
OKTC turns on automatic contract deployment
OKTC turns on auto-deployment via the ERC-20 module parameter enable_auto_deployment=true.
OKTC chain has a mapping relationship between the corresponding ibc token and the ERC-20 contract
Enable it by initiating a TokenMappingProposal. Otherwise, the cosmos native token coming from IBC cross-chain will remain as ibc token in OKTC, i.e. ibc/xxxxx.
According to the above description, Cosmos native token has two states after cross-chaining to OKTC and requires different ways to transfer the token back to the source chain.
send_to_ibc
of the corresponding ERC-20 contract, which simply provides the receiving account address and transfer amount of the source chain, and then the ERC-20 token will be returned to the source chain and become the original cosmos native token.Support native OKTC ERC-20 token transfer out through IBC cross-chain, ERC-20 contract code must refer here to achieve the following.
mint_by_okc_module
send_native20_to_ibc
__OKCSendNative20ToIbc
If you need to support IBC cross-chain transfer, in addition to the method and event mentioned above, you must also initiate a proposal to establish a mapping between the ERC-20 contract address and OKTC token, which will take effect after the vote. The operation example is as follows.
exchaincli tx gov submit-proposal token-mapping okb 0x45dD91b0289E60D89Cec94dF0Aac3a2f539c514a --title="token-mapping" --description=" token-mapping" --deposit 1000okt --from=userA
okb
is the specified token name on OKTC, you can use any value that conforms to the coin name specification.0x45dD91b0289E60D89Cec94dF0Aac3a2f539c514a
is the ERC-20 contract address. This can also be filled with ""
to indicate the deletion of an already existing token mapping relationship.You can query the existing mappings on OKTC chain by exchaincli query ERC-20 token-mapping
.
Once the ERC-20 contract and mapping are ready, you can start to operate the ERC-20 IBC cross-chain.
Call the contract send_native20_to_ibc
to specify the target link receiving account address, transfer quantity, IBC portID and IBC channelID. where the portID and channelID can be found here.
After the ERC-20 transfer out across the chain, it exists in the form of cosmos ibc token on the target chain (if the target chain does not do special processing). At this time, you can transfer the token back to OKTC by using the IBC transfer tool provided by the target chain, such as keplr wallet, cross-chain bridge, etc., and specify the corresponding channel and port (the channel and port corresponding to the transfer out). After OKTC receives the transferred token