| description | Use Across to bridge + execute a transaction |
|---|
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 SpokePool will attempt to call handleAcrossMessage() on your recipient address and pass in the following params:
- The deposit
messageis not empty - The
recipientaddress is a contract on the destinationChainId that implements a publichandleAcrossMessage(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
relayerFeePct
- Construct your
message - Use the Across API to get an estimate of the
relayerFeePctyou should set for your message and recipient combination - Call
deposit()passing in your message - Once the relayer calls
fillRelay()on the destination, your recipient'shandleAcrossMessagewill 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
ownerEOA
contract MyUnwrapper {
WETHInterface weth;
addess payable owner;
constructor() public {
owner = msg.sender;
}
function handleAcrossMessage(
address tokenSent,
uint256 amount,
bool, // fillCompleted unused
address, // relayer is unused
bytes memory // message is unused
) external {
require(tokenSent == address(weth), "received token not WETH");
weth.withdraw(amount);
(bool sent, bytes memory data) = owner.call{value: amount}("");
require(sent, "Failed to send Ether");
}
}- Call Across-API’s /suggested-fees endpoint with params
?token=0xWETH-on-ethereum-address&destinationChainId=10&amount= x&originChainId=1&recipient=MyUnwrapper.address&message=0x1234 - Here we set
messageto something useless but not-zero so that the destinationSpokePoolultimately callshandleAcrossMessageonMyUnwrapper