This repository was archived by the owner on Apr 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 336
Fixing the errors in the message passing tutorial #1367
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { | ||
| createWalletClient, | ||
| http, | ||
| defineChain, | ||
|
qbzzt marked this conversation as resolved.
Outdated
|
||
| publicActions, | ||
| getContract, | ||
| Address, | ||
| } from 'viem' | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { supersimL2A, supersimL2B } from '@eth-optimism/viem/chains' | ||
|
|
||
| import { | ||
| walletActionsL2, | ||
| publicActionsL2, | ||
| createInteropSentL2ToL2Messages, | ||
| } from '@eth-optimism/viem' | ||
|
|
||
| import greeterData from './Greeter.json' | ||
| import greetingSenderData from './GreetingSender.json' | ||
|
|
||
| const account = privateKeyToAccount(process.env.PRIV_KEY as `0x${string}`) | ||
|
|
||
| const walletA = createWalletClient({ | ||
| chain: supersimL2A, | ||
| transport: http(), | ||
| account | ||
| }).extend(publicActions) | ||
| .extend(publicActionsL2()) | ||
| .extend(walletActionsL2()) | ||
|
|
||
| const walletB = createWalletClient({ | ||
| chain: supersimL2B, | ||
| transport: http(), | ||
| account | ||
| }).extend(publicActions) | ||
| .extend(publicActionsL2()) | ||
| .extend(walletActionsL2()) | ||
|
|
||
| const greeter = getContract({ | ||
| address: process.env.GREETER_B_ADDR as Address, | ||
| abi: greeterData.abi, | ||
| client: walletB | ||
| }) | ||
|
|
||
| const greetingSender = getContract({ | ||
| address: process.env.GREETER_A_ADDR as Address, | ||
| abi: greetingSenderData.abi, | ||
| client: walletA | ||
| }) | ||
|
|
||
| const txnBHash = await greeter.write.setGreeting( | ||
| ["Greeting directly to chain B"]) | ||
| await walletB.waitForTransactionReceipt({hash: txnBHash}) | ||
|
|
||
| const greeting1 = await greeter.read.greet() | ||
| console.log(`Chain B Greeting: ${greeting1}`) | ||
|
|
||
| const txnAHash = await greetingSender.write.setGreeting( | ||
| ["Greeting through chain A"]) | ||
| const receiptA = await walletA.waitForTransactionReceipt({hash: txnAHash}) | ||
|
|
||
| const sentMessage = | ||
| (await createInteropSentL2ToL2Messages(walletA, { receipt: receiptA })) | ||
| .sentMessages[0] | ||
| const relayMsgTxnHash = await walletB.interop.relayMessage({ | ||
| sentMessageId: sentMessage.id, | ||
| sentMessagePayload: sentMessage.payload, | ||
| }) | ||
|
|
||
| const receiptRelay = await walletB.waitForTransactionReceipt( | ||
| {hash: relayMsgTxnHash}) | ||
|
|
||
| const greeting2 = await greeter.read.greet() | ||
| console.log(`Chain A Greeting: ${greeting2}`) | ||
|
|
||
|
qbzzt marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.