Skip to content

Fix deposit flow tutorial #1648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions pages/stack/transactions/deposit-flow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Information is encapsulated in lower layer packets on the sending side and then
1. The `op-node` component [looks for `TransactionDeposited` events on L1](https://github.com/ethereum-optimism/optimism/blob/62c7f3b05a70027b30054d4c8974f44000606fb7/op-node/rollup/derive/deposits.go#L13-L33).
If it sees any such events, it [parses](https://github.com/ethereum-optimism/optimism/blob/62c7f3b05a70027b30054d4c8974f44000606fb7/op-node/rollup/derive/deposit_log.go) them.

2. Next, `op-node` [converts](https://github.com/ethereum-optimism/optimism/blob/62c7f3b05a70027b30054d4c8974f44000606fb7/op-node/rollup/derive/deposits.go#L35-L51) those `TransactionDeposited` events into [deposit transactions](https://specs.optimism.io/protocol/deposits.html?utm_source=op-docs&utm_medium=docs#user-deposited-transactions).
2. Next, `op-node` [converts](https://github.com/ethereum-optimism/optimism/blob/62c7f3b05a70027b30054d4c8974f44000606fb7/op-node/rollup/derive/deposits.go#L35-L51) those `TransactionDeposited` events into [deposit transactions](https://specs.optimism.io/protocol/deposits.html?utm_source=op-docs\&utm_medium=docs#user-deposited-transactions).

3. In most cases, user deposit transactions call the [`relayMessage`](https://github.com/ethereum-optimism/optimism/blob/62c7f3b05a70027b30054d4c8974f44000606fb7/packages/contracts-bedrock/contracts/universal/CrossDomainMessenger.sol#L291-L413) function of [`L2CrossDomainMessenger`](https://github.com/ethereum-optimism/optimism/blob/62c7f3b05a70027b30054d4c8974f44000606fb7/packages/contracts-bedrock/contracts/universal/CrossDomainMessenger.sol).

Expand Down Expand Up @@ -94,6 +94,17 @@ It is possible to replay a failed deposit, possibly with more gas.

### Replays in action

<Callout type="info">
**L1 vs L2 network clarification**

This tutorial involves **two different networks**:

* **L1**: Ethereum Sepolia testnet (`https://sepolia.infura.io/v3/YOUR_KEY`)
* **L2**: OP Sepolia testnet (`https://sepolia.optimism.io`)

You'll send transactions on L1 that trigger actions on L2. Make sure you're using the correct RPC URLs for each step.
</Callout>

To see how replays work, you can use [this contract on OP Sepolia](https://sepolia-optimism.etherscan.io/address/0xEF60cF6C6D0C1c755be104843bb72CDa3D778630#code).

1. Call `stopChanges`, using this Foundry command:
Expand Down Expand Up @@ -125,29 +136,52 @@ To see how replays work, you can use [this contract on OP Sepolia](https://sepol
0xa41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000774657374696e6700000000000000000000000000000000000000000000000000
```

4. Send a greeting change as a deposit.
4. Send a greeting change as a deposit from L1 (Ethereum Sepolia) to L2 (OP Sepolia).
Use these commands:

```sh
L1_RPC=https://sepolia.optimism.io
# L1 = Ethereum Sepolia
# Get a free Infura key at https://infura.io or use the public RPC below
L1_RPC=https://sepolia.infura.io/v3/YOUR_INFURA_KEY
L1XDM_ADDRESS=0x5086d1eef304eb5284a0f6720f79403b4e9be294
FUNC="sendMessage(address,bytes,uint32)"
CALLDATA=`cast calldata "setGreeting(string)" "testing"`
cast send --rpc-url $L1_RPC --private-key $PRIV_KEY $L1XDM_ADDRESS $FUNC $GREETER $CALLDATA 10000000
```

The transaction will be successful on L1, but then emit a fail event on L2.
The transaction will be successful on **L1 (Ethereum Sepolia)**, but then emit a fail event on **L2 (OP Sepolia)**.

5. 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](https://sepolia-optimism.etherscan.io/address/0xEF60cF6C6D0C1c755be104843bb72CDa3D778630#internaltx), and select the latest one that appears as a failure. It should be a call to `L2CrossDomainMessenger` at address `0x420...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](https://sepolia-optimism.etherscan.io/address/0x4200000000000000000000000000000000000007#events) and look for `FailedRelayedMessage` events with your contract address.

5. The next step is to find the hash of the failed relay.
The easiest way to do this is to look in [the internal transactions of the destination contract](https://sepolia-optimism.etherscan.io/address/0xEF60cF6C6D0C1c755be104843bb72CDa3D778630#internaltx), and select the latest one that appears as a failure.
It should be a call to `L2CrossDomainMessenger` at address `0x420...007`. This is the call you need to replay.
**Method C: Using cast to query failed messages**

```sh
# First, you need the message hash. You can derive it from the L1 transaction, or check events
L2XDM_ADDRESS=0x4200000000000000000000000000000000000007
# Replace MSG_HASH with the actual message hash from the FailedRelayedMessage event
cast call $L2XDM_ADDRESS "failedMessages(bytes32)" $MSG_HASH
```

If 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.

6. Get the transaction information using Foundry.

<Callout type="warning">
**Wait for the failed relay transaction**

Make 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.
</Callout>

```sh
TX_HASH=<transaction hash from Etherscan>
TX_HASH=<transaction hash from the failed relay on L2>
L2XDM_ADDRESS=0x4200000000000000000000000000000000000007
REPLAY_DATA=`cast tx $TX_HASH input`
```
Expand Down