Build a Transaction
Building, signing, and submitting a Kaspa transaction with the WASM SDK.This guide builds and submits a simple payment transaction with the WASM SDK. It assumes an existing network connection. Use testnet-10 while learning - test KAS is free from the faucets.
Overview
Kaspa is a UTXO network, so building a transaction means: gather spendable UTXOs for an address, define the outputs to create, add a change output, compute mass/fees, sign the inputs, and submit. The SDK handles most of this. See Transaction Structure for what’s inside the result. All amounts are bigint sompi.
Keys and addresses
const { Mnemonic, XPrv, NetworkType } = kaspa;
const mnemonic = Mnemonic.random(); // or new Mnemonic(existingPhrase)
const xprv = new XPrv(mnemonic.toSeed());
// Kaspa's BIP-44 coin type is 111111
const privateKey = xprv.derivePath("m/44'/111111'/0'/0/0").toPrivateKey();
const address = privateKey.toAddress(NetworkType.Testnet); Build, sign, submit
createTransactions() performs coin selection, change output creation, and mass/fee calculation:
const { createTransactions, kaspaToSompi } = kaspa;
// 1. Gather UTXOs for the sending address
const { entries } = await rpc.getUtxosByAddresses([address]);
// 2. Build
const { transactions, summary } = await createTransactions({
entries,
outputs: [{ address: destinationAddress, amount: kaspaToSompi('0.2') }],
priorityFee: 0n, // extra sompi on top of the base fee; 0n is fine when the network is quiet
changeAddress: address
});
// 3. Sign and submit
for (const pending of transactions) {
await pending.sign([privateKey]);
const txid = await pending.submit(rpc);
console.log('Submitted', txid);
} transactions is an array because a large enough payment can exceed the per-transaction mass limit, in which case the SDK automatically chains multiple transactions. A typical payment produces one.
Notes
- Check
(await rpc.getServerInfo()).isSyncedbefore submitting. - The transaction can be watched in an explorer, or via
utxos-changedevent subscriptions. - For finer control, the SDK’s
Generatorclass takes the same parameters and yields pending transactions one at a time. - Fees are implicit (
inputs - outputs). Expected fee = fee rate × mass;rpc.getFeeEstimate()returns suggested fee rate buckets. - The Python SDK has the same flow (
create_transactions,sign,submit) - see its docs. - For multi-party or offline signing flows, see PSKT.