chia-wallet-sdk-bundle
v0.30.0
Published
WASM bindings for the Chia Wallet SDK - Universal bundle compatible with both Node.js and web environments.
Maintainers
Readme
Chia Wallet SDK - WASM (Universal Bundle)
WebAssembly (WASM) bindings for the Chia Wallet SDK, designed for universal compatibility with both Node.js and web environments.
Installation
npm install chia-wallet-sdk-bundleUsage
Usage in Node.js
No special setup is required. You can import and use the module like any regular JavaScript library:
import { Clvm, Simulator, PublicKey, fromHex, toHex } from 'chia-wallet-sdk-bundle';
// Create a new CLVM instance
const clvm = new Clvm();
// Create a simulator for testing
const simulator = new Simulator();
// Generate a test wallet
const alice = simulator.bls(1n);
console.log('Public Key:', toHex(alice.pk.toBytes()));
console.log('Puzzle Hash:', toHex(alice.puzzleHash));Usage in the Browser (with Vite)
By default, Vite does not support WebAssembly ESM integration out of the box.
To use this package directly in a Vite frontend project, simply add the official vite-plugin-wasm plugin:
1. Install the plugin
npm install -D vite-plugin-wasm2. Enable it in your vite.config.ts
import { defineConfig } from 'vite';
import wasm from 'vite-plugin-wasm';
export default defineConfig({
plugins: [wasm()],
});3. Import and use the SDK directly
import { Clvm, Simulator, PublicKey, fromHex, toHex } from 'chia-wallet-sdk-bundle';
// Create a new CLVM instance
const clvm = new Clvm();
// Create a simulator for testing
const simulator = new Simulator();
// Generate a test wallet
const alice = simulator.bls(1n);
console.log('Public Key:', toHex(alice.pk.toBytes()));
console.log('Puzzle Hash:', toHex(alice.puzzleHash));Address Operations
import { Address } from 'chia-wallet-sdk-bundle';
// Create an address from puzzle hash
const puzzleHash = fromHex("aca490e9f3ebcafa3d5342d347db2703b31029511f5b40c11441af1c961f6585");
const address = new Address(puzzleHash, "xch");
const encodedAddress = address.encode();
console.log('XCH Address:', encodedAddress);
// Decode an address
const decodedAddress = Address.decode(encodedAddress);
console.log('Decoded puzzle hash:', toHex(decodedAddress.puzzleHash));Coin Operations
import { Coin } from 'chia-wallet-sdk-bundle';
// Create a coin
const parentCoinId = fromHex("4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a");
const puzzleHash = fromHex("dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986");
const amount = 100n;
const coin = new Coin(parentCoinId, puzzleHash, amount);
const coinId = coin.coinId();
console.log('Coin ID:', toHex(coinId));CLVM Operations
// Allocate different types of values
const nil = clvm.nil();
const number = clvm.alloc(42);
const bigNumber = clvm.alloc(100n);
const string = clvm.alloc("Hello, Chia!");
const bytes = clvm.alloc(fromHex("deadbeef"));
const boolean = clvm.alloc(true);
// Create pairs and lists
const pair = clvm.pair(number, string);
const list = clvm.alloc([1, 2, 3, "test", true]);
// Serialize and deserialize
const serialized = list.serialize();
const deserialized = clvm.deserialize(serialized);NFT Operations
import { NftMetadata, NftMint, Constants } from 'chia-wallet-sdk-bundle';
// Create NFT metadata
const metadata = new NftMetadata(
1n, // edition number
1n, // edition total
["https://example.com/image.png"], // image URIs
null, // image hash
["https://example.com/"], // external URIs
null, // external hash
["https://example.com/description"], // description URIs
null // description hash
);
// Mint NFTs
const result = clvm.mintNfts(alice.coin.coinId(), [
new NftMint(
clvm.nftMetadata(metadata),
Constants.nftMetadataUpdaterDefaultHash(),
alice.puzzleHash,
alice.puzzleHash,
300 // fee
)
]);Universal Compatibility
This package is designed to work in:
- Node.js environments (16.0.0+)
- Web browsers with WebAssembly and ES6 Modules support
- Bundlers (webpack, vite, rollup, etc.)
Development
Building from Source
# Install dependencies
npm install
# Build the universal bundle
npm run build:bundleTesting
# Run tests
npm testLicense
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Credits
Special thanks to:
- SumSet Tech, LLC for sponsoring the initial development
- Solomons Lot for sponsoring the WASM bindings
- FireAcademy.io
- All open source contributors
Related Projects
- Chia Wallet SDK (Rust)
- Chia Wallet SDK (Node.js)
- Sage Wallet - A light wallet built using this SDK
