Connect with the WASM SDK
Connecting to the Kaspa network from JavaScript/TypeScript using the WASM SDK's RpcClient and Resolver.The WASM SDK is the official JavaScript/TypeScript SDK, built from bindings to rusty-kaspa. This guide covers connecting to the network and making RPC calls. No node is required - the SDK’s Resolver finds a public node.
Get the SDK
Download the SDK zip (kaspa-wasm32-sdk-*.zip) from the rusty-kaspa releases page and unzip. It contains nodejs/kaspa (CommonJS, for Node) and web/kaspa (ES modules, for browsers), plus docs and examples.
Note: the npm packages (kaspa, kaspa-wasm32-sdk) lag well behind the GitHub releases. As of mid-2026, the release zip is the way to get the current SDK. API docs are at kaspa.aspectron.org/docs.
Connect (Node.js)
// Node needs a W3C WebSocket shim before the SDK loads (npm install websocket)
globalThis.WebSocket = require('websocket').w3cwebsocket;
const kaspa = require('./kaspa'); // path to the unzipped nodejs/kaspa
const { RpcClient, Resolver } = kaspa;
kaspa.initConsolePanicHook();
const rpc = new RpcClient({
resolver: new Resolver(), // public node resolver - no URL needed
networkId: 'mainnet' // or 'testnet-10'
});
await rpc.connect();
console.log('Connected to', rpc.url);
const info = await rpc.getServerInfo();
console.log('Synced:', info.isSynced, 'DAA score:', info.virtualDaaScore);
await rpc.disconnect(); To connect to a specific node instead (see Run a Node), pass a url instead of a resolver:
const rpc = new RpcClient({ url: '127.0.0.1', networkId: 'mainnet' }); Connect (browser)
The web build must be initialized with the WASM binary before use, and the page must be served over http(s) - file:// cannot load WASM:
import * as kaspa from './kaspa/kaspa.js';
await kaspa.default('./kaspa/kaspa_bg.wasm');
const rpc = new kaspa.RpcClient({ resolver: new kaspa.Resolver(), networkId: 'mainnet' });
await rpc.connect(); Events
RpcClient is an event emitter. Notifications require an explicit subscribe call after connecting:
rpc.addEventListener('virtual-daa-score-changed', (event) => {
console.log(event.data);
});
await rpc.subscribeVirtualDaaScoreChanged();
// Others: subscribeBlockAdded() → 'block-added',
// subscribeUtxosChanged([address]) → UTXO updates for the given addresses For wallet-style balance tracking, the SDK’s higher-level UtxoProcessor + UtxoContext classes handle UTXO and maturity tracking. See the transactions/ examples in the SDK zip.
Next
- Build a Transaction with this connection.
- The Python SDK (
pip install kaspa) mirrors the same API.