Skip to content

Commit 1d9af5a

Browse files
committed
with devnet support
1 parent 7387006 commit 1d9af5a

File tree

1 file changed

+29
-45
lines changed

1 file changed

+29
-45
lines changed

pages/stack/interop/tutorials/message-passing.mdx

+29-45
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Before starting this tutorial, ensure you have:
3535

3636
Before starting this tutorial, refer to the [Installation Guide](/app-developers/tutorials/supersim/getting-started/installation) to set up **Foundry** and **Supersim** on your system.
3737

38-
## Implementing solidity message passing
38+
## Implementing onchain message passing (in Solidity)
3939

4040
This section demonstrates how to deploy smart contracts for cross-chain messaging and send messages between them.
4141
For now, we will ignore the need for executing messages by turning on autorelay.
@@ -419,7 +419,7 @@ We use [TypeScript](https://www.typescriptlang.org/) to have type safety combine
419419
"type": "commonjs",
420420
"description": "",
421421
"devDependencies": {
422-
"@eth-optimism/viem": "^0.3.0",
422+
"@eth-optimism/viem": "^0.3.2",
423423
"@types/node": "^22.13.1",
424424
"tsx": "^4.19.2",
425425
"viem": "^2.22.23"
@@ -435,6 +435,10 @@ We use [TypeScript](https://www.typescriptlang.org/) to have type safety combine
435435
export GREETER_A_ADDR GREETER_B_ADDR PRIV_KEY
436436
```
437437

438+
<details>
439+
440+
<summary>Sanity check</summary>
441+
438442
1. Create a simple `src/app.mts` file.
439443

440444
```typescript
@@ -448,6 +452,9 @@ We use [TypeScript](https://www.typescriptlang.org/) to have type safety combine
448452
npm run start
449453
```
450454

455+
</details>
456+
457+
451458
### Send a greeting
452459

453460
1. Link the compiled versions of the onchain code, which include the ABI, to the source code.
@@ -459,7 +466,7 @@ We use [TypeScript](https://www.typescriptlang.org/) to have type safety combine
459466
cd ..
460467
```
461468

462-
1. Replace `src/app.mts` with this code.
469+
1. Create or replace `src/app.mts` with this code.
463470

464471
```typescript
465472
import {
@@ -715,54 +722,25 @@ You can relay messages in exactly the same way you'd do it on Supersim.
715722

716723
| Contract | Network | Address
717724
| - | - | -
718-
| `Greeter` | [Devnet 1](../tools/devnet#interop-devnet-1) | [`0x1A183FCf61053B7dcd2322BbE766f7E1946d3718`](https://sid.testnet.routescan.io/address/0x1A183FCf61053B7dcd2322BbE766f7E1946d3718/contract/420120001/readContract?chainid=420120001)
725+
| `Greeter` | [Devnet 1](../tools/devnet#interop-devnet-1) | [`0x1A183FCf61053B7dcd2322BbE766f7E1946d3718`](https://sid.testnet.routescan.io/address/0x1A183FCf61053B7dcd2322BbE766f7E1946d3718)
719726
| `GreetingSender` | [Devnet 0](../tools/devnet#interop-devnet-1) | [`0x9De9f84a4EB3616B44CF1d68cD1A9098Df6cB25f`](https://sid.testnet.routescan.io/address/0x9De9f84a4EB3616B44CF1d68cD1A9098Df6cB25f/contract/420120000/readContract?chainid=420120000)
720727

721-
1. Set the address environment variables.
728+
To modify the program to relay messagez on devnet, follow these steps:
722729

723-
```sh
724-
export GREETER_A_ADDR=0x9De9f84a4EB3616B44CF1d68cD1A9098Df6cB25f
725-
export GREETER_B_ADDR=0x1A183FCf61053B7dcd2322BbE766f7E1946d3718
726-
```
730+
1. In `src/app.mts`, replace these lines to update the chains and contract addresses.
727731

728-
1. In `src/app.mts`, replace this line:
732+
| Line number | New content |
733+
| -: | - |
734+
| 10 | `import { interopAlpha0, interopAlpha1 } from '@eth-optimism/viem/chains'`
735+
| 24 | ` chain: interopAlpha0,`
736+
| 32 | ` chain: interopAlpha1,`
737+
| 40 | ` address: "0x1A183FCf61053B7dcd2322BbE766f7E1946d3718",`
738+
| 46 | ` address: "0x9De9f84a4EB3616B44CF1d68cD1A9098Df6cB25f",`
729739

730-
```typescript
731-
import { supersimL2A, supersimL2B } from '@eth-optimism/viem/chains'
732-
```
733-
734-
with
735-
736-
```typescript
737-
import { chainConfig } from 'viem/op-stack'
738-
739-
const supersimL2A = defineChain({
740-
...chainConfig,
741-
id: 420120000,
742-
name: 'Interop devnet 0',
743-
rpcUrls: {
744-
default: {
745-
http: ['https://interop-alpha-0.optimism.io'],
746-
},
747-
},
748-
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
749-
sourceId: 11155111,
750-
testnet: true,
751-
})
740+
1. Set `PRIV_KEY` to the private key of an address that has Sepolia ETH on the two chains.
752741

753-
const supersimL2B = defineChain({
754-
...chainConfig,
755-
id: 420120001,
756-
name: 'Interop devnet 1',
757-
rpcUrls: {
758-
default: {
759-
http: ['https://interop-alpha-1.optimism.io'],
760-
},
761-
},
762-
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
763-
sourceId: 11155111,
764-
testnet: true,
765-
})
742+
```sh
743+
export PRIV_KEY=0x<private key here>
766744
```
767745

768746
1. Rerun the test.
@@ -771,6 +749,12 @@ You can relay messages in exactly the same way you'd do it on Supersim.
771749
npm start
772750
```
773751

752+
1. You can see the transactions in a block explorer.
753+
754+
- The first transaction, which sets the greeting directly, [on the `Greeter` contract on interop1](https://sid.testnet.routescan.io/address/0x1A183FCf61053B7dcd2322BbE766f7E1946d3718).
755+
- The second transaction, the initiation message for the cross chain greeting change, [on the `GreetingSender` contract on interop0](https://sid.testnet.routescan.io/address/0x9De9f84a4EB3616B44CF1d68cD1A9098Df6cB25f).
756+
- The third transaction, the executing message for the cross chain greeting change, [on the `Greeter` contract on interop1 as an internal transaction](https://sid.testnet.routescan.io/address/0x1A183FCf61053B7dcd2322BbE766f7E1946d3718/internalTx).
757+
774758
### Debugging
775759

776760
To see what messages were relayed by a specific transaction you can use this code:

0 commit comments

Comments
 (0)