Skip to content

Stylus ERC20 template for CLI #7192

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

Merged
merged 1 commit into from
May 29, 2025
Merged

Stylus ERC20 template for CLI #7192

merged 1 commit into from
May 29, 2025

Conversation

kumaryash90
Copy link
Member

@kumaryash90 kumaryash90 commented May 29, 2025


PR-Codex overview

This PR enhances the create.ts and builder.ts files in the Stylus project CLI by adding project type selection and improving contract name extraction from ABI output.

Detailed summary

  • In create.ts, added prompts for selecting project type (Default or ERC20).
  • Updated project creation logic based on selected type.
  • In builder.ts, improved contract name selection from ABI output using prompts.
  • Renamed extractContractNameFromExportAbi to extractContractNamesFromExportAbi to return multiple contract names.
  • Adjusted references to use selected contract names throughout the build process.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added support for handling multiple contract ABIs, allowing users to select a contract entrypoint when more than one is present.
    • Introduced a prompt to select a project template type ("default" or "erc20") during project creation.
  • Improvements

    • Enhanced error handling and user guidance when no contract is selected or found.
    • Updated success messages and console output for improved clarity.

@kumaryash90 kumaryash90 requested review from a team as code owners May 29, 2025 00:40
Copy link

changeset-bot bot commented May 29, 2025

⚠️ No Changeset found

Latest commit: 16482cf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented May 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:19am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:19am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:19am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:19am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:19am

Copy link
Contributor

graphite-app bot commented May 29, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Contributor

coderabbitai bot commented May 29, 2025

Walkthrough

The changes introduce enhanced user interaction in the CLI for Stylus contract development. The build command now supports multiple contract ABIs, prompting the user to select one if several are detected. The project creation command adds a template selection step, allowing users to choose between a default or ERC20 template for new projects.

Changes

File(s) Change Summary
packages/thirdweb/src/cli/commands/stylus/builder.ts Refactored ABI handling to support multiple contracts, added user prompt for contract selection, improved error handling, and updated contract name extraction logic.
packages/thirdweb/src/cli/commands/stylus/create.ts Added template selection prompt (default or ERC20), introduced branching logic for project scaffolding, and updated user feedback messages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant FileSystem
    participant Repo

    User->>CLI: Run "stylus create"
    CLI->>User: Prompt for project template (default or erc20)
    User->>CLI: Selects template
    alt default template
        CLI->>FileSystem: Run "cargo stylus new <projectName>"
    else erc20 template
        CLI->>Repo: Clone "stylus-erc20-template.git"
        Repo-->>CLI: Template files
    end
    CLI->>User: Show success message
Loading
sequenceDiagram
    participant User
    participant CLI
    participant FileSystem

    User->>CLI: Run "stylus build"
    CLI->>FileSystem: Read ABI output
    CLI->>CLI: Parse contract names from ABI
    alt Multiple contracts found
        CLI->>User: Prompt to select contract
        User->>CLI: Selects contract
    else One contract found
        CLI->>CLI: Select contract automatically
    end
    CLI->>CLI: Extract ABI for selected contract
    CLI->>User: Proceed with build using selected contract
Loading

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92ee251 and 16482cf.

📒 Files selected for processing (2)
  • packages/thirdweb/src/cli/commands/stylus/builder.ts (5 hunks)
  • packages/thirdweb/src/cli/commands/stylus/create.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/thirdweb/src/cli/commands/stylus/create.ts
  • packages/thirdweb/src/cli/commands/stylus/builder.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Lint Packages
  • GitHub Check: Size
  • GitHub Check: Build Packages
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 0

🧹 Nitpick comments (2)
packages/thirdweb/src/cli/commands/stylus/create.ts (1)

63-63: Consider using HTTPS URL instead of SSH for better compatibility.

The hardcoded SSH URL may cause issues for users who haven't set up SSH keys with GitHub. Consider using HTTPS format for broader compatibility.

-    const repoUrl = "git@github.com:thirdweb-example/stylus-erc20-template.git";
+    const repoUrl = "https://github.com/thirdweb-example/stylus-erc20-template.git";
packages/thirdweb/src/cli/commands/stylus/builder.ts (1)

105-127: Consider adding validation for selectedIndex bounds checking.

While the current implementation handles the case where no contract is selected, consider adding explicit bounds checking to ensure the selectedIndex is within the valid range of contractNames array.

      const selectedIndex = response.contract;

      if (typeof selectedIndex !== "number") {
        spinner.fail("No contract selected.");
        process.exit(1);
      }

+     if (selectedIndex < 0 || selectedIndex >= contractNames.length) {
+       spinner.fail("Invalid contract selection.");
+       process.exit(1);
+     }

      selectedContractName = contractNames[selectedIndex]?.replace(/^I/, "");
      selectedAbiContent = parts[selectedIndex];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0731831 and 92ee251.

