From 9a480c66ebd011c69feda40d5e15961fa899e39c Mon Sep 17 00:00:00 2001 From: krofax Date: Thu, 6 Feb 2025 17:56:53 +0100 Subject: [PATCH 1/2] updated the script --- .../tutorials/cross-dom-solidity.mdx | 26 ++--- public/tutorials/cross-dom-solidity.js | 94 ++++++++++++------- 2 files changed, 73 insertions(+), 47 deletions(-) diff --git a/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx b/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx index 51d7d0af0..72443593c 100644 --- a/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx +++ b/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx @@ -176,19 +176,14 @@ Start the Node.js REPL with the `node` command. node ``` -{

Import Viem

} +{

Import viem

} -```js file=/public/tutorials/cross-dom-solidity.js#L3-L5 hash=65b9a5ad5b634bc2e424f5664e6e1f84 -``` - -{

Load your transaction hash

} - -```js file=/public/tutorials/cross-dom-solidity.js#L7 hash=320cd4f397d7bed8d914d4be0c99f8dc +```js file=/public/tutorials/cross-dom-solidity.js#L3-L6 hash=c4ff236835a2e078f26f99dacdfa53da ``` {

Create the RPC providers and wallets

} -```js file=/public/tutorials/cross-dom-solidity.js#L8-L9 hash=d47e4991c5153e1e1dc55de5047a8a3e +```js file=/public/tutorials/cross-dom-solidity.js#L8-L20 hash=9500ca6be35774522cce2260cd8e9cb6 ``` {

Wait until the message is ready to prove

} @@ -196,7 +191,7 @@ node Next, you will send messages from L2 to L1 is to prove that the message was sent on L2. You first need to wait until the message is ready to prove. -```js file=/public/tutorials/cross-dom-solidity.js#L12-L16 hash=df275e659d954eb72b8c5765d9baf6de +```js file=/public/tutorials/cross-dom-solidity.js#L22-L30 hash=0e460f24fc394acdcdb7f06df0188e31 ``` @@ -208,7 +203,12 @@ Feel free to take a quick break while you wait. Once the message is ready to be proven, you'll send an L1 transaction to prove that the message was sent on L2. -```js file=/public/tutorials/cross-dom-solidity.js#L18-L23 hash=e4d608ac2c2ceb5a744c8474679bd8cb +```js file=/public/tutorials/cross-dom-solidity.js#L32-L36 hash=6b44abbea96103df0513d098ae6e6659 +``` + +{

Build parameters to prove the withdrawal on the L2

} + +```js file=/public/tutorials/cross-dom-solidity.js#L38-L44 hash=a31f720f43df1680f5488ea233cc9506 ``` {

Wait until the message is ready for relay

} @@ -221,21 +221,21 @@ On OP Stack, this takes 7 days. We're currently testing fault proofs on OP Sepolia, so withdrawal times reflect Mainnet times.
-```js file=/public/tutorials/cross-dom-solidity.js#L25-L29 hash=88cec1db2fde515ea9008eaa1bbdfd73 +```js file=/public/tutorials/cross-dom-solidity.js#L46-L50 hash=8c08d1f4c6a7f5d1754a411b3590530d ``` {

Relay the message on L1

} Once the withdrawal is ready to be relayed you can finally complete the message sending process. -```js file=/public/tutorials/cross-dom-solidity.js#L31-L33 hash=d7e47c9787d92e2140622a6bdcc6d7bb +```js file=/public/tutorials/cross-dom-solidity.js#L52-L54 hash=d64917e14a9004ef0b81e3f08003d5cd ``` {

Wait until the message is relayed

} Now you simply wait until the message is relayed. -```js file=/public/tutorials/cross-dom-solidity.js#L35-L36 hash=4ff3cdc48f17cfd7de4a6ef2d2671dc2 +```js file=/public/tutorials/cross-dom-solidity.js#L56-L62 hash=5a0d3a97f8d71f11c1e46c5e4a734ffb ``` {

