Composable Bridging
Use Across to bridge + execute a transaction
Last updated
Use Across to bridge + execute a transaction
Last updated
You can instruct Across to execute a transaction upon filling your deposit on the destination chain. This transaction would be executed atomically with the fill transaction.
NOTE: The transaction that gets executed on the destination chain must be non-reverting otherwise user deposits may risk getting locked.
When a relayer fills your deposit by calling fillRelay()
on the destination SpokePool, if the deposit has a message attached, then the on your recipient address and pass in the following params:
The deposit message
is not empty
The recipient
address is a contract on the destinationChainId that implements a public handleAcrossMessage(address,uint256,bool,address,bytes)
function, and this function must be non-reverting
The additional gas cost to execute the above function is compensated for in the deposit's
Construct your message
Use the Across API to get an estimate of the relayerFeePct
you should set for your message and recipient combination
Call deposit()
passing in your message
Once the relayer calls fillRelay()
on the destination, your recipient's handleAcrossMessage
will be executed
Imagine that I want to bridge ETH from Ethereum to Optimism and receive ETH, not wrapped WETH on Optimism
I will deploy the following contract on Optimism which unwraps received WETH into ETH and sends to a designated owner
EOA
Here we set message
to something useless but not-zero so that the destination SpokePool
ultimately calls handleAcrossMessage
on MyUnwrapper
Call Across-API’s endpoint with params ?token=0xWETH-on-ethereum-address&destinationChainId=10&amount= x&originChainId=1&recipient=
MyUnwrapper.address&message=0x1234