Wallet SDK
The Chia Wallet SDK is a Rust library for building applications that interact with the Chia blockchain. It provides high-level abstractions for creating transactions, managing coins, and working with Chia primitives like CATs, NFTs, and Vaults.
This documentation assumes familiarity with Chia blockchain concepts such as coins, puzzles, conditions, and singletons. For background, see the Chia Documentation and Chialisp Documentation.
Installation
- Rust
- Node.js
- Python
Add the SDK to your Cargo.toml:
[dependencies]
chia-wallet-sdk = "0.32"
For the latest version and detailed API reference, see docs.rs/chia-wallet-sdk.
Install via npm:
npm install chia-wallet-sdk
The Node.js bindings provide a similar API with JavaScript/TypeScript support. Full TypeScript type definitions are included.
Install via pip:
pip install chia-wallet-sdk
The Python bindings provide a Pythonic API with full type stub support for IDE autocompletion.
Quick Example
Here's a minimal example that creates and spends a standard XCH coin:
- Rust
- Node.js
- Python
use chia_wallet_sdk::prelude::*;
// Create a spend context to build the transaction
let ctx = &mut SpendContext::new();
// Define the conditions for this spend:
// - Create a new coin with 900 mojos
// - Reserve 100 mojos as transaction fee
let conditions = Conditions::new()
.create_coin(puzzle_hash, 900, Memos::None)
.reserve_fee(100);
// Create the spend using StandardLayer (p2 puzzle)
StandardLayer::new(public_key).spend(ctx, coin, conditions)?;
// Extract the coin spends for signing and broadcast
let coin_spends = ctx.take();
import { Clvm, Coin, Simulator } from "chia-wallet-sdk";
// Create a CLVM instance to build the transaction
const clvm = new Clvm();
// Create conditions:
// - Create a new coin with 900 mojos
// - Reserve 100 mojos as transaction fee
const conditions = [
clvm.createCoin(puzzleHash, 900n, null),
clvm.reserveFee(100n),
];
// Create and spend using delegated spend (p2 puzzle)
clvm.spendStandardCoin(
coin,
publicKey,
clvm.delegatedSpend(conditions)
);
// Extract the coin spends for signing and broadcast
const coinSpends = clvm.coinSpends();
from chia_wallet_sdk import Clvm, Coin, Simulator
# Create a CLVM instance to build the transaction
clvm = Clvm()
# Create conditions:
# - Create a new coin with 900 mojos
# - Reserve 100 mojos as transaction fee
conditions = [
clvm.create_coin(puzzle_hash, 900, None),
clvm.reserve_fee(100),
]
# Create and spend using delegated spend (p2 puzzle)
clvm.spend_standard_coin(
coin,
public_key,
clvm.delegated_spend(conditions)
)
# Extract the coin spends for signing and broadcast
coin_spends = clvm.coin_spends()
This example demonstrates the core pattern you'll use throughout the SDK:
- Create a context - In Rust, use
SpendContext; in Node.js/Python, use theClvmclass - Build conditions - Define what the transaction should do (create coins, fees, announcements)
- Spend coins - Use primitives like
StandardLayer(Rust) orspendStandardCoin(bindings) - Extract and broadcast - Take the collected spends, sign them, and submit to the network
Core Concepts
The SDK is organized around these key abstractions:
| Concept | Rust | Node.js / Python | Description |
|---|---|---|---|
| Context | SpendContext | Clvm | Transaction builder that manages memory and collects coin spends |
| Conditions | Conditions builder | Method calls (createCoin, etc.) | Output conditions (create coin, fees, announcements) |
| Actions | Action, Spends | Action, Spends | High-level declarative transaction API |
| Primitives | Cat, Nft, Vault, etc. | spendCats, spendNft, etc. | High-level APIs for Chia constructs |
| Simulator | Simulator | Simulator | Test transaction validation locally |
Next Steps
- SpendContext - Understanding the core transaction builder
- Action System - High-level declarative transaction API
- Standard (XCH) - Working with basic XCH coins
- CAT - Issuing and spending custom asset tokens
- NFT - Minting and transferring NFTs
Relationship to chia-rs
The Wallet SDK builds on top of the lower-level chia-rs crates, providing ergonomic APIs for common operations. If you need lower-level control, the underlying types from chia-protocol, clvm-traits, and clvmr are re-exported through the SDK.