Skip to content
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

Fix Missing Steps in "Communicating between OP Stack and Ethereum in Solidity" Tutorial #1326

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

krofax
Copy link
Collaborator

@krofax krofax commented Feb 6, 2025

Description

Summary

This PR addresses Issue #1217 by adding missing steps and updating outdated instructions in the "Communicating between OP Stack and Ethereum in Solidity" tutorial. The changes ensure that the tutorial aligns with the latest Viem APIs and correctly guides users through the withdrawal proving process.

Changes Introduced

  1. Updated Import Statements
  • Added missing imports for Viem modules .
  1. Removed Hardcoded transactionHash Reference
  • Removed const transactionHash = process.env.TUTORIAL_TRANSACTION_HASH, as it was incorrectly referenced later.
  • Instead, a new method for retrieving the transaction receipt has been introduced in Step 12.
  1. Updated RPC Provider and Wallet Initialization
  • Replaced older provider setup with createPublicClient and .extend(publicActionsL1()) / .extend(publicActionsL2()).
  • Updated wallet setup to use createWalletClient and .extend(walletActionsL1()).
  1. Added Proper Transaction Receipt Retrieval
  • Introduced await l2Provider.getTransactionReceipt({ hash: process.env.TUTORIAL_TRANSACTION_HASH }) to ensure proper receipt handling.

Tests

Additional context

Include a link to any github issues that this may close in the following form:

@krofax krofax requested a review from a team as a code owner February 6, 2025 17:07
Copy link

netlify bot commented Feb 6, 2025

Deploy Preview for docs-optimism ready!

Name Link
🔨 Latest commit 5789db6
🔍 Latest deploy log https://app.netlify.com/sites/docs-optimism/deploys/67ab6d23dd54d20008452705
😎 Deploy Preview https://deploy-preview-1326--docs-optimism.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

📝 Walkthrough

Walkthrough

This pull request updates the cross-domain Solidity tutorial by significantly enhancing wallet operations and transaction handling. The code in public/tutorials/cross-dom-solidity.js now imports additional functions from the viem library and creates wallet clients (l1Wallet and l2Wallet) using environment-sourced private keys. The transaction receipt retrieval has been refactored to pass an object with a hash property, and new methods—buildProveWithdrawal, proveWithdrawal, and finalizeWithdrawal—have been introduced to streamline the withdrawal proof process. Similar changes are reflected in the corresponding .mdx tutorial file, including updated headings and revised code snippets to maintain consistency with the new wallet-based workflow.

Sequence Diagram(s)

sequenceDiagram
    participant T as Tutorial Script
    participant L2 as l2Provider
    participant L1 as l1Wallet

    T->>L2: getTransactionReceipt({ hash: process.env.TUTORIAL_TRANSACTION_HASH })
    T->>L2: buildProveWithdrawal(parameters)
    L2-->>T: return withdrawal proof args
    T->>L1: proveWithdrawal(args)
    L1-->>T: return proveWithdrawal hash
    T->>L1: finalizeWithdrawal(withdrawal details)
    L1-->>T: return finalizeHash
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers

  • brokewhale
  • ZakAyesh
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3e5453 and 9a480c6.

