Cross-Chain Contract Calls
Cross-Chain Contract Calls: This feature enables contract calls across chains, buy NFTs, stake or donate without needing gas on the destination chain!
Destination calls are currently supported on Polygon, Binance, Optimism, Ethereum, Fantom, Avalanche and Arbitrum.
To read more about what xChain Contract calls are and how they work, please click here.
With this feature, you can make arbitrary contract calls across blockchains. All you need to do is prepare the callData
for the contract call you want to make on the destination chain (e.g. stake KLIMA in the example below). Pass that callData
along with information about where you want to pay for it to the endpoint. The response contains information on how many tokens must be submitted to pay for all transfer and swap fees.
Parameters
About the contract call:
Parameter | Explaination | Example Data |
---|---|---|
(required) | The chain the contract is deployed on. Can be the chain id or chain key. |
|
(required) | The token required to perform the contract interaction (can be something to stake, donate or to be used as payment). |
|
(required) | The amount of token required by the contract interaction. The LI.FI API will try and generate a quote that guarantees at least that amount on the destination chain. |
|
| The address of the contract to interact with. |
|
| The |
|
| The estimated gas used by the destination call. If this value is incorrect, the interaction may fail -- choose this carefully! |
|
| If the approval address is different thant the contract to call, specify that address here. |
|
| Some contract interactions will output a token (e.g. staking), specify the token address to forward the token to the user. Omit this parameter if no token should be returned to the user. |
|
| If the call fails, use this address to send the bridged tokens to. If none is specified, the sending address will be used. |
|
How does the user want to pay:
Parameter | Explaination | Example Data |
---|---|---|
(required) | The sending chain. Can be the chain id or chain key. |
|
| The token that the user pays with. Can be the address or the symbol. |
|
| The wallet that will send the transaction and contains the starting token. |
|
Additional options:
Parameter | Explaination | Example Data |
---|---|---|
| The maximum allowed slippage for the transaction as a decimal value. 0.05 represents 5%. |
|
| A string containing tracking information about the integrator of the API. |
|
| A string containing tracking information about the referrer of the integrator. |
|
(optional) | The percent of the integrator's fee that is taken from every transaction |
|
Example: stake KLIMA on Polygon
The example below demonstrates how to stake KLIMA token (KlimaDAO) into sKLIMA (staked KLIMA). The process involves
sending some
DAI
token from Binance Smart Chain (BSC) to Polygon (POL)swapping
DAI
forKLIMA
performing a contract call to the KLIMA staking contract.
The callData
will be executed by our executer contract, not by the users wallet, so ensure that the contract does not expect the user to be msg.sender
. The staked tokens are sent to the executor which will then forward them to the user if the contractOutputsToken
parameter is set.
In the end, the contract will produce the staked KLIMA
token sKLIMA
which will then be transferred back to the user.
Once the quote is generated, you can execute it like any other quote as explained here.
Links to the example transactions
Here you can find links to the sending and receiving transactions for the transfer from DAI on BNB Smart Chain to sKLIMA on Polygon via the custom contract call.
Sending: https://bscscan.com/tx/0x3cbc7e29ad89d0b04a8f59a4851fae17a65b7b5248567da74f5462e28642231f
Receiving: https://polygonscan.com/tx/0xeb399611d324467c9dbd7cf2006e3c73aa982ca19b67b987365e4098162a5a09
Last updated