From 01fb5252f5c9a93a9569084a57c46be6044b0ba0 Mon Sep 17 00:00:00 2001 From: krofax Date: Tue, 15 Oct 2024 16:03:30 +0100 Subject: [PATCH] updated codebase --- next-env.d.ts | 2 +- .../tutorials/cross-dom-solidity.mdx | 56 ++++++------------- public/tutorials/cross-dom-solidity.js | 48 +++++++++------- 3 files changed, 46 insertions(+), 60 deletions(-) diff --git a/next-env.d.ts b/next-env.d.ts index a4a7b3f5..4f11a03d 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx b/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx index b846658c..1d086f67 100644 --- a/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx +++ b/pages/builders/app-developers/tutorials/cross-dom-solidity.mdx @@ -5,9 +5,7 @@ description: Learn how to write Solidity contracts on OP Mainnet and Ethereum th --- import { Steps, Callout, Tabs } from 'nextra/components' -import { WipCallout } from '@/components/WipCallout' - # Communicating Between OP Mainnet and Ethereum in Solidity @@ -82,8 +80,8 @@ It will take a few minutes for your message to reach L2. Feel free to take a quick break while you wait. -You can use the Optimism SDK to programmatically check the status of any message between L1 and L2. -Later on in this tutorial you'll learn how to use the Optimism SDK and the `waitForMessageStatus` function to wait for various message statuses. +You can use Viem to programmatically check the status of any message between L1 and L2. +Later on in this tutorial you'll learn how to use Viem and the `waitToProve` function to wait for various message statuses. This same function can be used to wait for a message to be relayed from L1 to L2. @@ -145,20 +143,12 @@ Set up the project as a basic Node.js project with `pnpm` or your favorite packa pnpm init ``` -{

Install the Optimism SDK

} +{

Install Viem

} -Install the Optimism SDK with `pnpm` or your favorite package manager. +Install Viem with `pnpm` or your favorite package manager. ```bash -pnpm add @eth-optimism/sdk -``` - -{

Install ethers.js

} - -Install `ethers` with `pnpm` or your favorite package manager. - -```bash -pnpm add ethers@^5 +pnpm add viem ``` {

Add your private key to your environment

} @@ -189,46 +179,32 @@ Start the Node.js REPL with the `node` command. node ``` -{

Import the Optimism SDK

} +{

Import Viem

} -```js file=/public/tutorials/cross-dom-solidity.js#L3 hash=26b2fdb17dd6c8326a54ec51f0769528 -``` - -{

Import ethers.js

} - -```js file=/public/tutorials/cross-dom-solidity.js#L4 hash=69a65ef97862612e4978b8563e6dbe3a +```js file=/public/tutorials/cross-dom-solidity.js#L3-L5 hash=ed24e2f752f8c16ded84de74af10589d ``` {

Load your private key

} -```js file=/public/tutorials/cross-dom-solidity.js#L6 hash=755b77a7ffc7dfdc186f36c37d3d847a +```js file=/public/tutorials/cross-dom-solidity.js#L7 hash=f5211d75b2d19d7fd6da17ef02449e4b ``` {

Load your transaction hash

} -```js file=/public/tutorials/cross-dom-solidity.js#L8 hash=320cd4f397d7bed8d914d4be0c99f8dc +```js file=/public/tutorials/cross-dom-solidity.js#L9 hash=320cd4f397d7bed8d914d4be0c99f8dc ``` {

Create the RPC providers and wallets

} -```js file=/public/tutorials/cross-dom-solidity.js#L10-L13 hash=9afdce50665ae93bce602068071ffaa1 -``` - -{

Create a CrossChainMessenger instance

} - -The Optimism SDK exports a `CrossChainMessenger` class that makes it easy to prove and relay cross-chain messages. - -Create an instance of the `CrossChainMessenger` class: - -```js file=/public/tutorials/cross-dom-solidity.js#L15-L20 hash=997b9c4cdd5fb1f9d4e0882a683ae016 +```js file=/public/tutorials/cross-dom-solidity.js#L11-L12 hash=cedcc56e3200a039274dda506a897cb6 ``` {

Wait until the message is ready to prove

} -The second step to send messages from L2 to L1 is to prove that the message was sent on L2. +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#L23 hash=25a072666b6147f8d8983d8223f045b8 +```js file=/public/tutorials/cross-dom-solidity.js#L17-L20 hash=be084e2a13c2cad44f6354feeb2bcbcb ``` @@ -240,7 +216,7 @@ 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#L26 hash=17922abea43b3d379404fedd87422dde +```js file=/public/tutorials/cross-dom-solidity.js#L23-L27 hash=1af494e8b4c1533bc9d1ce981f7ec88c ``` {

Wait until the message is ready for relay

} @@ -253,21 +229,21 @@ On OP Mainnet, 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#L29 hash=45d995aab47ec29afee4bb4577ae9303 +```js file=/public/tutorials/cross-dom-solidity.js#L30-L33 hash=ef3598d29f837b59cfb89e7bbbc0645d ``` {

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#L32 hash=b5515811ffcf8b9ada15dea8ae666e44 +```js file=/public/tutorials/cross-dom-solidity.js#L36-L40 hash=c3e5c5d15c048c231397aebcb92eef2c ``` {

Wait until the message is relayed

} Now you simply wait until the message is relayed. -```js file=/public/tutorials/cross-dom-solidity.js#L35 hash=d6e7f89e929eea0ac3217a6751b7e578 +```js file=/public/tutorials/cross-dom-solidity.js#L43-L46 hash=e9da5a2b27185b0b948ac45b2d42a7f9 ``` {

Check the L1 Greeter

} diff --git a/public/tutorials/cross-dom-solidity.js b/public/tutorials/cross-dom-solidity.js index 9ddafb16..fba881eb 100644 --- a/public/tutorials/cross-dom-solidity.js +++ b/public/tutorials/cross-dom-solidity.js @@ -1,37 +1,47 @@ (async () => { -const optimism = require("@eth-optimism/sdk") -const ethers = require("ethers") +const { createPublicClient, http } = require('viem'); +const { optimismSepolia } = require('viem/chains'); +const { publicActionsL2 } = require('viem/op-stack'); -const privateKey = process.env.TUTORIAL_PRIVATE_KEY +const privateKey = process.env.TUTORIAL_PRIVATE_KE const transactionHash = process.env.TUTORIAL_TRANSACTION_HASH -const l1Provider = new ethers.providers.StaticJsonRpcProvider("https://rpc.ankr.com/eth_sepolia") -const l2Provider = new ethers.providers.StaticJsonRpcProvider("https://sepolia.optimism.io") -const l1Wallet = new ethers.Wallet(privateKey, l1Provider) -const l2Wallet = new ethers.Wallet(privateKey, l2Provider) - -const messenger = new optimism.CrossChainMessenger({ - l1ChainId: 11155111, // 11155111 for Sepolia, 1 for Ethereum - l2ChainId: 11155420, // 11155420 for OP Sepolia, 10 for OP Mainnet - l1SignerOrProvider: l1Wallet, - l2SignerOrProvider: l2Wallet, -}) +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 messenger.waitForMessageStatus(transactionHash, optimism.MessageStatus.READY_TO_PROVE) +await l1Provider.getWithdrawalStatus({ + receipt, + targetChain: l2Provider.chain, +}) console.log('Proving message...') -await messenger.proveMessage(transactionHash) +const receipt = await l2Provider.getTransactionReceipt(transactionHash) +const output = await l1Provider.waitToProve({ + receipt, + targetChain: l2Provider.chain, +}) console.log('Waiting for message to be relayable...') -await messenger.waitForMessageStatus(transactionHash, optimism.MessageStatus.READY_FOR_RELAY) +await l1Provider.getWithdrawalStatus({ + receipt, + targetChain: l2Provider.chain, +}) console.log('Relaying message...') -await messenger.finalizeMessage(transactionHash) +const [message] = getWithdrawals(receipt) +await l1Provider.waitToFinalize({ + withdrawalHash: message.withdrawalHash, + targetChain: l2Provider.chain +}) console.log('Waiting for message to be relayed...') -await messenger.waitForMessageStatus(transactionHash, optimism.MessageStatus.RELAYED) +await l1Provider.getWithdrawalStatus({ + receipt, + targetChain: l2Provider.chain, +}) + })()