📒 Files selected for processing (2)
  • pages/builders/app-developers/tutorials/cross-dom-solidity.mdx (3 hunks)
  • public/tutorials/cross-dom-solidity.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.mdx`: "ALWAYS review Markdown content THOROUGHLY with ...

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

  • 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/builders/app-developers/tutorials/cross-dom-solidity.mdx
🪛 ESLint
public/tutorials/cross-dom-solidity.js

[error] 3-3: Extra semicolon.

(semi)


[error] 4-4: Extra semicolon.

(semi)


[error] 5-5: Extra semicolon.

(semi)


[error] 6-6: Extra semicolon.

(semi)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pr-workflow

public/tutorials/cross-dom-solidity.js Outdated Show resolved Hide resolved
public/tutorials/cross-dom-solidity.js Show resolved Hide resolved
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: 2

🧹 Nitpick comments (4)
public/tutorials/cross-dom-solidity.js (2)

46-54: Add error handling for message relaying.

Consider adding try-catch blocks to handle potential failures during the relaying process.

 console.log('Waiting for message to be relayable...')
+try {
   await l1Provider.getWithdrawalStatus({ 
     receipt, 
     targetChain: l2Provider.chain, 
   }) 

   console.log('Relaying message...')
   const [message] = getWithdrawals(receipt)
   await l1Provider.waitToFinalize({ withdrawalHash: message.withdrawalHash, targetChain: l2Provider.chain }) 
+} catch (error) {
+  console.error('Failed to relay message:', error)
+  throw error
+}

56-62: Add error handling for withdrawal finalization.

Consider adding try-catch blocks to handle potential failures during the finalization process.

+try {
   const finalizeHash = await l1Wallet.finalizeWithdrawal({
     targetChain: l2Wallet.chain,
     withdrawal,
   })

   console.log('Waiting for message to be relayed...')
   await l1Provider.getWithdrawalStatus({ receipt, targetChain: l2Provider.chain }) 
+} catch (error) {
+  console.error('Failed to finalize withdrawal:', error)
+  throw error
+}
pages/app-developers/tutorials/bridging/cross-dom-solidity.mdx (2)

229-229: Add missing comma.

Add a comma after "relayed" in the sentence: "Once the withdrawal is ready to be relayed you can finally complete..."

-Once the withdrawal is ready to be relayed you can finally complete the message sending process.
+Once the withdrawal is ready to be relayed, you can finally complete the message sending process.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~229-~229: Possible missing comma found.
Context: ...3>} Once the withdrawal is ready to be relayed you can finally complete the message se...

(AI_HYDRA_LEO_MISSING_COMMA)


179-179: Fix capitalization in heading.

The heading "Import viem" should be "Import Viem" as Viem is a proper noun.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a480c6 and 5789db6.

📒 Files selected for processing (2)
  • pages/app-developers/tutorials/bridging/cross-dom-solidity.mdx (3 hunks)
  • public/tutorials/cross-dom-solidity.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.mdx`: "ALWAYS review Markdown content THOROUGHLY with ...

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

  • 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/app-developers/tutorials/bridging/cross-dom-solidity.mdx
🪛 LanguageTool
pages/app-developers/tutorials/bridging/cross-dom-solidity.mdx

[uncategorized] ~229-~229: Possible missing comma found.
Context: ...3>} Once the withdrawal is ready to be relayed you can finally complete the message se...

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 ESLint
public/tutorials/cross-dom-solidity.js

[error] 3-3: Extra semicolon.

(semi)


[error] 4-4: Extra semicolon.

(semi)


[error] 5-5: Extra semicolon.

(semi)


[error] 6-6: Extra semicolon.

(semi)

⏰ 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 (3)
public/tutorials/cross-dom-solidity.js (3)

3-6: Remove unnecessary semicolons.

Remove the semicolons at the end of import statements to comply with the project's coding style.

-const { createPublicClient, http, createWalletClient } = require("viem");
-const { optimismSepolia, sepolia } = require("viem/chains");
-const { publicActionsL1, publicActionsL2, walletActionsL1, walletActionsL2, getWithdrawals } = require("viem/op-stack");
-const { privateKeyToAccount } = require("viem/accounts");
+const { createPublicClient, http, createWalletClient } = require("viem")
+const { optimismSepolia, sepolia } = require("viem/chains")
+const { publicActionsL1, publicActionsL2, walletActionsL1, walletActionsL2, getWithdrawals } = require("viem/op-stack")
+const { privateKeyToAccount } = require("viem/accounts")
🧰 Tools
🪛 ESLint

[error] 3-3: Extra semicolon.

(semi)


[error] 4-4: Extra semicolon.

(semi)


[error] 5-5: Extra semicolon.

(semi)


[error] 6-6: Extra semicolon.

(semi)


22-24: LGTM! Secure transaction receipt retrieval.

The implementation correctly uses an environment variable for the transaction hash.


26-42: LGTM! Well-structured withdrawal proving process.

The implementation follows the correct sequence of operations and includes helpful progress logging.

public/tutorials/cross-dom-solidity.js Show resolved Hide resolved
public/tutorials/cross-dom-solidity.js Show resolved Hide resolved
@krofax krofax merged commit 6cbe69b into main Feb 11, 2025
8 checks passed
@krofax krofax deleted the fix-comms-tut branch February 11, 2025 16:07
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.

3 participants