11---
2- title : Communicating between OP Mainnet and Ethereum in Solidity
2+ title : Communicating between OP Stack and Ethereum in Solidity
33lang : en-US
4- description : Learn how to write Solidity contracts on OP Mainnet and Ethereum that can talk to each other.
4+ description : Learn how to write Solidity contracts on OP Stack and Ethereum that can talk to each other.
55---
66
77import { Steps , Callout , Tabs } from ' nextra/components'
8- import { WipCallout } from ' @/components/WipCallout'
98
10- <WipCallout />
11- # Communicating between OP Mainnet and Ethereum in Solidity
9+ # Communicating between OP Stack and Ethereum in Solidity
1210
13- This tutorial explains how to write Solidity contracts on OP Mainnet and Ethereum that can talk to each other.
14- Here you'll use a contract on OP Mainnet that can set a "greeting" variable on a contract on Ethereum, and vice-versa.
11+ This tutorial explains how to write Solidity contracts on OP Stack and Ethereum that can talk to each other.
12+ Here you'll use a contract on OP Stack that can set a "greeting" variable on a contract on Ethereum, and vice-versa.
1513This is a simple example, but the same technique can be used to send any kind of message between the two chains.
1614
1715You won't actually be deploying any smart contracts as part of this tutorial.
18- Instead, you'll reuse existing contracts that have already been deployed to OP Mainnet and Ethereum.
16+ Instead, you'll reuse existing contracts that have already been deployed to OP Stack and Ethereum.
1917Later in the tutorial you'll learn exactly how these contracts work so you can follow the same pattern to deploy your own contracts.
2018
2119<Callout type = " info" >
22- Just looking to bridge tokens between OP Mainnet and Ethereum?
23- Check out the tutorial on [ Bridging ERC-20 Tokens to OP Mainnet With the Optimism SDK ] ( ./cross-dom-bridge-erc20 ) .
20+ Just looking to bridge tokens between OP Stack and Ethereum?
21+ Check out the tutorial on [ Bridging ERC-20 Tokens to OP Stack With the viem ] ( ./cross-dom-bridge-erc20 ) .
2422</Callout >
2523
2624## Message passing basics
2725
28- OP Mainnet uses a smart contract called the ` CrossDomainMessenger ` to pass messages between OP Mainnet and Ethereum.
26+ OP Stack uses a smart contract called the ` CrossDomainMessenger ` to pass messages between OP Stack and Ethereum.
2927Both chains have a version of this contract (the ` L1CrossDomainMessenger ` and the ` L2CrossDomainMessenger ` ).
30- Messages sent from Ethereum to OP Mainnet are automatically relayed behind the scenes.
31- Messages sent from OP Mainnet to Ethereum must be explicitly relayed with a second transaction on Ethereum.
28+ Messages sent from Ethereum to OP Stack are automatically relayed behind the scenes.
29+ Messages sent from OP Stack to Ethereum must be explicitly relayed with a second transaction on Ethereum.
3230Read more about message passing in the guide to [ Sending Data Between L1 and L2] ( /builders/app-developers/bridging/messaging ) .
3331
3432## Dependencies
@@ -80,8 +78,8 @@ It will take a few minutes for your message to reach L2.
8078Feel free to take a quick break while you wait.
8179
8280<Callout type = " info" >
83- You can use the Optimism SDK to programmatically check the status of any message between L1 and L2.
84- Later on in this tutorial you'll learn how to use the Optimism SDK and the ` waitForMessageStatus ` function to wait for various message statuses.
81+ You can use Viem to programmatically check the status of any message between L1 and L2.
82+ Later on in this tutorial you'll learn how to use Viem and the ` waitToProve ` function to wait for various message statuses.
8583This same function can be used to wait for a message to be relayed from L1 to L2.
8684</Callout >
8785
@@ -127,36 +125,27 @@ Feel free to keep this tab open so you can easily copy the transaction hash late
127125
128126{ <h3 >Create a demo project folder</h3 >}
129127
130- You're going to use the Optimism SDK to prove and relay your message to L1.
131- Since the Optimism SDK is a [ Node.js] ( https://nodejs.org/en/ ) library, you'll need to create a Node.js project to use it.
128+ You're going to use the viem to prove and relay your message to L1.
132129
133130``` bash
134- mkdir op-sample-project
135- cd op-sample-project
131+ mkdir cross-dom
132+ cd cross-dom
136133```
137134
138- { <h3 >Initialize the Project </h3 >}
135+ { <h3 >Initialize the project </h3 >}
139136
140137Set up the project as a basic Node.js project with ` pnpm ` or your favorite package manager.
141138
142139``` bash
143140pnpm init
144141```
145142
146- { <h3 >Install the Optimism SDK </h3 >}
143+ { <h3 >Install viem </h3 >}
147144
148- Install the Optimism SDK with ` pnpm ` or your favorite package manager.
145+ Install Viem with ` pnpm ` or your favorite package manager.
149146
150147``` bash
151- pnpm add @eth-optimism/sdk
152- ```
153-
154- { <h3 >Install ethers.js</h3 >}
155-
156- Install ` ethers ` with ` pnpm ` or your favorite package manager.
157-
158- ``` bash
159- pnpm add ethers@^5
148+ pnpm add viem
160149```
161150
162151{ <h3 >Add your private key to your environment</h3 >}
@@ -187,46 +176,27 @@ Start the Node.js REPL with the `node` command.
187176node
188177```
189178
190- { <h3 >Import the Optimism SDK</h3 >}
191-
192- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L3 hash=26b2fdb17dd6c8326a54ec51f0769528
193- ```
194-
195- { <h3 >Import ethers.js</h3 >}
179+ { <h3 >Import Viem</h3 >}
196180
197- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L4 hash=69a65ef97862612e4978b8563e6dbe3a
198- ```
199-
200- { <h3 >Load your private key</h3 >}
201-
202- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L6 hash=755b77a7ffc7dfdc186f36c37d3d847a
181+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L3-L5 hash=65b9a5ad5b634bc2e424f5664e6e1f84
203182```
204183
205184{ <h3 >Load your transaction hash</h3 >}
206185
207- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L8 hash=320cd4f397d7bed8d914d4be0c99f8dc
186+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L7 hash=320cd4f397d7bed8d914d4be0c99f8dc
208187```
209188
210189{ <h3 >Create the RPC providers and wallets</h3 >}
211190
212- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L10-L13 hash=9afdce50665ae93bce602068071ffaa1
213- ```
214-
215- { <h3 >Create a CrossChainMessenger instance</h3 >}
216-
217- The Optimism SDK exports a ` CrossChainMessenger ` class that makes it easy to prove and relay cross-chain messages.
218-
219- Create an instance of the ` CrossChainMessenger ` class:
220-
221- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L15-L20 hash=997b9c4cdd5fb1f9d4e0882a683ae016
191+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L8-L9 hash=d47e4991c5153e1e1dc55de5047a8a3e
222192```
223193
224194{ <h3 >Wait until the message is ready to prove</h3 >}
225195
226- The second step to send messages from L2 to L1 is to prove that the message was sent on L2.
196+ Next, you will send messages from L2 to L1 is to prove that the message was sent on L2.
227197You first need to wait until the message is ready to prove.
228198
229- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L23 hash=25a072666b6147f8d8983d8223f045b8
199+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L12-L16 hash=df275e659d954eb72b8c5765d9baf6de
230200```
231201
232202<Callout type = " info" >
@@ -238,34 +208,34 @@ Feel free to take a quick break while you wait.
238208
239209Once the message is ready to be proven, you'll send an L1 transaction to prove that the message was sent on L2.
240210
241- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L26 hash=17922abea43b3d379404fedd87422dde
211+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L18-L23 hash=e4d608ac2c2ceb5a744c8474679bd8cb
242212```
243213
244214{ <h3 >Wait until the message is ready for relay</h3 >}
245215
246216The final step to sending messages from L2 to L1 is to relay the messages on L1.
247217This can only happen after the fault proof period has elapsed.
248- On OP Mainnet , this takes 7 days.
218+ On OP Stack , this takes 7 days.
249219
250220<Callout >
251221We're currently testing fault proofs on OP Sepolia, so withdrawal times reflect Mainnet times.
252222</Callout >
253223
254- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L29 hash=45d995aab47ec29afee4bb4577ae9303
224+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L25- L29 hash=88cec1db2fde515ea9008eaa1bbdfd73
255225```
256226
257227{ <h3 >Relay the message on L1</h3 >}
258228
259229Once the withdrawal is ready to be relayed you can finally complete the message sending process.
260230
261- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L32 hash=b5515811ffcf8b9ada15dea8ae666e44
231+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L31-L33 hash=d7e47c9787d92e2140622a6bdcc6d7bb
262232```
263233
264234{ <h3 >Wait until the message is relayed</h3 >}
265235
266236Now you simply wait until the message is relayed.
267237
268- ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L35 hash=d6e7f89e929eea0ac3217a6751b7e578
238+ ``` js file=<rootDir>/public/tutorials/cross-dom-solidity.js#L35-L36 hash=4ff3cdc48f17cfd7de4a6ef2d2671dc2
269239```
270240
271241{ <h3 >Check the L1 Greeter</h3 >}
@@ -348,10 +318,10 @@ You can follow a similar pattern in your own smart contracts.
348318## Conclusion
349319
350320You just learned how you can write Solidity contracts on Sepolia and OP Sepolia that can talk to each other.
351- You can follow the same pattern to write contracts that can talk to each other on Ethereum and OP Mainnet .
321+ You can follow the same pattern to write contracts that can talk to each other on Ethereum and OP Stack .
352322
353323This sort of cross-chain communication is useful for a variety of reasons.
354- For example, the [ Standard Bridge] ( /builders/app-developers/bridging/standard-bridge ) contracts use this same system to bridge ETH and ERC-20 tokens between Ethereum and OP Mainnet .
324+ For example, the [ Standard Bridge] ( /builders/app-developers/bridging/standard-bridge ) contracts use this same system to bridge ETH and ERC-20 tokens between Ethereum and OP Stack .
355325
356- One cool way to take advantage of cross-chain communication is to do most of your heavy lifting on OP Mainnet and then send a message to Ethereum only when you have important results to share.
357- This way you can take advantage of the low gas costs on OP Mainnet while still being able to use Ethereum when you need it.
326+ One cool way to take advantage of cross-chain communication is to do most of your heavy lifting on OP Stack and then send a message to Ethereum only when you have important results to share.
327+ This way you can take advantage of the low gas costs on OP Stack while still being able to use Ethereum when you need it.
0 commit comments