📒 Files selected for processing (2)
  • packages/thirdweb/src/cli/commands/stylus/builder.ts (5 hunks)
  • packages/thirdweb/src/cli/commands/stylus/create.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Lint Packages
  • GitHub Check: Size
  • GitHub Check: Unit Tests
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/thirdweb/src/cli/commands/stylus/create.ts (2)

41-50: LGTM! Template selection implementation is clean.

The template selection prompt follows the established pattern and provides clear options for users.


53-72:

✅ Verification successful

Verify error handling consistency across both project creation paths.

Both paths have proper error handling with spinners, but ensure the error messages and exit behavior are consistent between the default cargo command and git clone operations.


🏁 Script executed:

#!/bin/bash
# Description: Check if the thirdweb-example/stylus-erc20-template repository exists and is accessible

# Test: Verify the repository exists and is publicly accessible
curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/thirdweb-example/stylus-erc20-template

Length of output: 112


Error handling consistency confirmed

The ERC20 template repo is publicly accessible (HTTP 200), and both the cargo stylus new and git clone flows use the same spinner.fail("Failed to create Stylus project."); message followed by process.exit(1). No changes required here.

packages/thirdweb/src/cli/commands/stylus/builder.ts (3)

6-6: LGTM! Import addition is appropriate.

The prompts import is correctly added to support the new contract selection functionality.


99-137: Excellent enhancement for multi-contract support with robust error handling.

The implementation properly handles both single and multiple contract scenarios, with clear user prompts and comprehensive error checking. The logic flow is well-structured and maintains consistency with the existing codebase patterns.


216-220:

❓ Verification inconclusive

Validate the regex pattern for contract name extraction.

The regex pattern /<stdin>:(I?[A-Za-z0-9_]+)/g should be verified to ensure it correctly matches all valid Stylus contract name formats.


🏁 Script executed:

#!/bin/bash
# Description: Search for examples of Stylus ABI export output to validate the regex pattern

# Search for examples of contract name patterns in Stylus-related files
rg -A 5 -B 5 "export-abi|<stdin>:" --type rust

Length of output: 197


Please verify the regex against actual Stylus CLI output

I couldn’t find any example export-abi outputs in the repo to confirm that the pattern
/<stdin>:(I?[A-Za-z0-9_]+)/g covers all valid contract names (interfaces, special characters, etc.).

• No occurrences of export-abi or <stdin>: were found in the codebase to test against.
• Please run the Stylus CLI (e.g. stylus export-abi …) and share sample output.
• Confirm that your regex captures every contract name format (consider interfaces, dashes, numbers).

Copy link
Contributor

github-actions bot commented May 29, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 61.7 KB (0%) 1.3 s (0%) 602 ms (+734.11% 🔺) 1.9 s
thirdweb (cjs) 344.53 KB (0%) 6.9 s (0%) 985 ms (+63.81% 🔺) 7.9 s
thirdweb (minimal + tree-shaking) 5.69 KB (0%) 114 ms (0%) 61 ms (+931.94% 🔺) 175 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 15 ms (+857.46% 🔺) 25 ms
thirdweb/react (minimal + tree-shaking) 19.54 KB (0%) 391 ms (0%) 59 ms (+483.7% 🔺) 450 ms

Copy link

codecov bot commented May 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.67%. Comparing base (e8a25d7) to head (16482cf).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7192   +/-   ##
=======================================
  Coverage   55.67%   55.67%           
=======================================
  Files         904      904           
  Lines       58391    58391           
  Branches     4119     4116    -3     
=======================================
  Hits        32510    32510           
+ Misses      25776    25775    -1     
- Partials      105      106    +1     
Flag Coverage Δ
packages 55.67% <ø> (ø)

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member Author

kumaryash90 commented May 29, 2025

Merge activity

<!--

## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes"

If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000):

## Notes for the reviewer

Anything important to call out? Be sure to also clarify these in your comments.

## How to test

Unit tests, playground, etc.

-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR enhances the `create.ts` and `builder.ts` files for the Stylus project by adding project type selection and improving contract name handling during ABI processing. It introduces prompts for user input and refines how contract names are extracted and utilized.

### Detailed summary
- In `create.ts`, added prompts for selecting project type (Default or ERC20).
- Updated project creation logic based on the selected type.
- In `builder.ts`, improved contract name extraction to handle multiple contracts.
- Added prompts for selecting the entrypoint if multiple contracts are found.
- Refined usage of selected contract names throughout the build process.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **New Features**
  - Added support for handling multiple contract ABIs, allowing users to select a contract entrypoint when more than one is present.
  - Introduced a prompt to select a project template type ("default" or "erc20") during project creation.

- **Improvements**
  - Enhanced error handling and user guidance when no contract is selected or found.
  - Updated success messages and console output for improved clarity.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants