Converting ICRC to ERC20
Last updated
Last updated
The sequence diagram details the process involved in converting ICRC tokens to ERC20 tokens is shown below:
The in-depth explanation of each step is as follows:
User Interaction with ICRC Ledger:
The user initiates the process by either transferring ICRC tokens to a specific subaccount or approving the BitoBridge Hub canister to access their tokens. This is represented by the transfer(subaccount)/approve(hub_canister)
message, where the ICRC Ledger confirms the action with an ok
response.
BitoBridge Hub Processing:
After receiving confirmation from the ICRC Ledger, the user interacts with the BitoBridge Hub, specifying the target blockchain for the token bridge via the bridge(target_chain)
function call.
The BitoBridge Hub then performs several queries to determine necessary fees and exchange rates:
query(target_chain_gas_fee)
retrieves the current gas fees for the target chain.
query(icp_in_usd price)
fetches the current exchange rate of ICP to USD.
query(target_chain_native_token_in_usd price)
determines the price of the target chain’s native token in USD.
query(token_in_icp price)
gets the price of the ICRC token in ICP.
The results of these queries are used to calculate the total_gas_fee()
needed for the transaction.
Token Transfer Execution:
Once all fees and rates are confirmed, the BitoBridge Hub commands the ICRC Ledger to perform the actual token transfer to the target blockchain account via the transfer_from(user_account,target_chain)
function.
The ICRC Ledger returns a block_index
indicating the transaction's block number or confirmation status.
Minting Process:
With the transaction confirmed, the BitoBridge Hub dispatches a minting task to the BitoBridge Minter using the dispatch(target_chain_block_index)
command.
The BitoBridge Minter then communicates with the target chain’s RPC node through call eth_sendRawTransaction()
to initiate the minting of the equivalent ERC20 tokens on the Ethereum blockchain.
ERC20 Token Minting:
Once the Ethereum network processes the transaction, the ERC20 tokens are minted directly to the user's address on the Ethereum blockchain. The completion of this process is confirmed back to the BitoBridge Minter via the ok
response from the RPC node.
The BitoBridge Minter completes the process by signaling the BitoBridge Ledger to finalize the minting with mintTo()
.
Throughout this process, BitoBridge’s core canisters interact with services like XRC and ICPSwap for price data and RPC nodes for blockchain interactions, ensuring that all actions are based on the most accurate and current information available. This integration facilitates a seamless and secure conversion of ICRC tokens to ERC20 tokens, maintaining the integrity and traceability of the transaction across blockchains.