Fix outdated Stylus SDK API patterns and versions across docs#3189
Fix outdated Stylus SDK API patterns and versions across docs#3189
Conversation
The example showed RawDeploy::new(self.vm()).value(amount).deploy() but the actual API is RawDeploy::new().salt(salt).deploy(host, code, endowment). Verified against stylus-sdk-rs source.
- stylus/quickstart: update Rust minimum version 1.88→1.91 (matches SDK's rust-version), pin rust-toolchain.toml to 1.91.0 instead of "stable", update stylus-sdk dev-dependency 0.8.4→0.10.2 - 03-public-chains: update deprecated Stylus testnet section, fix grammar - arbitrum-bridge/01-quickstart: fix typo
- vm-differences: fix Vec<u256> -> Vec<U256> in code example - testing-contracts: update minimum Rust version 1.81→1.91 (matches SDK's rust-version in Cargo.toml)
- prerequisites: update expected rustc version 1.81→1.91 - global-variables-and-functions: replace developer.arbitrum.io external links with internal doc paths
The Stylus SDK v0.10 removed the evm module and msg module. The correct patterns are self.vm().log() for events and self.vm().msg_sender() for caller address. Also fixes incorrect migration table entries in choose-your-path (ensure! doesn't exist, Erase trait is wrong). Files updated: - project-structure.mdx - exporting-abi.mdx - gas-optimization.mdx - choose-your-path.mdx
- gas-optimization: replace block::timestamp() with self.vm().block_timestamp(), replace #[external] with #[public] on impl block, replace ensure! with explicit if-checks - exporting-abi: replace remaining msg::sender()/msg::value() with self.vm() equivalents
Bulk update Rust toolchain versions from 1.81/1.88 to 1.91 to match the SDK's minimum supported Rust version (rust-version = "1.91.0" in stylus-sdk Cargo.toml). Files updated: - trait-based-composition.mdx - using-cli.mdx - using-constructors.mdx - importing-interfaces.mdx - troubleshooting/common-issues.mdx
- common-issues.mdx: replace #[external] with #[public] in ABI troubleshooting example - contracts.mdx: replace all msg::value() with self.vm().msg_value(), update transfer_eth() to include host arg, fix function signatures - debugging-tx.mdx: replace #[external] with #[public]
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR updates the Stylus documentation to match the current stylus-sdk-rs API surface (v0.10.2) and Rust toolchain requirements (1.91.x), replacing deprecated patterns and refreshing version/link references across the Stylus docs set.
Changes:
- Updated Rust toolchain guidance and pinned versions (1.91 / 1.91.0) and
stylus-sdkdev-dependency references. - Replaced deprecated SDK API usages in examples (e.g.,
msg::*→self.vm().*,evm::log→self.vm().log,#[external]→#[public], updatedtransfer_eth/RawDeploycall shapes). - Fixed stale external links by pointing to current internal doc paths.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/stylus/advanced/rust-to-solidity-differences.mdx | Updates deployment example to current RawDeploy API shape. |
| docs/stylus/advanced/hostio-exports.mdx | Refreshes Arbitrum reference links to internal docs. |
| docs/stylus/quickstart.mdx | Pins Rust toolchain to 1.91.0 and updates stylus-sdk dev-dependency to 0.10.2. |
| docs/stylus/using-cli.mdx | Updates Rust toolchain prerequisites and WASM target setup examples to 1.91. |
| docs/stylus/concepts/vm-differences.mdx | Fixes outdated type usage in a code example (U256). |
| docs/stylus/cli-tools/overview.mdx | Updates Rust toolchain prerequisites to 1.91+. |
| docs/stylus/cli-tools/debugging-tx.mdx | Switches example attribute from #[external] to #[public]. |
| docs/stylus/fundamentals/testing-contracts.mdx | Updates Rust toolchain prerequisite version to 1.91+. |
| docs/stylus/fundamentals/prerequisites.mdx | Updates expected rustc version output to 1.91.0+. |
| docs/stylus/fundamentals/global-variables-and-functions.mdx | Updates L1↔L2 messaging/time links to internal doc paths. |
| docs/stylus/fundamentals/project-structure.mdx | Updates event logging and sender access patterns to self.vm() APIs. |
| docs/stylus/fundamentals/contracts.mdx | Updates ETH transfer examples to newer transfer_eth calling pattern and msg_value() access via VM. |
| docs/stylus/fundamentals/choose-your-path.mdx | Updates migration table entries to current SDK idioms (self.vm(), #[constructor], logging). |
| docs/stylus/best-practices/gas-optimization.mdx | Updates timestamp/sender/logging examples to new VM-based APIs and removes ensure! in one section. |
| docs/stylus/how-tos/exporting-abi.mdx | Updates sender/value/event logging examples to self.vm() APIs and reduces repeated lookups. |
| docs/stylus/how-tos/trait-based-composition.mdx | Updates Rust toolchain prerequisite + WASM setup commands to 1.91. |
| docs/stylus/how-tos/using-constructors.mdx | Updates Rust toolchain prerequisite + WASM setup commands to 1.91. |
| docs/stylus/how-tos/importing-interfaces.mdx | Updates Rust toolchain prerequisite + WASM setup commands to 1.91. |
| docs/stylus/troubleshooting/common-issues.mdx | Updates toolchain/attribute examples to 1.91 and #[public]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ```rust | ||
| // These are equivalent: | ||
| transfer_eth(recipient, value)?; | ||
| transfer_eth(self.vm(), recipient, value)?; | ||
| call(Call::new_in(self).value(value), recipient, &[])?; |
There was a problem hiding this comment.
This “equivalent under the hood” snippet isn’t self-contained: recipient and value are undefined, which makes it hard to copy/paste and verify. Consider either defining them in the snippet (e.g., as parameters/locals) or explicitly marking them as placeholders in comments.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Added explicit type annotations and placeholder values for recipient and value in commit 2f2b002 so the snippet is self-contained:
// `recipient` is an Address and `value` is a U256 amount in wei
let recipient: Address = /* ... */;
let value: U256 = /* ... */;
transfer_eth(self.vm(), recipient, value)?;
call(Call::new_in(self).value(value), recipient, &[])?;There was a problem hiding this comment.
Added type annotations as a comment in the snippet: (recipient: Address, value: U256) so readers understand the expected types without needing to trace the surrounding context. Commit: 4d87446
| // ✅ Extract common logic to internal functions | ||
| impl MyContract { | ||
| // Internal helper (no ABI encoding overhead) | ||
| fn internal_validate(&self, addr: Address, amount: U256) -> Result<(), Vec<u8>> { | ||
| ensure!(!addr.is_zero(), "Invalid address"); | ||
| ensure!(amount > U256::ZERO, "Invalid amount"); | ||
| if addr.is_zero() { | ||
| return Err(b"Invalid address".to_vec()); |
There was a problem hiding this comment.
This file still contains several ensure!(...) examples (e.g., cleanup/transfer/add_to_balance sections). Since this PR replaces ensure! with explicit if checks for the current SDK, please update the remaining ensure! usages in this doc for consistency and to avoid readers copying non-compiling code.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Replaced all four remaining ensure!() usages in gas-optimization.mdx with explicit if checks in commit 2f2b002. The affected sections were: cleanup (balance check), transfer (valid amount check), and add_to_balance_bad (zero and overflow checks).
There was a problem hiding this comment.
Replaced all four remaining ensure! usages in this file with explicit if checks + return Err(...) patterns (lines 124, 241, 252, 255). Commit: 4d87446
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
Systematic fact-check of Stylus documentation against the current
stylus-sdk-rssource code (v0.10.2, Rust 1.91.0). Fixes deprecated API patterns and outdated version references.Deprecated API replacements
evm::log()→self.vm().log()(removed in SDK v0.10)msg::sender()→self.vm().msg_sender()msg::value()→self.vm().msg_value()block::timestamp()→self.vm().block_timestamp()#[external]→#[public](attribute renamed)ensure!macro → explicitifchecks (macro doesn't exist in SDK)transfer_eth(to, amount)→transfer_eth(host, to, amount)(host arg added)RawDeploy::new(self.vm()).value(amount).deploy(&bytecode, salt)→RawDeploy::new().salt(salt).deploy(self.vm(), &bytecode, amount)Version updates (verified against stylus-sdk-rs Cargo.toml)
Stale link fixes
developer.arbitrum.io/time→ internal doc pathdeveloper.arbitrum.io/arbos/l1-to-l2-messaging→ internal doc pathMigration table fix (choose-your-path.mdx)
ensure!(condition, Error)→Result<T, E> + ?Derive Erase trait→self.vm().log(Event{})impl with initialization→#[constructor] methodFiles changed (20 Stylus docs)
stylus/advanced/rust-to-solidity-differences.mdxstylus/advanced/hostio-exports.mdxstylus/quickstart.mdxstylus/using-cli.mdxstylus/concepts/vm-differences.mdxstylus/cli-tools/overview.mdxstylus/cli-tools/debugging-tx.mdxstylus/fundamentals/testing-contracts.mdxstylus/fundamentals/prerequisites.mdxstylus/fundamentals/global-variables-and-functions.mdxstylus/fundamentals/project-structure.mdxstylus/fundamentals/contracts.mdxstylus/fundamentals/choose-your-path.mdxstylus/best-practices/gas-optimization.mdxstylus/how-tos/exporting-abi.mdxstylus/how-tos/trait-based-composition.mdxstylus/how-tos/using-constructors.mdxstylus/how-tos/importing-interfaces.mdxstylus/troubleshooting/common-issues.mdxTest plan
yarn buildpasses with no broken linksNot addressed (needs full rewrite in separate PRs)
stylus/cli-tools/commands-reference.mdx— CLI commands completely outdatedstylus/best-practices/security.mdx— 20+ deprecated API instancesstylus/concepts/public-preview-expectations.mdx— says Stylus is "release-candidate"stylus/reference/rust-sdk-guide.md— old reference with deprecated patterns🤖 Generated with Claude Code