Skip to content

Commit e51a1d8

Browse files
authored
Merge pull request #1575 from ethereum-optimism/harry/fix_code_snippets
fix: fix code snippets in interop tutorials
2 parents d5614c9 + 8bd8906 commit e51a1d8

File tree

5 files changed

+33
-43
lines changed

5 files changed

+33
-43
lines changed

pages/interop/tutorials/bridge-crosschain-eth.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ The tutorial uses these primary tools:
214214

215215
Import all chain definitions from `@eth-optimism/viem`.
216216

217-
```typescript file=<rootDir>/public/tutorials/transfer-eth.mts#L29-L32 hash=2c2dd55bc8c8122fe2991ab38cc9c1ac
217+
```typescript file=<rootDir>/public/tutorials/transfer-eth.mts#L28-L31 hash=e8c21357997ea12151305337eced7d71
218218
```
219219

220220
If the address we use is `0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266`, one of the prefunded addresses on `anvil`, assume we're using Supersim.
221221
Otherwise, use Interop devnet.
222222

223-
```typescript file=<rootDir>/public/tutorials/transfer-eth.mts#L78-L80 hash=c5c2f87d5f6bb564376016ac62712501
223+
```typescript file=<rootDir>/public/tutorials/transfer-eth.mts#L73-L79 hash=7d892d7a6578d8efb7cbe16a0af7e342
224224
```
225225

226226
To relay a message we need the information in the receipt.
@@ -232,7 +232,7 @@ The tutorial uses these primary tools:
232232
A single transaction can send multiple messages.
233233
But here we know we sent just one, so we look for the first one in the list.
234234

235-
```typescript file=<rootDir>/public/tutorials/transfer-eth.mts#L90-L96 hash=d650e8c2b31d75d82ba4c5e4519c028d
235+
```typescript file=<rootDir>/public/tutorials/transfer-eth.mts#L90-L94 hash=2f3cc02cffd52ab5b807c5e70388f0ac
236236
```
237237

238238
This is how you use `@eth-optimism/viem` to create an executing message.

pages/interop/tutorials/message-passing.mdx

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ For development purposes, we'll first use autorelay mode to handle message execu
119119
1. In the directory where Supersim is installed, start it with autorelay.
120120

121121
```sh
122-
./supersim --interop.autorelay
122+
supersim --interop.autorelay
123123
```
124124

125125
Supersim creates three `anvil` blockchains:
@@ -221,24 +221,12 @@ For development purposes, we'll first use autorelay mode to handle message execu
221221
4. Install the Optimism Solidity libraries into the project.
222222

223223
```sh
224-
cd lib
225-
npm install @eth-optimism/contracts-bedrock
226-
cd ..
227-
echo @eth-optimism/=lib/node_modules/@eth-optimism/ >> remappings.txt
224+
forge install ethereum-optimism/optimism --no-commit
228225
```
229226

230-
5. The [`@eth-optimism/contracts-bedrock`](https://www.npmjs.com/package/@eth-optimism/contracts-bedrock) library does not have the Interop Solidity code yet.
231-
Run these commands to add it.
227+
5. Create `src/GreetingSender.sol`.
232228

233-
```sh
234-
mkdir -p lib/node_modules/@eth-optimism/contracts-bedrock/interfaces/L2
235-
wget https://raw.githubusercontent.com/ethereum-optimism/optimism/refs/heads/develop/packages/contracts-bedrock/interfaces/L2/IL2ToL2CrossDomainMessenger.sol
236-
mv IL2ToL2CrossDomainMessenger.sol lib/node_modules/@eth-optimism/contracts-bedrock/interfaces/L2
237-
```
238-
239-
6. Create `src/GreetingSender.sol`.
240-
241-
```solidity file=<rootDir>/public/tutorials/GreetingSender.sol#L1-L28 hash=75d197d1e1da112421785c2160f6a55a
229+
```solidity file=<rootDir>/public/tutorials/GreetingSender.sol#L1-L28 hash=9ed77001810caf52bbaa94da8b0dc5c6
242230
```
243231

