Skip to main content

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.

info

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

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.

Quick Example

Here's a minimal example that creates and spends a standard XCH coin:

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();

This example demonstrates the core pattern you'll use throughout the SDK:

  1. Create a context - In Rust, use SpendContext; in Node.js/Python, use the Clvm class
  2. Build conditions - Define what the transaction should do (create coins, fees, announcements)
  3. Spend coins - Use primitives like StandardLayer (Rust) or spendStandardCoin (bindings)
  4. Extract and broadcast - Take the collected spends, sign them, and submit to the network

Core Concepts

The SDK is organized around these key abstractions:

ConceptRustNode.js / PythonDescription
ContextSpendContextClvmTransaction builder that manages memory and collects coin spends
ConditionsConditions builderMethod calls (createCoin, etc.)Output conditions (create coin, fees, announcements)
ActionsAction, SpendsAction, SpendsHigh-level declarative transaction API
PrimitivesCat, Nft, Vault, etc.spendCats, spendNft, etc.High-level APIs for Chia constructs
SimulatorSimulatorSimulatorTest 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.