A small Rust starter kit for building on Kaspa testnet-10. Four binaries take you from generating a wallet all the way to spending a covenant. Nothing here needs a local node; it all goes through the public Resolver.
| Binary | What it does | Needs funds? |
|---|---|---|
wallet |
Generate a wallet (keypair + testnet address) | no |
connect |
Connect via Resolver, read your balance | no |
send |
Build, sign, and broadcast a transaction | yes |
covenant_p2sh |
Lock funds in a pay-to-script-hash covenant, then spend it | to spend |
The shared bits (connect, keypair, address, .env) live in src/lib.rs.
This is a one-time setup of the language itself, separate from the kit. You only do it once per machine.
Install Rust via rustup. rust-toolchain.toml pins the
toolchain to 1.91.0, and rustup fetches it automatically on the first cargo
command. A Rust installed some other way (Homebrew, apt, the system package
manager) won't honor the pin and may be too old. Check:
rustup --version
cargo --versionIf you already have rustup but an older default, run rustup update.
cd kaspa-rust-starter
cp .env.example .env
cargo build# 1. Make a wallet. Copy the printed private key into .env (KASPA_PRIVATE_KEY=...).
cargo run --bin wallet
# 2. Fund the address from the faucet (see below), give it a few seconds, then check it landed.
cargo run --bin connect
# 3. Send 1 KAS back to yourself and watch it in the explorer.
cargo run --bin send
# 4. Print a P2SH covenant address; paste it into the faucet to fund it, then spend it.
cargo run --bin covenant_p2sh
cargo run --bin covenant_p2sh -- --spendKASPA_PRIVATE_KEY is read from .env or the environment.
The send and covenant_p2sh binaries submit a transaction and print its id.
Re-run connect to watch the balance change, or look the tx id up in the explorer.
- Network:
testnet-10. Addresses start withkaspatest:. - Faucet: https://faucet-tn10.kaspanet.io/. Paste your
kaspatest:address to get test KAS. - Explorer: https://tn10.kaspa.stream/ — search your address or a tx id.
- Units: amounts are in sompi, where 1 KAS = 100,000,000 sompi.
- No node required:
Resolver::default()finds a public testnet-10 node for you. - Docs: https://docs.kaspa.org
- Connect:
KaspaRpcClient::new(WrpcEncoding::Borsh, None, Some(Resolver::default()), Some(network_id), None), thenclient.connect(...), withnetwork_id = NetworkId::with_suffix(NetworkType::Testnet, 10). - Wallet: a
secp256k1::Keypairturns intoAddress::new(Prefix::Testnet, Version::PubKey, &xonly_pubkey). - Send:
get_utxos_by_addressesgives you UTXOs; build aTransactionwithpay_to_address_scriptoutputs, sign it viasign(MutableTransaction::with_entries(tx, entries), keypair), and callsubmit_transaction. - Covenants:
ScriptBuilderbuilds a redeem script, thenpay_to_script_hash_scriptplusextract_script_pub_key_addressturn it into a spendable P2SH address. Spending reveals the script and a signature in the input's unlock script.
- Send to a different address by editing
toinsrc/bin/send.rs. - Add covenant rules (for example, enforcing the recipient or amount) in
build_redeem_scriptinsrc/bin/covenant_p2sh.rs. - Reference code in rusty-kaspa (pinned to the
v2.0.1tag):rpc/wrpc/examples/simple_client,rothschild, andcrypto/txscript/examples/covenants.rs.