Skip to content

Commit 54b7e7b

Browse files
Message passing fix
1 parent 2d467b9 commit 54b7e7b

File tree

2 files changed

+76
-76
lines changed

2 files changed

+76
-76
lines changed

pages/stack/interop/message-passing.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ sequenceDiagram
104104

105105
5. If everything checks out, `L2ToL2CrossDomainMessenger` calls the destination contract with the calldata provided in the message.
106106

107-
## Next steps dasd
107+
## Next steps
108108

109-
* Read how [messages get from one blockchain to another (`CrossL2Inbox`)](explainer#how-messages-get-from-one-chain-to-the-other).
110-
* Try [Supersim](tools/supersim) for testing cross-chain messages locally.
111-
* Learn about [manually relaying messages](/stack/interop/tutorials/relay-messages-viem).
109+
* Read how [messages get from one blockchain to another (`CrossL2Inbox`)](explainer#how-messages-get-from-one-chain-to-the-other).
110+
* Try [Supersim](tools/supersim) for testing cross-chain messages locally.
111+
* Learn about [manually relaying messages](/stack/interop/tutorials/relay-messages-viem).
112112

113113
{/* After the tutorial for L2ToL2CrossDomainMessenger is written, need to add a link here */}

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

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -155,49 +155,49 @@ For development purposes, we'll first use autorelay mode to handle message execu
155155
GREETER_B_ADDR=`forge create --rpc-url $RPC_B --private-key $PRIV_KEY Greeter --broadcast | awk '/Deployed to:/ {print $3}'`
156156
```
157157

158-
<details>
159-
<summary>Explanation</summary>
158+
<details>
159+
<summary>Explanation</summary>
160160

161-
The command that deploys the contract is:
161+
The command that deploys the contract is:
162162

163-
```sh
164-
forge create --rpc-url $RPC_B --private-key $PRIV_KEY Greeter --broadcast
165-
```
163+
```sh
164+
forge create --rpc-url $RPC_B --private-key $PRIV_KEY Greeter --broadcast
165+
```
166166

167-
The command output gives us the deployer address, the address of the new contract, and the transaction hash:
167+
The command output gives us the deployer address, the address of the new contract, and the transaction hash:
168168

169-
```
170-
Deployer: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
171-
Deployed to: 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707
172-
Transaction hash: 0xf155d360ec70ee10fe0e02d99c16fa5d6dc2a0e79b005fec6cbf7925ff547dbf
173-
```
169+
```
170+
Deployer: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
171+
Deployed to: 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707
172+
Transaction hash: 0xf155d360ec70ee10fe0e02d99c16fa5d6dc2a0e79b005fec6cbf7925ff547dbf
173+
```
174174

175-
The [`awk`](https://www.tutorialspoint.com/awk/index.htm) command looks for the line that has `Deployed to:` and writes the third word in that line, which is the address.
175+
The [`awk`](https://www.tutorialspoint.com/awk/index.htm) command looks for the line that has `Deployed to:` and writes the third word in that line, which is the address.
176176

177-
```sh
178-
awk '/Deployed to:/ {print $3}'
179-
```
177+
```sh
178+
awk '/Deployed to:/ {print $3}'
179+
```
180180

181-
Finally, in UNIX (including Linux and macOS) the when the command line includes backticks (\`\`\`), the shell executes the code between the backticks and puts the output, in this case the contract address, in the command.
182-
So we get.
181+
Finally, in UNIX (including Linux and macOS) the when the command line includes backticks (\`\`\`), the shell executes the code between the backticks and puts the output, in this case the contract address, in the command.
182+
So we get.
183183

184-
```sh
185-
GREETER_B_ADDR=<the address>
186-
```
187-
</details>
184+
```sh
185+
GREETER_B_ADDR=<the address>
186+
```
187+
</details>
188188

189-
<details>
190-
<summary>Sanity check</summary>
189+
<details>
190+
<summary>Sanity check</summary>
191191

192-
Run these commands to verify the contract works.
193-
The first and third commands retrieve the current greeting, while the second command updates it.
192+
Run these commands to verify the contract works.
193+
The first and third commands retrieve the current greeting, while the second command updates it.
194194

195-
```sh
196-
cast call --rpc-url $RPC_B $GREETER_B_ADDR "greet()" | cast --to-ascii
197-
cast send --private-key $PRIV_KEY --rpc-url $RPC_B $GREETER_B_ADDR "setGreeting(string)" Hello
198-
cast call --rpc-url $RPC_B $GREETER_B_ADDR "greet()" | cast --to-ascii
199-
```
200-
</details>
195+
```sh
196+
cast call --rpc-url $RPC_B $GREETER_B_ADDR "greet()" | cast --to-ascii
197+
cast send --private-key $PRIV_KEY --rpc-url $RPC_B $GREETER_B_ADDR "setGreeting(string)" Hello
198+
cast call --rpc-url $RPC_B $GREETER_B_ADDR "greet()" | cast --to-ascii
199+
```
200+
</details>
201201

202202
4. Install the Optimism Solidity libraries into the project.
203203

@@ -222,18 +222,18 @@ For development purposes, we'll first use autorelay mode to handle message execu
222222
```solidity file=<rootDir>/public/tutorials/GreetingSender.sol#L1-L28 hash=75d197d1e1da112421785c2160f6a55a
223223
```
224224

225-
<details>
226-
<summary>Explanation</summary>
225+
<details>
226+
<summary>Explanation</summary>
227227

228-
```solidity file=<rootDir>/public/tutorials/GreetingSender.sol#L21-L27 hash=6c27ebcf4916e5aa2325d30f99c65436
229-
```
228+
```solidity file=<rootDir>/public/tutorials/GreetingSender.sol#L21-L27 hash=6c27ebcf4916e5aa2325d30f99c65436
229+
```
230230

231-
This function encodes a call to `setGreeting` and sends it to a contract on another chain.
232-
`abi.encodeCall(Greeter.setGreeting, (greeting))` constructs the [calldata](https://docs.soliditylang.org/en/latest/internals/layout_in_calldata.html) by encoding the function selector and parameters.
233-
The encoded message is then passed to `messenger.sendMessage`, which forwards it to the destination contract (`greeterAddress`) on the specified chain (`greeterChainId`).
231+
This function encodes a call to `setGreeting` and sends it to a contract on another chain.
232+
`abi.encodeCall(Greeter.setGreeting, (greeting))` constructs the [calldata](https://docs.soliditylang.org/en/latest/internals/layout_in_calldata.html) by encoding the function selector and parameters.
233+
The encoded message is then passed to `messenger.sendMessage`, which forwards it to the destination contract (`greeterAddress`) on the specified chain (`greeterChainId`).
234234

235-
This ensures that `setGreeting` is executed remotely with the provided `greeting` value (as long as there is an executing message to relay it).
236-
</details>
235+
This ensures that `setGreeting` is executed remotely with the provided `greeting` value (as long as there is an executing message to relay it).
236+
</details>
237237

238238
7. Deploy `GreetingSender` to chain A.
239239

@@ -315,19 +315,19 @@ In this section we change `Greeter.sol` to emit a separate event in it receives
315315
}
316316
```
317317

318-
<details>
319-
<summary>Explanation</summary>
318+
<details>
319+
<summary>Explanation</summary>
320320

321-
```solidity
322-
if (msg.sender == Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER) {
323-
(address sender, uint256 chainId) =
324-
messenger.crossDomainMessageContext();
325-
emit CrossDomainSetGreeting(sender, chainId, _greeting);
326-
}
327-
```
321+
```solidity
322+
if (msg.sender == Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER) {
323+
(address sender, uint256 chainId) =
324+
messenger.crossDomainMessageContext();
325+
emit CrossDomainSetGreeting(sender, chainId, _greeting);
326+
}
327+
```
328328

329-
If we see that we got a message from `L2ToL2CrossDomainMessenger`, we call [`L2ToL2CrossDomainMessenger.crossDomainMessageContext`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L118-L126).
330-
</details>
329+
If we see that we got a message from `L2ToL2CrossDomainMessenger`, we call [`L2ToL2CrossDomainMessenger.crossDomainMessageContext`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L118-L126).
330+
</details>
331331

332332
2. Redeploy the contracts.
333333
Because the address of `Greeter` is immutable in `GreetingSender`, we need to redeploy both contracts.
@@ -497,36 +497,36 @@ In production we will not have this, we need to create our own executing message
497497
```typescript file=<rootDir>/public/tutorials/app_v2.mts hash=a7b0f60aa6f1e48fc9994178ed3d5498
498498
```
499499

500-
<details>
501-
<summary>Explanation</summary>
500+
<details>
501+
<summary>Explanation</summary>
502502

503-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L11-L15 hash=721ed87241535b606be281539baa8770
504-
```
503+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L11-L15 hash=721ed87241535b606be281539baa8770
504+
```
505505

506-
Import from the [`@eth-optimism/viem`](https://www.npmjs.com/package/@eth-optimism/viem) package.
506+
Import from the [`@eth-optimism/viem`](https://www.npmjs.com/package/@eth-optimism/viem) package.
507507

508-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L22-L28 hash=ffa76edb1191121e15eb4286e16ad041
509-
```
508+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L22-L28 hash=ffa76edb1191121e15eb4286e16ad041
509+
```
510510

511-
In addition to extending the wallets with [Viem public actions](https://viem.sh/docs/accounts/local#5-optional-extend-with-public-actions), extend with the OP-Stack actions, both the public ones and the ones that require an account.
511+
In addition to extending the wallets with [Viem public actions](https://viem.sh/docs/accounts/local#5-optional-extend-with-public-actions), extend with the OP-Stack actions, both the public ones and the ones that require an account.
512512

513-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L59 hash=23aa6f24baeb5757130361f30c1b0e9c
514-
```
513+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L59 hash=23aa6f24baeb5757130361f30c1b0e9c
514+
```
515515

516-
To relay a message we need the information in the receipt.
517-
Also, we need to wait until the transaction with the relayed message is actually part of a block.
516+
To relay a message we need the information in the receipt.
517+
Also, we need to wait until the transaction with the relayed message is actually part of a block.
518518

519-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L61-L63 hash=da4b8733c578a393eb36f154a4e816e1
520-
```
519+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L61-L63 hash=da4b8733c578a393eb36f154a4e816e1
520+
```
521521

522-
A single transaction can send multiple messages.
523-
But here we know we sent just one, so we look for the first one in the list.
522+
A single transaction can send multiple messages.
523+
But here we know we sent just one, so we look for the first one in the list.
524524

525-
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L64-L70 hash=6bfcd99f2e79df79897d230f36d4a682
526-
```
525+
```typescript file=<rootDir>/public/tutorials/app_v2.mts#L64-L70 hash=6bfcd99f2e79df79897d230f36d4a682
526+
```
527527

528-
Here we first send the relay message on chain B, and then wait for the receipt for it.
529-
</details>
528+
Here we first send the relay message on chain B, and then wait for the receipt for it.
529+
</details>
530530

531531
2. Rerun the JavaScript program, and see that the message is relayed.
532532

0 commit comments

Comments
 (0)