Comment on page
To onboard users to a new chain they need both tokens they can bridge via LI.FI and some gas to be able to submit their first transactions. LI.Fuel helps to do both in one transaction.
LI.Fuel allows to receive a part of the bridged tokens as gas on the destination chain. This is possible by adding the
fromAmountForGasto a quote or routes request:
fromAmountForGasto the quote
A user is on Ethereum and wants to transfer 5 USDC to Polygon.
- 1.Check if a user has gas on the destination chain (Polygon):
const balance = await getProvider(destinationChain).getBalance(userAddress)
- 2.If a user has no gas on the destination chain we need to find out how much gas would be good to have on Polygon. The
/gas/suggestionendpoint provides that information. Optionally, the token a user is currently sending can be added to the request to calculate how much of that token should be swapped into gas:
// The service is available, has enough liquidity and is enabled for this chain
// The recommended amount is high enough to execut 4-10 approvals + swaps on the destionation chain.
// The amount is calculated based on the current market conditions (gasPrice) on the chain, to ensure that
// users don't get stuck, but also don't send too much gas.
// LI.Fuel allows a maximum of $5 to be swapped for MATIC
// LI.Fuel will take $0.01 from the transferred amount as fee for the service (mainly gas costs on Polygon)
// USDC token we passed, 0.24$ for gas in USDC is 240000
- 3.Knowing these recommendations, any value between the USD amount of the service fee and the limit can be chosen. We would suggest using the recommended amount as default. As we passed the token (USDC) the user wants to pay with, we can use the received
fromAmountparameter which is the amount of USDC the user needs to pay on Ethereum to get the recommended amount of gas on the destination chain. In this example, it is
240000. To include this in a route add the value as
In a quote request:
In a routes request:
curl --location 'https://li.quest/v1/advanced/routes' \
--header 'Content-Type: application/json' \
- 4.Submit the quote/route as any other cross-chain route. In the transaction the funds are split automatically to send the requested amount to LI.Fuel, and the rest to the selected bridge. Monitor the transfer using the status endpoint.
- 5.(optional) LI.Fuel is designed to pay out gas to the user quickly, so he already has the gas when the other bridged assets arrive. It is not required to check the status of the gas delivery but it can be done by passing the transaction hash from the source chain to this endpoint: