• Stars
    star
    222
  • Rank 179,123 (Top 4 %)
  • Language
    Rust
  • Created over 1 year ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust Smart Contracts on Arbitrum

Logo

The Stylus SDK

Rust contracts on Arbitrum Β»

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;
  }
}

#[external]
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
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!

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-2023 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.

More Repositories

1

arbitrum-classic

Powers fast, private, decentralized applications
Go
1,975
star
2

nitro

Nitro goes vroom and fixes everything
Go
738
star
3

arbitrum-tutorials

Get started developing on Arbitrum
JavaScript
451
star
4

arbitrum-sdk

TypeScript
226
star
5

arbitrum-docs

Arbitrum Docs! Content + Webapp
MDX
180
star
6

arbitrum-token-bridge

πŸ’™ Interface for bridging assets to and from Arbitrum chains
TypeScript
153
star
7

token-bridge-contracts

Arbitrum token bridge and peripheral contracts
Solidity
149
star
8

bold

Efficient, all-vs-all dispute protocol for Optimistic Rollups
Go
111
star
9

eth-pos-devnet

Shell
111
star
10

stylus

Stylus VM and Fraud Prover
Go
107
star
11

nitro-contracts

The core Arbitrum Nitro contracts deployed to the parent chain to host the rollup
Solidity
97
star
12

arb-os

ArbOS operating system, to run at Layer 2 on Arbitrum chains. Also a compiler for Mini, the language in which ArbOS is written.
Rust
93
star
13

go-ethereum

Go
55
star
14

cargo-stylus

Cargo subcommand for developing Arbitrum Stylus projects in Rust
Rust
55
star
15

awesome-stylus

A curated list of Arbitrum Stylus code examples, libraries and resources
54
star
16

blockscout

Elixir
45
star
17

orbit-setup-script

TypeScript
42
star
18

stylus-hello-world

Project starter template for writing Arbitrum Stylus programs in Rust
Rust
39
star
19

arbitrum

35
star
20

arbitrum-orbit-sdk

πŸ’™ SDK for building Arbitrum Orbit chains
TypeScript
29
star
21

sszpp

C++ SSZ library
C++
25
star
22

arbitrum-token-lists

TypeScript
22
star
23

demo-dapp-pet-shop

Pet shop dapp, for use as an Arbitrum demo
JavaScript
20
star
24

arbitrum-orbit-deployment-ui

Introducing the L3 Orbit Chain Deployment Interface, a user-friendly tool to effortlessly deploy your own Layer 3 Orbit Chain. This repository streamlines the setup process, allowing developers to focus on their decentralized applications.
TypeScript
20
star
25

methodical-ssz

Code generation tool for adding Ethereum SimpleSerialiZe support methods to existing go types
Go
19
star
26

zig-on-stylus

EVM-interoperable smart contracts written in Zig!
Zig
18
star
27

nitro-testnode

A complete environment for nitro-based service including sequencer, batch-poster, validator, and a coordinator.
TypeScript
18
star
28

stylus-sdk-c

C/C++ Smart Contracts on Arbitrum
C
17
star
29

arbitrum-subgraphs

TypeScript
16
star
30

bold-validator-starter-kit

Starter kit repo for running Arbitrum BOLD validators
Shell
16
star
31

nft-bridge-workshop-demo

TypeScript
12
star
32

fund-distribution-contracts

Contracts for distributing rewards data availability committee members
Solidity
11
star
33

stylus-by-example

Simple examples of Arbitrum Stylus Rust & WASM smart contracts
MDX
11
star
34

arbitrum-monitoring

A collection of scripts designed for monitoring various aspects of Arbitrum chains.
TypeScript
10
star
35

Blobwatcher

Blob Monitoring Tool
Go
10
star
36

stylus-geth

Go
10
star
37

timeboost-design

Go
9
star
38

token-bridge-sdk

TypeScript
9
star
39

demo-dapp-election

JavaScript
9
star
40

stylus-sdk-bf

Bf Smart Contracts on Arbitrum πŸ˜…
WebAssembly
8
star
41

upgrade-executor

Support system for performing contract upgrades
Solidity
6
star
42

Arbiswap_V2_mono

TypeScript
6
star
43

arbitrum-cli-tools

TypeScript
6
star
44

community-helm-charts

Community Helm Charts provided by Offchain Labs
Smarty
6
star
45

retryable-tx-panel

TypeScript
5
star
46

actions

Collection of reusable GitHub actions and workflows
Shell
5
star
47

stylus-workshop-rust-solidity

Stylus workshop for interaction between Rust and Solidity
Solidity
5
star
48

stylus-contracts

Solidity
5
star
49

stylus-workshop-nft

Rust
5
star
50

config-monorepo

JavaScript
4
star
51

arbitrum-interop-quickstart

JavaScript
4
star
52

RescuETH

TypeScript
4
star
53

decentralized-timeboost-spec

4
star
54

keccak-const

Rust
4
star
55

arbitrum-deployment-website

Ethers interface form Arbitrum chain deployment
TypeScript
3
star
56

l1-l3-teleport-contracts

Solidity
3
star
57

crosschain-oracle-workshop-demo

Solidity
3
star
58

arb-compiler-evm-archive

Python
3
star
59

gnosis-safe-contracts

TypeScript
3
star
60

arb_reddit_community_points

TypeScript
3
star
61

deposits_tracker

TypeScript
2
star
62

stylus-erc20

Solidity
2
star
63

fastcache

Go
2
star
64

retryables_tracker

TypeScript
2
star
65

SoftFloat

SoftFloat-3e with WASM build support
C
2
star
66

wasmer

Rust
2
star
67

token-bridge-sdk-old

TypeScript
2
star
68

stylus-hello-world-minimal

Shell
1
star
69

orbit-actions

Solidity
1
star
70

encode-workshop-crosschain-messaging

JavaScript
1
star
71

token-mock

JavaScript
1
star
72

arb-provider-ethers-deprecated-

TypeScript
1
star
73

paired-erc20

Solidity
1
star
74

fakerdao

JavaScript
1
star
75

Arb-Burner-Wallet

TypeScript
1
star
76

arbtoken_twitter_faucet

TypeScript
1
star
77

ethers-bls-signer

TypeScript
1
star
78

arb-peripheral-template

An easy to use template to integrate with Arbitrum peripheral contracts
JavaScript
1
star
79

stylus-workshop-counter

Rust
1
star
80

stylus-chess

Rust
1
star
81

navigator

HTML
1
star
82

cuckoocache

Go
1
star
83

arb-ethers-web3-bridge

Arbitrum bridge for converting ethers provider into web3
JavaScript
1
star
84

arbitrum-funds-recovery-tool

Tool to recover funds that are stuck on an L2 aliased address
TypeScript
1
star