Skip to content

How do use cast to relay messages #1589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

qbzzt
Copy link
Contributor

@qbzzt qbzzt commented Apr 29, 2025

Description

A separate tutorial because this is a rare edge case.

Tests

N/A

Additional context

Remove https://docs.optimism.io/interop/tutorials/relay-messages-cast and https://docs.optimism.io/interop/tutorials/relay-messages-viem because they are redundant.

After #1581 is merged, it would be a good idea to move https://docs.optimism.io/interop/tutorials/message-passing#implement-manual-message-relaying to the same place as the cast tutorial - they are very similar.

Metadata

N/A

@qbzzt qbzzt requested a review from a team as a code owner April 29, 2025 02:25
Copy link

netlify bot commented Apr 29, 2025

Deploy Preview for docs-optimism failed. Why did it fail? →

Built without sensitive environment variables

Name Link
🔨 Latest commit 11add36
🔍 Latest deploy log https://app.netlify.com/sites/docs-optimism/deploys/681116687bf35700081b012c

Copy link
Contributor

coderabbitai bot commented Apr 29, 2025

📝 Walkthrough

"""

Walkthrough

This change introduces a new manual relay transaction tutorial for blockchain interoperability using the Foundry cast tool. It adds a metadata JSON file (_meta.json) describing the tutorial, a detailed Markdown tutorial file (relay-with-cast.mdx), and a shell script (setup-for-manual-relay.sh) that automates the setup of a local cross-chain messaging environment. The shell script creates and deploys two Solidity contracts—Greeter and GreetingSender—on separate local chains, sets up the necessary dependencies, and provides a helper script (sendAndRelay.sh) to demonstrate sending and manually relaying a cross-chain message. The tutorial guides users through the entire process, including event log extraction, relay message construction, and access list generation, culminating in the successful relay of a message between two chains.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChainA
    participant ChainB
    participant SupersimRPC

    User->>ChainA: Deploy GreetingSender contract
    User->>ChainB: Deploy Greeter contract
    User->>ChainA: Call setGreeting() on GreetingSender
    ChainA-->>User: Emit SentMessage event
    User->>User: Extract event log and construct payload
    User->>SupersimRPC: Request access list for relay tx
    SupersimRPC-->>User: Return access list
    User->>ChainB: Call relayMessage() on CrossDomainMessenger with payload and access list
    ChainB-->>User: Greeter greeting updated
Loading

Possibly related PRs

Suggested reviewers

  • krofax
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14ea7d0 and 11add36.

📒 Files selected for processing (5)
  • pages/interop/reading-logs.mdx (1 hunks)
  • pages/interop/tutorials.mdx (0 hunks)
  • pages/interop/tutorials/_meta.json (1 hunks)
  • pages/interop/tutorials/relay-messages-cast.mdx (0 hunks)
  • pages/interop/tutorials/relay-messages-viem.mdx (0 hunks)
💤 Files with no reviewable changes (3)
  • pages/interop/tutorials.mdx
  • pages/interop/tutorials/relay-messages-viem.mdx
  • pages/interop/tutorials/relay-messages-cast.mdx
✅ Files skipped from review due to trivial changes (2)
  • pages/interop/reading-logs.mdx
  • pages/interop/tutorials/_meta.json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (5)
public/tutorials/setup-for-manual-relay.sh (2)

86-90: Add error handling for directory changes
Similar to the initial cd, wrap cd lib and cd .. with || exit 1 or set strict mode so failed directory changes abort:

- cd lib
+ cd lib || exit 1
...
- cd ..
+ cd .. || exit 1
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 86-86: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


91-93: Use a more robust download command
Replace wget with a fail-safe curl invocation (or ensure wget -q errors are caught):

- wget https://raw.githubusercontent.com/.../IL2ToL2CrossDomainMessenger.sol
+ curl -fsSL https://raw.githubusercontent.com/.../IL2ToL2CrossDomainMessenger.sol -o IL2ToL2CrossDomainMessenger.sol
pages/interop/tutorials/message-passing/relay-with-cast.mdx (3)

24-28: Remove unused import
Callout is imported but never used. Please remove the unused import to keep the code clean:

- import { Callout } from 'nextra/components'

59-59: Use sentence case for H3 headings
Change “### What You'll Build” to:

### What you'll build

to comply with sentence-case rules for headers.


101-102: Avoid exposing private key in docs snippet
Displaying the hardcoded private key in the tutorial may confuse readers or leak test credentials. Replace it with a placeholder or instruct the user to set their own:

- PRIVATE_KEY=0xac0974bec39a...
+ PRIVATE_KEY=<YOUR_SUPERSIM_PRIVATE_KEY>
🧰 Tools
🪛 Gitleaks (8.21.2)

101-101: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78a9fcb and 14ea7d0.

📒 Files selected for processing (3)
  • pages/interop/tutorials/message-passing/_meta.json (1 hunks)
  • pages/interop/tutorials/message-passing/relay-with-cast.mdx (1 hunks)
  • public/tutorials/setup-for-manual-relay.sh (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.mdx`: "ALWAYS review Markdown content THOROUGHLY with the following criteria: - First, check the frontmatter section at the top of the file: 1. For regular pages, ensure AL...

**/*.mdx: "ALWAYS review Markdown content THOROUGHLY with the following criteria:

  • First, check the frontmatter section at the top of the file:
    1. For regular pages, ensure ALL these fields are present and not empty:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    personas: [non-empty array]
    categories: [non-empty array]
    content_type: [valid type]
    ---
    1. For landing pages (index.mdx or files with ), only these fields are required:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    ---
    1. If any required fields are missing or empty, comment:
      'This file appears to be missing required metadata. Please check keywords.config.yaml for valid options and add the required fields manually. You can validate your changes by running:
    pnpm validate-metadata
    ```'
  • Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
  • Avoid gender-specific language and use the imperative form.
  • Monitor capitalization for emphasis. Avoid using all caps, italics, or bold for emphasis.
  • Ensure proper nouns are capitalized in sentences.
  • Apply the Oxford comma.
  • Use proper title case for buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
  • Use correct spelling and grammar at all times (IMPORTANT).
  • For H1, H2, and H3 headers:
    1. Use sentence case, capitalizing only the first word.
    2. Preserve the capitalization of proper nouns, technical terms, and acronyms as defined in the 'nouns.txt' file located in the root directory of the project.
    3. Do not automatically lowercase words that appear in the 'nouns.txt' file, regardless of their position in the header.
  • Flag any headers that seem to inconsistently apply these rules for manual review.
  • When reviewing capitalization, always refer to the 'nouns.txt' file for the correct capitalization of proper nouns and technical terms specific to the project.
    "
  • pages/interop/tutorials/message-passing/relay-with-cast.mdx
🪛 Biome (1.9.4)
pages/interop/tutorials/message-passing/_meta.json

[error] 2-3: Expected a property but instead found '}'.

Expected a property here.

(parse)

🪛 Gitleaks (8.21.2)
pages/interop/tutorials/message-passing/relay-with-cast.mdx

101-101: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

public/tutorials/setup-for-manual-relay.sh

7-7: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🪛 Shellcheck (0.10.0)
public/tutorials/setup-for-manual-relay.sh

[warning] 5-5: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


[warning] 86-86: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


[warning] 97-97: Use semicolon or linefeed before 'done' (or quote to make it literal).

(SC1010)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - docs-optimism
  • GitHub Check: Header rules - docs-optimism
  • GitHub Check: Pages changed - docs-optimism
🔇 Additional comments (2)
public/tutorials/setup-for-manual-relay.sh (2)

13-53: Contract Greeter implementation looks solid
The SPDX license, pragma, imports, and event logic for cross-domain messaging are all correctly defined and follow best practices.


55-83: Contract GreetingSender implementation looks good
Constructor arguments and the setGreeting relay logic using abi.encodeCall are appropriately implemented.

Comment on lines +1 to +6
#! /bin/sh

rm -rf manual-relay
mkdir manual-relay
cd manual-relay

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure safe script execution and error handling
Add strict mode and handle cd failures to prevent the script from continuing on error. For example, right after the shebang add:

+ set -euo pipefail

and change:

- cd manual-relay
+ cd manual-relay || exit 1
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 5-5: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

Comment on lines +7 to +11
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
USER_ADDRESS=`cast wallet address --private-key $PRIVATE_KEY`
URL_CHAIN_A=http://localhost:9545
URL_CHAIN_B=http://localhost:9546

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid hardcoding private keys in source
Embedding a private key in the script can leak sensitive credentials. Instead, load the key from an environment variable or CLI argument and validate it before use:

- PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
+ : "${PRIVATE_KEY:?Environment variable PRIVATE_KEY must be set}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
USER_ADDRESS=`cast wallet address --private-key $PRIVATE_KEY`
URL_CHAIN_A=http://localhost:9545
URL_CHAIN_B=http://localhost:9546
# public/tutorials/setup-for-manual-relay.sh
# Ensure PRIVATE_KEY is provided via env var, don’t hard-code it
: "${PRIVATE_KEY:?Environment variable PRIVATE_KEY must be set}"
USER_ADDRESS=`cast wallet address --private-key $PRIVATE_KEY`
URL_CHAIN_A=http://localhost:9545
URL_CHAIN_B=http://localhost:9546
🧰 Tools
🪛 Gitleaks (8.21.2)

7-7: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Comment on lines +2 to +3
"relay-with-cast": "Manual relay transaction",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix invalid JSON (remove trailing comma)
The trailing comma after the single property makes this file unparsable. Remove it:

-     "relay-with-cast": "Manual relay transaction",
+     "relay-with-cast": "Manual relay transaction"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"relay-with-cast": "Manual relay transaction",
}
"relay-with-cast": "Manual relay transaction"
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 2-3: Expected a property but instead found '}'.

Expected a property here.

(parse)

import { InteropCallout } from '@/components/WipCallout'
import { AutorelayCallout } from '@/components/AutorelayCallout'

# Manual relay transactions tutorial
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Align H1 with frontmatter title
The H1 reads “Manual relay transactions tutorial” but the frontmatter title is singular (“Manual relay transaction tutorial”). Please make them consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants