MCPcopy Index your code
hub / github.com/OffchainLabs/stylus-sdk-rs

github.com/OffchainLabs/stylus-sdk-rs @v0.10.7

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.10.7 ↗ · + Follow
1,589 symbols 4,256 edges 299 files 439 documented · 28%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Logo

The Stylus SDK

<a href="https://docs.arbitrum.io/stylus/gentle-introduction"><strong>Rust contracts on Arbitrum »</strong></a>

Overview

The Stylus SDK enables smart contract developers to write programs for Arbitrum chains written in the Rust programming language. Stylus programs are compiled to WebAssembly and can then be deployed on-chain to execute alongside Solidity smart contracts. Stylus programs are not only orders of magnitude cheaper and faster but also enable what was thought to be previously impossible for WebAssembly: EVM-interoperability.

For information about deploying Rust smart contracts, see the Cargo Stylus CLI Tool. For more information about Stylus, see Stylus: A Gentle Introduction. For a simpler intro to Stylus Rust development, see the Quick Start guide.

Comprehensive documentation on the Rust SDK can be found here.

Feature highlights

The SDK makes it easy to develop Ethereum ABI-equivalent Stylus contracts in Rust. It provides a full suite of types and shortcuts that abstract away the details of Ethereum's storage layout, making it easy to just write Rust. For an in depth exploration of the features, please see comprehensive Feature Overview.

Some of the features available in the SDK include:

  • Generic, storage-backed Rust types for programming Solidity-equivalent smart contracts with optimal storage caching.
  • Simple macros for writing language-agnostic methods and entrypoints.
  • Automatic export of Solidity interfaces for interoperability across programming languages.
  • Powerful primitive types backed by the feature-rich Alloy.

Rust programs written with the Stylus SDK can call and be called by Solidity smart contracts due to ABI equivalence with Ethereum programming languages. In fact, existing Solidity DEXs can list Rust tokens without modification, and vice versa.

use stylus_sdk::{alloy_primitives::U256, prelude::*};

// Generate Solidity-equivalent, Rust structs backed by storage.
sol_storage! {
  #[entrypoint]
  pub struct Counter {
    uint256 number;
  }
}

#[public]
impl Counter {
  // Gets the number value from storage.
  pub fn number(&self) -> Result<U256, Vec<u8>> {
    Ok(self.number.get())
  }

  // Sets a number in storage to a user-specified value.
  pub fn set_number(&mut self, new_number: U256) -> Result<(), Vec<u8>> {
    self.number.set(new_number);
    Ok(())
  }
}

Additionally, the Stylus SDK supports #[no_std] for contracts that wish to opt out of the standard library. In fact, the entire SDK is available from #[no_std], so no special feature flag is required. This can be helpful for reducing binary size, and may be preferable in pure-compute use cases like cryptography.

Most users will want to use the standard library, which is available since the Stylus VM supports rustc's wasm32-unknown-unknown target triple. In the future we may add wasm32-wasi too, along with floating point and SIMD, which the Stylus VM does not yet support.

Don't know Rust?

The Stylus VM supports more than just Rust. In fact, any programming language that compiles down to WebAssembly could in principle be deployed to Stylus-enabled chains. The table below includes the official ports of the SDK, with more coming soon.

Repo Use cases License
Rust SDK Everything! Apache 2.0 or MIT
C/C++ SDK Cryptography and algorithms Apache 2.0 or MIT
AssemblyScript SDK* Educational Apache 2.0 or MIT
Bf SDK Educational Apache 2.0 or MIT
Cargo Stylus Deploying Stylus programs Apache 2.0 or MIT

Want to write your own? Join us in the #stylus channel on discord!

*This SDK is developed and maintained by an independent team.

Developing Stylus Programs

The Stylus SDK is just one of the building blocks in creating and deploying WebAssembly programs to Arbitrum chains. To create a new Stylus project from a hello-world example and deploy it onchain, check out some of our tools below:

Repo Use cases License
Stylus Hello World Rust Stylus starter template Apache 2.0 or MIT
Cargo Stylus CLI Deploying Stylus programs Apache 2.0 or MIT

License

© 2022-2024 Offchain Labs, Inc.

This project is licensed under either of

at your option.

The SPDX license identifier for this project is MIT OR Apache-2.0.

Extension points exported contracts — how you extend this code

StorageType (Interface)
Accessor trait that lets a type be used in persistent storage. Users can implement this trait to add novel data structur [13 …
stylus-sdk/src/storage/traits.rs
HostAccess (Interface)
Defines a trait that allows a Stylus contract to access its host safely. [12 implementers]
stylus-core/src/host.rs
Trait1 (Interface)
Missing #[public] attribute on trait methods [1 implementers]
stylus-proc/tests/fail/public/missing_macros.rs
ExternalContractAccess (Interface)
Trait for accessing external contract libraries during debugging [1 implementers]
cargo-stylus/src/utils/hostio.rs
InterfaceExtension (Interface)
(no doc) [2 implementers]
stylus-proc/src/macros/public/types.rs
Color (Interface)
(no doc) [1 implementers]
stylus-tools/src/utils/color.rs
Trait1 (Interface)
(no doc) [1 implementers]
cargo-stylus/tests/contract_abi/src/lib.rs
Trait1 (Interface)
(no doc) [1 implementers]
examples/callee/src/lib.rs

Core symbols most depended-on inside this repo

new
called by 355
stylus-tools/src/ops/new.rs
clone
called by 194
stylus-sdk/src/host/mod.rs
vm
called by 109
stylus-sdk/src/storage/vec.rs
get
called by 97
examples/first_app/src/lib.rs
set
called by 94
stylus-sdk/src/storage/mod.rs
call
called by 88
stylus-sdk/src/call/raw.rs
push
called by 67
stylus-sdk/src/storage/vec.rs
get
called by 59
stylus-sdk/src/storage/vec.rs

Shape

Method 803
Function 468
Class 200
Interface 66
Enum 52

Languages

Rust100%
TypeScript1%
Python1%

Modules by API surface

stylus-test/src/vm.rs65 symbols
cargo-stylus/src/utils/hostio.rs56 symbols
stylus-sdk/src/storage/bytes.rs52 symbols
stylus-sdk/src/host/mod.rs51 symbols
stylus-proc/src/macros/public/types.rs34 symbols
stylus-sdk/src/storage/vec.rs27 symbols
examples/test/src/lib.rs26 symbols
stylus-tools/src/utils/color.rs25 symbols
stylus-proc/tests/public.rs20 symbols
stylus-core/src/host.rs20 symbols
examples/erc721/src/erc721.rs20 symbols
cargo-stylus/src/commands/replay.rs20 symbols

For agents

$ claude mcp add stylus-sdk-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page