244232
<details>
@@ -296,8 +284,8 @@ In this section we change `Greeter.sol` to emit a separate event in it receives
296284
//SPDX-License-Identifier: MIT
297285
pragma solidity ^0.8.0;
298286
299-
import { Predeploys } from "@eth-optimism/contracts-bedrock/src/libraries/Predeploys.sol";
300-
import { IL2ToL2CrossDomainMessenger } from "@eth-optimism/contracts-bedrock/interfaces/L2/IL2ToL2CrossDomainMessenger.sol";
287+
import { Predeploys } from "lib/optimism/packages/contracts-bedrock/src/libraries/Predeploys.sol";
288+
import { IL2ToL2CrossDomainMessenger } from "lib/optimism/packages/contracts-bedrock/interfaces/L2/IL2ToL2CrossDomainMessenger.sol";
301289
302290
contract Greeter {
303291
@@ -511,35 +499,35 @@ In this section we change `Greeter.sol` to emit a separate event in it receives
511499

512500
1. Replace `src/app.mts` with:
513501

514-
```typescript file=<rootDir>/public/tutorials/app_v2.mts hash=a7b0f60aa6f1e48fc9994178ed3d5498
502+
```typescript file=<rootDir>/public/tutorials/app_v2.mts hash=f0aef31ef2ce29590a37f18ca07e52a9
515503
```
516504

517505
<details>
518506
<summary>Explanation</summary>
519507

520-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L11-L15 hash=721ed87241535b606be281539baa8770
508+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L11 hash=fef2e60f0dbefba4d1e16f4d87800993
521509
```
522510

523511
Import from the [`@eth-optimism/viem`](https://www.npmjs.com/package/@eth-optimism/viem) package.
524512

525-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L22-L28 hash=ffa76edb1191121e15eb4286e16ad041
513+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L18-L24 hash=ffa76edb1191121e15eb4286e16ad041
526514
```
527515

528516
In addition to extending the wallets with [Viem public actions](https://viem.sh/docs/accounts/local#5-optional-extend-with-public-actions), extend with the OP-Stack actions, both the public ones and the ones that require an account.
529517

530-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L59 hash=23aa6f24baeb5757130361f30c1b0e9c
518+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L55 hash=23aa6f24baeb5757130361f30c1b0e9c
531519
```
532520

533521
To relay a message we need the information in the receipt.
534522
Also, we need to wait until the transaction with the relayed message is actually part of a block.
535523

536-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L61-L63 hash=da4b8733c578a393eb36f154a4e816e1
524+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L57-L60 hash=8cc99e67ee36474c81183108531cb295
537525
```
538526

539527
A single transaction can send multiple messages.
540528
But here we know we sent just one, so we look for the first one in the list.
541529

542-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L64-L70 hash=6bfcd99f2e79df79897d230f36d4a682
530+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L61-L68 hash=fa49aa2a099c57f3b86671a4c0414f31
543531
```
544532

545533
Here we first send the relay message on chain B, and then wait for the receipt for it.
@@ -605,13 +593,15 @@ In this section we change `Greeter.sol` to emit a separate event in it receives
605593
To see what messages were relayed by a specific transaction you can use this code:
606594

607595
```typescript
608-
import { decodeRelayedL2ToL2Messages } from '@eth-optimism/viem'
609-
610-
const decodedRelays = decodeRelayedL2ToL2Messages(
611-
{receipt: receiptRelay})
612-
613-
console.log(decodedRelays)
614-
console.log(decodedRelays.successfulMessages[0].log)
596+
const messages = await walletA.interop.getCrossDomainMessages({
597+
logs: receiptRelay.logs,
598+
})
599+
600+
console.log(messages)
601+
const status = await walletB.interop.getCrossDomainMessageStatus({
602+
message: messages[0],
603+
})
604+
console.log(status)
615605
```
616606
</Steps>
617607

pages/interop/tutorials/relay-messages-cast.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct Identifier {
125125

126126
### Retrieve the block timestamp the log was emitted in
127127

128-
Since the message identifier requires the block timestamp, fetch the block info to get the timestamp.
128+
Since the message identifier requires the block timestamp, fetch the block info to get the timestamp. `0xREPLACE_WITH_CORRECT_BLOCKHASH` should be replaced with the `blockHash` from the output of the previous step.
129129

130130
```sh
131131
cast block 0xREPLACE_WITH_CORRECT_BLOCKHASH --rpc-url http://127.0.0.1:9545
@@ -167,7 +167,7 @@ struct Identifier {
167167

168168
### Construct the access list for the message
169169

170-
An access list must be passed along with the relay message tx. There are two admin RPC methods that can be used to construct the access list: `admin_getAccessListByMsgHash` and `admin_getAccessListForIdentifier` and.
170+
An access list must be passed along with the relay message transaction. There are two admin RPC methods that can be used to construct the access list: `admin_getAccessListByMsgHash` and `admin_getAccessListForIdentifier`.
171171

172172
a. To get the access list using the `admin_getAccessListByMsgHash` RPC method, call the method with the message hash.
173173

pages/interop/tutorials/transfer-superchainERC20.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,33 +185,33 @@ The tutorial uses these primary tools:
185185

186186
3. Create `src/xfer-erc20.mts`:
187187

188-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts hash=19a948eeb482046afb1a55ccc5019599
188+
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts hash=26d412ead555cdd59c16676a4dcd91e8
189189
```
190190

191191
<details>
192192
<summary>Explanation of `xfer-erc20.mts`</summary>
193193

194-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L79-L84 hash=85f317d0cbe2b59e303e36a3e6154c62
194+
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L75-L80 hash=b144852a4fa9ae45e79ec6f124e48e79
195195
```
196196

197197
Use `@eth-optimism/viem`'s `walletActionsL2().sendSuperchainERC20` to send the `SuperchainERC20` tokens.
198198
Internally, this function calls [`SuperchainTokenBridge.sendERC20`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol#L52-L78) to send the tokens.
199199

200200
<AutorelayCallout />
201201

202-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L88-L90 hash=cab6e961b558f4f5a7b877062b1cfa45
202+
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L84-L86 hash=cab6e961b558f4f5a7b877062b1cfa45
203203
```
204204

205205
To relay a message, we need the information in the receipt.
206206
Also, we need to wait until the transaction with the relayed message is actually part of a block.
207207

208-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L92-L94 hash=1da0981adb2fbd38cccf1b0602158418
208+
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L88-L91 hash=e1445aa565f4aaff02a62365fb196ca8
209209
```
210210

211211
A single transaction can send multiple messages.
212212
But here we know we sent just one, so we look for the first one in the list.
213213

214-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L96-L99 hash=b5ad9f0c44aee84742cd20c348fdb156
214+
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L92-L96 hash=0a65e0138ab6954b863ebafacaa23c84
215215
```
216216

217217
This is how you use `@eth-optimism/viem` to create an executing message.

public/tutorials/GreetingSender.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.0;
33

4-
import { Predeploys } from "@eth-optimism/contracts-bedrock/src/libraries/Predeploys.sol";
5-
import { IL2ToL2CrossDomainMessenger } from "@eth-optimism/contracts-bedrock/interfaces/L2/IL2ToL2CrossDomainMessenger.sol";
4+
import { Predeploys } from "lib/optimism/packages/contracts-bedrock/src/libraries/Predeploys.sol";
5+
import { IL2ToL2CrossDomainMessenger } from "lib/optimism/packages/contracts-bedrock/interfaces/L2/IL2ToL2CrossDomainMessenger.sol";
66

77
import { Greeter } from "src/Greeter.sol";
88

0 commit comments

Comments
 (0)