Check the L1 Greeter

} diff --git a/public/tutorials/cross-dom-solidity.js b/public/tutorials/cross-dom-solidity.js index c4368c9e5..ada55acdb 100644 --- a/public/tutorials/cross-dom-solidity.js +++ b/public/tutorials/cross-dom-solidity.js @@ -1,39 +1,65 @@ (async () => { -const { createPublicClient, http } = require('viem'); -const { optimismSepolia } = require('viem/chains'); -const { publicActionsL1, publicActionsL2} = require('viem/op-stack'); - -const transactionHash = process.env.TUTORIAL_TRANSACTION_HASH - -const l1Provider = createPublicClient({ chain: sepolia, transport: http("https://rpc.ankr.com/eth_sepolia") }).extend(publicActionsL1()) -const l2Provider = createPublicClient({ chain: optimismSepolia, transport: http("https://sepolia.optimism.io") }).extend(publicActionsL2()); - -console.log('Waiting for message to be provable...') -await l1Provider.getWithdrawalStatus({ - receipt, - targetChain: l2Provider.chain, -}) - -console.log('Proving message...') -const receipt = await l2Provider.getTransactionReceipt(transactionHash) -const output = await l1Provider.waitToProve({ - receipt, - targetChain: l2Provider.chain, -}) - -console.log('Waiting for message to be relayable...') -await l1Provider.getWithdrawalStatus({ - receipt, - targetChain: l2Provider.chain, -}) - -console.log('Relaying message...') -const [message] = getWithdrawals(receipt) -await l1Provider.waitToFinalize({ withdrawalHash: message.withdrawalHash, targetChain: l2Provider.chain }) - -console.log('Waiting for message to be relayed...') -await l1Provider.getWithdrawalStatus({ receipt, targetChain: l2Provider.chain }) + const { createPublicClient, http, createWalletClient } = require("viem"); + const { optimismSepolia, sepolia } = require("viem/chains"); + const { publicActionsL1, publicActionsL2, walletActionsL1, walletActionsL2 } = require("viem/op-stack"); + const { privateKeyToAccount } = require("viem/accounts"); + + const l1Provider = createPublicClient({ chain: sepolia, transport: http("https://eth-sepolia.g.alchemy.com/v2/***") }).extend(publicActionsL1()) + const l2Provider = createPublicClient({ chain: optimismSepolia, transport: http("https://opt-sepolia.g.alchemy.com/v2/***") }).extend(publicActionsL2()) + const account = privateKeyToAccount(process.env.TUTORIAL_PRIVATE_KEY) + + const l1Wallet = createWalletClient({ + chain: sepolia, + transport: http("https://eth-sepolia.g.alchemy.com/v2/***") + }).extend(walletActionsL1()) + + const l2Wallet = createWalletClient({ + chain: optimismSepolia, + transport: http("https://opt-sepolia.g.alchemy.com/v2/***") + }).extend(walletActionsL2()) + + const receipt = await l2Provider.getTransactionReceipt({ + hash: process.env.TUTORIAL_TRANSACTION_HASH + }) + + console.log('Waiting for message to be provable...') + await l1Provider.getWithdrawalStatus({ + receipt, + targetChain: l2Provider.chain, + }) + + console.log('Proving message...') + const { output, withdrawal } = await l1Provider.waitToProve({ + receipt, + targetChain: l2Provider.chain, + }) + + const args = await l2Provider.buildProveWithdrawal({ + account, + output, + withdrawal, + }) + + const hash = await l1Wallet.proveWithdrawal(args) + + console.log('Waiting for message to be relayable...') + await l1Provider.getWithdrawalStatus({ + receipt, + targetChain: l2Provider.chain, + }) + + console.log('Relaying message...') + const [message] = getWithdrawals(receipt) + await l1Provider.waitToFinalize({ withdrawalHash: message.withdrawalHash, targetChain: l2Provider.chain }) + + const finalizeHash = await l1Wallet.finalizeWithdrawal({ + targetChain: l2Wallet.chain, + withdrawal, + }) + + console.log('Waiting for message to be relayed...') + await l1Provider.getWithdrawalStatus({ receipt, targetChain: l2Provider.chain }) })() From a864e5885991e0808244a09577d4a3e3a1c15ee9 Mon Sep 17 00:00:00 2001 From: krofax Date: Tue, 11 Feb 2025 16:15:43 +0100 Subject: [PATCH 2/2] updated file imports --- pages/builders/app-developers/tutorials/cross-dom-solidity.mdx | 2 +- public/tutorials/cross-dom-solidity.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx b/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx index 72443593c..89b04ac0f 100644 --- a/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx +++ b/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx @@ -178,7 +178,7 @@ node {

Import viem

} -```js file=/public/tutorials/cross-dom-solidity.js#L3-L6 hash=c4ff236835a2e078f26f99dacdfa53da +```js file=/public/tutorials/cross-dom-solidity.js#L3-L6 hash=ab7ce5835f34a359602c8fe03080c3ed ``` {

Create the RPC providers and wallets

} diff --git a/public/tutorials/cross-dom-solidity.js b/public/tutorials/cross-dom-solidity.js index ada55acdb..00263b452 100644 --- a/public/tutorials/cross-dom-solidity.js +++ b/public/tutorials/cross-dom-solidity.js @@ -2,7 +2,7 @@ const { createPublicClient, http, createWalletClient } = require("viem"); const { optimismSepolia, sepolia } = require("viem/chains"); - const { publicActionsL1, publicActionsL2, walletActionsL1, walletActionsL2 } = require("viem/op-stack"); + const { publicActionsL1, publicActionsL2, walletActionsL1, walletActionsL2, getWithdrawals } = require("viem/op-stack"); const { privateKeyToAccount } = require("viem/accounts"); const l1Provider = createPublicClient({ chain: sepolia, transport: http("https://eth-sepolia.g.alchemy.com/v2/***") }).extend(publicActionsL1())