The SolScript command-line interface for compiling and managing projects.
cargo install solscriptCompile a SolScript file to Anchor/Rust.
solscript build <FILE> [OPTIONS]Arguments:
<FILE>- Path to the.solsource file
Options:
-o, --output <DIR>- Output directory (default:./output)--no-color- Disable colored output
Example:
solscript build counter.sol -o ./buildOutput Structure:
./build/
├── Anchor.toml
├── Cargo.toml
├── programs/
│ └── counter/
│ ├── Cargo.toml
│ └── src/
│ └── lib.rs
└── tests/
└── counter.ts
Type-check a SolScript file without generating output.
solscript check <FILE>Arguments:
<FILE>- Path to the.solsource file
Example:
solscript check token.solOutput:
- Success: No output, exit code 0
- Errors: Displays type errors with source locations
Parse a file and display the AST.
solscript parse <FILE> [OPTIONS]Arguments:
<FILE>- Path to the.solsource file
Options:
--json- Output AST as JSON (default: debug format)
Example:
solscript parse counter.sol --json > ast.jsonCompile to Solana BPF bytecode.
solscript build-bpf <FILE> [OPTIONS]Arguments:
<FILE>- Path to the.solsource file
Options:
-o, --output <DIR>- Output directory (default:./target)--opt-level <LEVEL>- Optimization level: 0, 1, 2, 3 (default: 2)--keep-intermediate- Keep intermediate Anchor files--llvm- Use direct LLVM compilation (requires LLVM 18)
Compilation Modes:
-
Anchor Mode (Default): Generates Rust/Anchor code, then compiles with
cargo build-sbfsolscript build-bpf token.sol -o ./deploy
-
Direct LLVM Mode: Compiles directly to BPF via LLVM (faster, requires LLVM 18)
solscript build-bpf --llvm token.sol -o ./deploy
Examples:
# Standard compilation via Anchor
solscript build-bpf token.sol -o ./deploy --opt-level 3
# Direct LLVM compilation (faster)
solscript build-bpf --llvm counter.sol -o ./deploy
# Keep intermediate files for debugging
solscript build-bpf token.sol --keep-intermediateRequirements:
- Anchor Mode: Solana CLI tools,
cargo-build-sbf - LLVM Mode: LLVM 18 with BPF target,
LLVM_SYS_180_PREFIXset
Deploy a compiled program to Solana.
solscript deploy <FILE> [OPTIONS]Arguments:
<FILE>- Path to the.solsource file
Options:
-o, --output <DIR>- Build output directory (default:./target)--network <NETWORK>- Target network: devnet, testnet, mainnet (default: devnet)--keypair <PATH>- Path to keypair file--skip-build- Skip the build step
Example:
solscript deploy token.sol --network devnet --keypair ~/.config/solana/id.jsonRun tests for a SolScript project.
solscript test <FILE> [OPTIONS]Arguments:
<FILE>- Path to the.solsource file
Options:
-o, --output <DIR>- Build output directory (default:./target)--skip-build- Skip the build step
Example:
solscript test counter.solCreate a new SolScript project from a template.
solscript new <NAME> [OPTIONS]Arguments:
<NAME>- Project name (optional if using--list)
Options:
-t, --template <TEMPLATE>- Template to use (default: counter)--list- List available templates
Available Templates:
| Template | Difficulty | Description |
|---|---|---|
simple |
Beginner | Minimal contract for learning |
counter |
Beginner | Counter with ownership (default) |
token |
Intermediate | ERC20-style fungible token |
voting |
Intermediate | Decentralized voting system |
escrow |
Advanced | Trustless escrow with disputes |
nft |
Advanced | ERC721-style NFT collection |
Examples:
# List all templates
solscript new --list
# Create with default template (counter)
solscript new my-project
# Create with specific template
solscript new my-token --template token
solscript new my-nft -t nftGenerated Structure:
my-project/
├── src/
│ └── main.sol # Contract code
├── solscript.toml # Project configuration
├── .gitignore
└── README.md
!!! warning "Deprecated"
solscript init is deprecated. Use solscript new instead.
Initialize a new SolScript project (legacy command).
solscript init <NAME>This command is an alias for solscript new <NAME> --template counter.
Add a dependency to the project.
solscript add <PACKAGE> [OPTIONS]Arguments:
<PACKAGE>- Package name or GitHub URL
Options:
--version <VERSION>- Package version--git <URL>- Git repository URL--branch <BRANCH>- Git branch name
Examples:
# Add from registry
solscript add @solana/spl-token
# Add from GitHub
solscript add --git https://github.com/user/lib --branch mainCheck the development environment.
solscript doctorOutput:
SolScript Environment Check
============================
Solana CLI: ✓ installed (1.18.0)
Anchor CLI: ✓ installed (0.30.0)
cargo-build-sbf: ✓ installed
Node.js: ✓ installed (20.0.0)
All tools available!
Start the Language Server Protocol server.
solscript lsp [OPTIONS]Options:
--stdio- Use stdio for communication (default)--tcp <PORT>- Use TCP on specified port
Example:
solscript lsp --stdioUsed by IDE extensions for code intelligence.
Project configuration file:
[package]
name = "my-project"
version = "0.1.0"
description = "My SolScript project"
[solana]
cluster = "devnet"
program_id = "11111111111111111111111111111111"
[build]
output_dir = "./target"
optimization = 2
[dependencies]
spl-token = { git = "https://github.com/solana-labs/solana-program-library", branch = "master" }| Variable | Description | Default |
|---|---|---|
SOLSCRIPT_OUTPUT |
Default output directory | ./output |
SOLANA_KEYPAIR |
Path to keypair file | ~/.config/solana/id.json |
SOLANA_CLUSTER |
Target cluster | devnet |
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Compilation error |
| 2 | Type checking error |
| 3 | Runtime/deployment error |
| 4 | Configuration error |