Examples
Last updated
Last updated
A worked example for how to quote and bridge ERC20 funds between two EVM chains is as follows.
Let's say Alice has funds on Goerli wants to send herself UNI to the same address on Sepolia.
We know the following:
Alice calls api with the parameters above to make sure the bridging params are acceptable.
/api/getBridgingQuote?chainFrom=5&chainTo=11155111&tokenFrom=0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984&tokenTo=0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984&amount=0.1
She might get a response akin to the following
This shows her there are enough tokens at the destination and that her proposed bridging is allowed.
The response also shows her the fees she would expect to pay (fee_token_total_dec
) as part of this transaction.
The expected structure of the payload is shown below, it contains information about where the funds she is bridging will be sent and an agreement of the amount she will receive and the fee that will be charged.
It is extremely important to correctly calculate the dest_amount
as this will be the amount transferred at the destination. If this does not account for the fee (i.e. deposit amount - fee obtained from the API call) the transaction will be rejected.
Alice should make sure she has granted sufficient allowance to the bridge contract.
To do this she would then call getBridgeContract on the chain she wants to bridge from, in this case Goerli. The call would might looks like this.
/api/getBridgeContract?chain=5
Returning
Bringing everything together, using this address and the payload information, Alice can then build and send her transaction to the bridge contract.
Once the transaction has been broadcast, she will see confirmation on chain.
She can do this by calling getHistory
with the source transaction hash as the id
paramater to see the current status of her bridge transaction.
Once the bridging is complete, the field destination_chain_tx
will contain the transaction hash of the funds being credited at the destination chain.
Alice is happy.
Alice would now build the payload data for the transaction based on the instructions found on the page.
This should then be and might yield something like this:
Using this address she can the bridge contract to spend 0.1 UNI.
Alice should then wait while the transaction is being and credited at her destination chain.