L2CrossDomainMessenger records it as a failed message, and you can replay it later, optionally with more gas.
In this tutorial, you’ll make a deposit fail on purpose against a test contract, then replay it successfully, so you can see the full failure-and-replay cycle end to end. For the concepts behind deposits and why replays are possible, see Deposit flow.
Before you begin
- Foundry installed (this tutorial uses
cast). - A test account private key, funded with a small amount of test ETH on both Ethereum Sepolia (L1) and OP Sepolia (L2).
- An L1 (Ethereum Sepolia) RPC URL — e.g. a free Infura key or another provider.
L1 vs L2 network clarificationThis tutorial involves two different networks:
- L1: Ethereum Sepolia testnet (
https://sepolia.infura.io/v3/YOUR_KEY) - L2: OP Sepolia testnet (
https://sepolia.optimism.io)
Trigger and replay a failed deposit
To see how replays work, you can use this contract on OP Sepolia.-
Call
stopChanges, using this Foundry command: -
Verify that
getStatus()returns false, meaning changes are not allowed, and see the value ofgreet()using Foundry. Note that Foundry returns false as zero. -
Get the calldata.
You can use this Foundry command:
Or just use this value:
-
Send a greeting change as a deposit from L1 (Ethereum Sepolia) to L2 (OP Sepolia).
Use these commands:
The transaction will be successful on L1 (Ethereum Sepolia), but then emit a fail event on L2 (OP Sepolia).
-
The next step is to find the hash of the failed relay. There are several ways to do this:
Method A: Using Etherscan Internal Transactions
Look in the internal transactions of the destination contract, and select the latest one that appears as a failure. It should be a call to
L2CrossDomainMessengerat address0x420...007. Method B: Using Contract Events (if internal transactions aren’t visible) If you can’t see internal transactions on Etherscan, check the L2CrossDomainMessenger contract events and look forFailedRelayedMessageevents with your contract address. Method C: Using cast to query failed messagesIf the latest internal transaction is a success, it probably means your transaction hasn’t relayed yet. Wait until it is, that may take a few minutes. -
Get the transaction information using Foundry.
Wait for the failed relay transactionMake sure you wait for the deposit to be processed on L2 and fail before proceeding. This can take 2-5 minutes. You should see a failed transaction in one of the methods from step 5.
-
Call
startChanges()to allow changes using this Foundry command:Don’t do this prematurelyIf you callstartChanges()too early, it will happen when the message is relayed to L2, and then the initial deposit will be successful and there will be no need to replay it. -
Verify that
getStatus()returns true, meaning changes are not allowed, and see the value ofgreet(). Foundry returns true as one. -
Now send the replay transaction.
Why do we need to specify the gas limit?The gas estimation mechanism tries to find the minimum gas limit at which the transaction would be successful. However,
L2CrossDomainMessengerdoes not revert when a replay fails due to low gas limit, it just emits a failure message. The gas estimation mechanism considers that a success.To get a gas estimate, you can use this command:That address is a special case in which the contract does revert. -
Verify the greeting has changed:
Debugging
To debug deposit transactions, you can ask the L2 cross domain messenger for the state of the transaction.-
Look on Etherscan to see the
FailedRelayedMessageevent. SetMSG_HASHto that value. -
To check if the message is listed as failed, run this:
To check if it is listed as successful, run this:
Next steps
- Read Deposit flow to understand how deposits are processed across L1 and L2 under the hood.
- Learn about sending data between L1 and L2 from your contracts.