@wakeuplabs/as-stylus
v0.2.9
Published
SDK to build AssemblyScript contracts for Stylus
Keywords
Readme
AssemblyScript Stylus SDK
⚠️ ALPHA VERSION NOTICE
This SDK is currently in alpha development and is actively being worked on. It is not production-ready and may contain bugs, breaking changes, or incomplete features. Use at your own risk and avoid deploying to mainnet without thorough testing.
Smart contracts on Arbitrum using AssemblyScript
Overview
The AssemblyScript Stylus SDK enables smart contract developers to write programs for Arbitrum Stylus using AssemblyScript with TypeScript-like syntax. Stylus programs are compiled to WebAssembly and can be deployed on-chain to execute alongside Solidity smart contracts. AssemblyScript contracts are not only faster and cheaper but also provide a familiar development experience for JavaScript/TypeScript developers.
For more information about Stylus, see Stylus: A Gentle Introduction. For deployment, see the Cargo Stylus CLI Tool.
Features
- TypeScript-like Syntax: Write contracts using familiar decorators and TypeScript syntax
- Type Safety: Strong typing with compile-time validation
- High Performance: Compiled to WASM for optimal execution on Stylus
- Rich Type System: Support for
U256,I256,Address,String,Boolean,Mapping, andStructtypes - Event System: Emit events with proper ABI encoding
- Error Handling: Custom error types with revert functionality
- ABI Generation: Automatic generation of Ethereum-compatible ABIs
- Interoperability: Full compatibility with Solidity contracts
Quick Start
Generate a new project
npx @wakeuplabs/as-stylus generate my-counter
cd my-counterThis creates a basic project structure:
my-counter/
├── contract.ts # Your contract code
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
└── asconfig.json # AssemblyScript configurationWrite Your Contract
Edit contract.ts:
import { Contract, External, U256, U256Factory, View } from "@wakeuplabs/as-stylus";
@Contract
export class Counter {
counter: U256;
constructor() {
this.counter = U256Factory.create();
}
@External
set(value: U256): void {
this.counter = value;
}
@External
increment(): void {
const delta: U256 = U256Factory.fromString("1");
this.counter = this.counter.addUnchecked(delta);
}
@External
decrement(): void {
const delta: U256 = U256Factory.fromString("1");
this.counter = this.counter.subUnchecked(delta);
}
@View
get(): U256 {
return this.counter;
}
}Build and deploy
npx @wakeuplabs/as-stylus compile <contract-file> --endpoint <rpc-url> # build artifacts, Compile to WASM and check Validate with cargo stylus
npm run deploy <contract-file> --endpoint <rpc-url> --private-key <private-key> --output <output-file> --constructor-args <constructor-args...> # Deploy to ArbitrumCLI Commands
The as-stylus CLI provides several commands for contract development:
| Command | Description | Usage |
| ------------ | -------------------------------------------- | ----------------------------------------------- |
| generate | Create a new Stylus project with boilerplate | @wakeuplabs/as-stylus generate <project-name> |
| compile | Compile AssemblyScript to WASM | @wakeuplabs/as-stylus compile <contract-path> |
| deploy | Deploy contract to Stylus network | @wakeuplabs/as-stylus deploy <contract-path> |
| clean | Remove build artifacts and temporary files | @wakeuplabs/as-stylus clean |
Requirements
- Node.js ≥ 18.x
- AssemblyScript ≥ 0.27.x
- cargo stylus CLI tool (for compilation and deployment)
Install cargo stylus:
cargo install --force cargo-stylus
rustup target add wasm32-unknown-unknown🏗️ Project Structure
your-project/
├── contract.ts # Main contract code
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── asconfig.json # AssemblyScript configuration
└── artifacts # Generated files (after build)
├── index.ts # Transformed AssemblyScript
├── package.json # Generated package config
├── abi/ # Abi generated (after build)
└── build/ # Compiled WASM (after compile)
└── module.wasm # Final bytecodeRelated Resources
- Stylus Documentation
- GitHub Repository
- AssemblyScript Documentation
- Cargo Stylus CLI
- Arbitrum Developer Portal
License
This project is licensed under either of:
- Apache License, Version 2.0
- MIT License
at your option.
Ready to build the future of smart contracts with AssemblyScript?
Start with npx @wakeuplabs/as-stylus generate my-first-contract and join the Stylus revolution!
