Kaspeak SDK¶
This page provides a concise guide to the main methods and features of Kaspeak SDK. Detailed data formats and cryptography schemes are described in corresponding documentation sections.
This is a practical guide to using the SDK.
Quick Start¶
Initialize the SDK:
create(privateKey, prefix, networkId?) Method Parameters¶
privateKey— private key for the address, represented asbigint,number,Uint8Array, or hex-string.prefix— unique ASCII prefix for your application, up to 4 characters. This prevents messages from different apps from overlapping.networkId(optional) —"mainnet","testnet-10"(default).
After calling create(), the SDK is fully initialized and ready to connect.
connectNode(url?) Method Parameters¶
url(optional) — URL to connect to a specific Kaspa node. If not specified, the SDK will automatically select a node.
Event Subscription and Error Handling¶
| Event | Data |
|---|---|
message |
{ header, data } |
balance |
{ balance, utxoCount } |
node-connect |
void |
node-disconnect |
void |
error |
string |
messagefires for every incoming payload, even if its type is not registered.balanceis triggered on any balance change for the SDK address.node-connectis called immediately after successfully establishing an RPC connection to the Kaspa network.node-disconnectis triggered when the current RPC connection is closed.erroris a stub for future functionality.
Working with Custom Message Types¶
To create your own message types:
The registerMessage(ctor, worker?) method:
ctor— class that extendsBaseMessage.worker— handler function for incoming messages of this type.
Core SDK Methods for Messaging¶
Encoding and sending a message:
Decoding and handling a message:
Getting conversation keys (for encryption and identifiers):
Checking balance:
SDK Settings and Parameters¶
Kaspeak SDK has flexible configuration:
Additional SDK Methods and Properties¶
- sdk.address — The Kaspa address used, derived from the private key.
- sdk.publicKey — Public key (hex, 33 bytes in compressed format).
- sdk.balance — Actual balance of the address in use.
- sdk.utxoCount — Current number of UTXOs for the address.
- sdk.isConnected — Status of the current connection to the Kaspa network.
- sdk.getAddressFromPublicKey() — Get Kaspa address from public key.
- sdk.transferFunds() — Send KAS to one or more addresses.