Chopsticks is a powerful tool that allows you to create a parallel reality of your Substrate network. It's useful for testing, development, and experimentation with blockchain networks.
Before we start, ensure you have the following:
-
π¦ Rust: Install Rust and set up your environment.
- π§ Install Rust: Rust Installation Guide
- π― Add the wasm32-unknown-unknown target:
rustup target add wasm32-unknown-unknown
-
π» Visual Studio Code (VS Code): Set up VS Code for Rust and Substrate development.
- π₯ Download and install VS Code from the official website.
- 𧩠Install the following extensions in VS Code:
- π¦ Rust Extension:
- π Go to the Extensions view (
Ctrl+Shift+X
). - π Search for "Rust" and install the Rust extension by rust-lang.
- π Go to the Extensions view (
- 𧬠Substrate Extension:
- π In the Extensions view, search for "Substrate" and install the Substrate extension.
- π¬ Rust Analyzer Extension (Recommended):
- π This extension provides enhanced Rust language support, including code completion and inline error checking.
- π Search for "Rust Analyzer" in the Extensions view and install the Rust Analyzer extension.
- π¦ Rust Extension:
-
π¦ Install Rust:
- π Option 1: Native Windows Installation
- π₯ Download and install Rust using the installer provided at the official Rust website.
- π₯οΈ Open Command Prompt (cmd) or PowerShell and run:
rustup target add wasm32-unknown-unknown
- π§ Option 2: Using WSL2 (Recommended)
- π§ Install WSL2 if you haven't already by following the WSL installation guide.
- π¦ Install a Linux distribution from the Microsoft Store (e.g., Ubuntu).
- π₯οΈ Open your WSL2 terminal (e.g., Ubuntu) and install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- π― After installation, add the wasm32 target:
rustup target add wasm32-unknown-unknown
- π Option 1: Native Windows Installation
-
π₯’ Install Chopsticks:
- π Option 1: Native Windows Installation
- π₯οΈ Open Command Prompt or PowerShell and run:
cargo install chopsticks --git https://github.com/AcalaNetwork/chopsticks.git
- π₯οΈ Open Command Prompt or PowerShell and run:
- π§ Option 2: Using WSL2
- π₯οΈ In your WSL2 terminal, run:
cargo install chopsticks --git https://github.com/AcalaNetwork/chopsticks.git
- π₯οΈ In your WSL2 terminal, run:
- π Option 1: Native Windows Installation
-
π¦ Install Node.js and NPM (optional, but useful for some Substrate development tasks):
- π Option 1: Native Windows Installation
- π₯ Download the Windows installer from the Node.js website and run it.
- β
Confirm installation by running in Command Prompt:
node -v npm -v
- π§ Option 2: Using WSL2
- π₯οΈ In your WSL2 terminal, install Node.js using the package manager:
sudo apt update sudo apt install nodejs npm
- β
Confirm installation by running:
node -v npm -v
- π₯οΈ In your WSL2 terminal, install Node.js using the package manager:
- π Option 1: Native Windows Installation
-
π¦ Install Rust:
- π₯οΈ Open Terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- π Follow the on-screen instructions to complete the installation.
- π― Add the wasm32 target:
rustup target add wasm32-unknown-unknown
- π₯οΈ Open Terminal and run:
-
π₯’ Install Chopsticks:
- π₯οΈ In Terminal, run:
cargo install chopsticks --git https://github.com/AcalaNetwork/chopsticks.git
- π₯οΈ In Terminal, run:
-
π¦ Install Node.js and npm:
- π₯ Download and install Node.js from the official website.
- β
Confirm installation by running:
node -v npm -v
-
π§° Install Development Tools:
- π» Install Xcode from the App Store if you haven't already.
- π οΈ Install Xcode Command Line Tools:
xcode-select --install
-
π¦ Install Rust:
- π₯οΈ Open a terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- π Follow the on-screen instructions to complete the installation.
- π― Add the wasm32 target:
rustup target add wasm32-unknown-unknown
- π₯οΈ Open a terminal and run:
-
π₯’ Install Chopsticks:
- π₯οΈ In the terminal, run:
cargo install chopsticks --git https://github.com/AcalaNetwork/chopsticks.git
- π₯οΈ In the terminal, run:
-
π¦ Install Node.js and npm:
- π₯οΈ Use your distribution's package manager. For Ubuntu/Debian:
sudo apt update sudo apt install nodejs npm
- β
Confirm installation by running:
node -v npm -v
- π₯οΈ Use your distribution's package manager. For Ubuntu/Debian:
-
π§° Install Development Tools:
- π οΈ Install essential build tools:
sudo apt update sudo apt install build-essential
- π οΈ Install essential build tools:
After completing the OS-specific setup, follow these additional steps:
-
π₯ Clone the Chopsticks Repository:
git clone --recurse-submodules https://github.com/AcalaNetwork/chopsticks.git cd chopsticks
-
π¦ Install Dependencies:
yarn
-
ποΈ Build WebAssembly:
yarn build-wasm
To quickly fork an existing network (e.g., Acala mainnet), run:
npx @acala-network/chopsticks@latest --endpoint=wss://acala-rpc-2.aca-api.network/ws
For more complex setups, it's recommended to use a configuration file. Create a file named chopsticks.yml
in your project root:
endpoint: "ws://127.0.0.1:9944"
mock-signature-host: true
db: ./db.sqlite
import-storage:
System:
Account:
- - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
- data:
free: "1000000000000000000000"
Balances:
TotalIssuance: "1000000000000000000000"
runtime:
wasm_file: ./runtime/target/release/wbuild/node-runtime/node_runtime.wasm
To run Chopsticks with a config file:
npx @acala-network/chopsticks@latest -c acala
To replay the latest block:
npx @acala-network/chopsticks@latest run-block --endpoint=wss://acala-rpc-2.aca-api.network/ws
Options:
-b|--block
: Replay a specific block hash--output-path=<file_path>
: Print out JSON file--html
: Generate storage diff preview--open
: Automatically open the HTML file
Dry run an extrinsic:
npx @acala-network/chopsticks@latest dry-run --config=configs/mandala.yml --html --open --extrinsic=0x...
Dry run a call (with mocked signature):
npx @acala-network/chopsticks@latest dry-run --config=configs/mandala.yml --html --open --extrinsic=0x... --address=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
To set up an XCM multichain environment:
npx @acala-network/chopsticks@latest xcm -r kusama -p karura -p statemine
Chopsticks supports plugins and custom RPC methods. To load custom RPC methods:
npx @acala-network/chopsticks@latest --unsafe-rpc-methods=rpc-methods-scripts.js
For testing big migrations, you can prefetch and cache storages. Add a prefetch-storages
section to your config file:
prefetch-storages:
- '0x123456'
- Balances
- Tokens.Accounts
- System: Account
- Tokens:
Accounts: [5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY]
Alternatively, use the fetch-storages
subcommand:
npx @acala-network/chopsticks@latest fetch-storages 0x123456 Balances Tokens.Accounts --endpoint=wss://acala-rpc-0.aca-api.network --block=<blockhash> --db=acala.sqlite
Chopsticks also includes a Try-Runtime CLI for advanced testing and migration scenarios. Refer to the Try-Runtime documentation for more information.
Chopsticks can run in a browser environment, allowing you to turn a mainnet into a devnet directly in your browser. Check out the example at acalanetwork.github.io/chopsticks.
By following this enhanced tutorial, you'll be able to leverage the full power of Chopsticks for simulating, testing, and experimenting with Substrate-based blockchain networks.