Crate chia_wallet_sdk
source ·Expand description
This is an unofficial wallet SDK for the Chia blockchain, enabling the development of high-performance wallet applications built with Chia’s light wallet protocol.
§Why do you need an SDK?
If you intend on writing an application that uses the Chia blockchain, be it a dApp, a wallet, or even just tooling on top of it, you will most likely need some code to interact with a Chia wallet. The worst case scenario is that you need to write an entire wallet and all of its driver code from scratch every time. This is very challenging to do, takes a lot of time, and can be error prone if anything is done wrong.
To build driver code, you need libraries like chia-bls
and clvmr
, for interacting with Chia’s native BLS signatures and CLVM runtime. You compose puzzles by currying them, and spend them by constructing solutions. Even with libraries in place to do this (assuming they are tested properly), it can be very tedious and hard to get right. That’s what this Wallet SDK is aiming to solve.
It’s essentially a higher level wrapper over the core primitives that the Chia blockchain provides, and aims to make various things in the lifecycle of wallet development simpler such as state management and signing.
§chia_rs and clvm_rs
This SDK is built on top of the primitives developed in the chia_rs and clvm_rs libraries. I help maintain chia_rs to add new core functionality necessary for wallet development as needed. And clvm_rs is a great implementation of the CLVM runtime, especially when combined with the clvm-traits helper library for translating Rust types to CLVM and vice versa.
§Supported primitives
Currently, only a subset of Chia’s primitives are supported:
§Standard puzzle
You can spend the standard puzzle, also known as the “standard transaction”, “p2 puzzle”, or “p2_delegated_puzzle_or_hidden_puzzle”. The hidden puzzle functionality is not currently supported.
§CATs
CATs with any asset id can be spent, but only as long as the inner puzzle is the standard puzzle. You can also issue CATs with the “everything with signature” TAIL (multi-issuance).
§DIDs
You cannot create new DIDs or recover them, and the API for spending them is not as flexible as it will be in the future. But there is a very thin wrapper for spending DIDs, as long as the inner puzzle is the standard puzzle.
§NFTs
You can spend NFTs and mint them in bulk by spending a DID as the parent. You can also change the DID owner of an NFT. As previously mentioned, all primitives assume the standard puzzle is the inner puzzle, which is typically the case at this time.
Re-exports§
pub use wallet::*;
Modules§
- The
prelude
module contains the most commonly used types and traits. - Contains logic needed to glue a wallet together with all of the data stores.
Structs§
- The information required to create and spend an NFT bulk mint.
- The information required to spend a CAT coin. This assumes that the inner puzzle is a standard transaction.
- The information required to create and spend an eve CAT coin.
- The information required to mint an NFT.
- The output of a single NFT mint.
- A run TAIL condition.
- A wrapper around
Allocator
that caches puzzles and simplifies coin spending. - A coin and its corresponding public key.
Enums§
- Errors you can get while trying to decode an address.
- Errors you can get while trying to decode a puzzle hash.
- Errors that can occur when spending a coin.
- An error that occurs while trying to load an SSL certificate.
Functions§
- Attempts to connect to a peer and return a handle to the WebSocket wrapper.
- Creates an eve CAT coin and spends it.
- Creates a TLS connector from a certificate.
- Decodes an address into a puzzle hash and HRP prefix.
- Decodes a puzzle hash from hex, with or without a prefix.
- Dump a
SpendBundle
to a JSON string. - Encodes an address with a given HRP prefix.
- Encodes a puzzle hash into hex, with or without a prefix.
- Constructs a coin spend to issue more of an
EverythingWithSignature
CAT. - Loads an SSL certificate, or creates it if it doesn’t exist already.
- Bulk mints a set of NFTs.
- Creates a set of CAT coin spends for a given asset id.
- Spend a standard DID coin (a DID singleton with the standard transaction inner puzzle).
- Spend an NFT.
- Creates a new coin spend for a given standard transaction coin.
- Spends a set of standard transaction coins.
- Constructs a solution for the standard puzzle, given a list of condition. This assumes no hidden puzzle is being used in this spend.
- Removes the
0x
prefix from a puzzle hash in hex format.