Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

🦀 Kaspa Rust Starter Kit

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.

What's inside

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.

Prerequisite: install Rust

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 --version

If you already have rustup but an older default, run rustup update.

Set up the kit

cd kaspa-rust-starter
cp .env.example .env
cargo build

Run it (in order)

# 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 -- --spend

KASPA_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.

Reference

How it fits together

  • Connect: KaspaRpcClient::new(WrpcEncoding::Borsh, None, Some(Resolver::default()), Some(network_id), None), then client.connect(...), with network_id = NetworkId::with_suffix(NetworkType::Testnet, 10).
  • Wallet: a secp256k1::Keypair turns into Address::new(Prefix::Testnet, Version::PubKey, &xonly_pubkey).
  • Send: get_utxos_by_addresses gives you UTXOs; build a Transaction with pay_to_address_script outputs, sign it via sign(MutableTransaction::with_entries(tx, entries), keypair), and call submit_transaction.
  • Covenants: ScriptBuilder builds a redeem script, then pay_to_script_hash_script plus extract_script_pub_key_address turn it into a spendable P2SH address. Spending reveals the script and a signature in the input's unlock script.

Where to go next