CrossChain Precompiled
Address: 0x0000000000000000000000000000000000001004
Interface: ICrossChain
ABI: ICrossChain
Overview: Use crossChain precompiled contract to call some functions of the crossChain module, such as: crossChain, cancelSendToExternal, etc.
Introduction
Before accessing the cross-chain precompiled contract, the cross-chain operations of the precompile can be called via the hook method.
Using a simple example, a specific event, say: CrossChain
, is added to a token contract; and when the token contract is deployed and successfully executes a transaction that emits this specific event, the EVM module in f(x)Core will parse the event generated by the contract. If the emitted event is relevant to the cross-chain precompiled contract, the corresponding cross-chain logic will be executed based on the data in the CrossChain
event.
Use-case Reference
Low-level Call (Sample contract)
Encode.crossChain
encodes the crossChain
method and its parameters using abi.encodeWithSignature
to create a bytes array that will be sent to the cross-chain precompiled contract to invoke the corresponding crossChain
method along with the encoded parameters.
Contract Interface (Sample Contract)
The contract interface method is relatively simple. It only needs to define the contract interface with the appropriate method, and parameters are simply passed into it like a regular call to another contract’s function. It does not require encoding the method and its parameters since the contract interface takes care of that, however the reason cannot be obtained in the event of a failure.
The crossChain
method has the payable
keyword, so it can directly cross-chain f(x)Core’s native currency: FX. Note that there are some differences between executing a cross-chain transaction for FX and an ERC20 token:
When using cross-chain for FX,
_token
needs to be the zero address (0x0000000000000000000000000000000000000000
), and fill in:value = _amount + _fee
.When using cross-chain for ERC20 token, an approval must first be granted to the address:
0x0000000000000000000000000000000000001004
, and the authorized amount must be equals to:amount = _amount + _fee
.
Method
crossChain
send token from f(x)Core to other chain, like ethereum, pundix, etc.
if token is erc20, must be approved before calling this method
_token
: the token address on the f(x)Core(Tokens)if token is origin token, _token address is
0x0000000000000000000000000000000000000000
_receipt
: the receipt address on the target chain_amount
: the amount of the token to be cross chain_fee
: the fee of the token to be cross chainif cross chain to cosmos chain, _fee is
0
_target
: the target of the token on the target chain(more detail see Target_target represents cross chain destination, such as chain
ethereum
,pundix
destination ethereum: _target is
eth
destination other cosmos chain(example Pundix): _target is
ibc/{id}/{prefix}
.id
is the channel id of the target chain on f(x)Core(examples: Pundix: 0)prefix
is the address prefix of the target chain(examples: Pundix: px)
_memo
: the memo of cross chain
_target convert string to bytes, if less than 32, fill in 0 in behind, until 32 bytes
crossChain event
sender
: the sender addresstoken
: the erc20 token address on the f(x)Coredenom
: the cross chain token denomreceipt
: the receipt address on the target chainamount
: the amount of the token to be cross chainfee
: the fee of the token to be cross chaintarget
: the target of cross chainmemo
: the memo of cross chain
cancelSendToExternal
cancel cross chain to external chain, like ethereum, bsc, etc.
only cancel send to external chain(ethereum,bsc, etc.) transaction, can't cancel send to cosmos chain(pundix, cosmoshub, etc.) transaction.
_chain
: the module name of the cross chain, like eth, bsc, etc._txid
: the txid of the cross chain transaction
cancelSendToExternal event
sender
: the sender addresschain
: the module name of the cross chain, like eth, bsc, etc.txID
: the txid of the cross chain transaction
increaseBridgeFee
increase fee for send to external chain transaction
only increase fee for send to external chain transaction, can't increase fee for send to cosmos chain transaction
not necessarily the initiator of the cross chain transaction, anyone can increase the fee for the cross chain transaction
if token is erc20, must be approved before calling this method
_chain
: the chain name of the cross chain, like eth, bsc, etc(not contain cosmos chain)._txid
: the txid of the cross chain transaction_token
: the address of cross chain fee token(Tokens)if token is origin token, _token address is
0x0000000000000000000000000000000000000000
_fee
: increase fee amount
increaseBridgeFee event
sender
: the sender addresstoken
: the address of cross chain fee tokenchain
: the module name of the cross chain, like eth, bsc, etc.txID
: the txid of the cross chain transactionfee
: increase fee amount
Last updated