THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Wallet Accounting: Satoshi Ledgers and UTXO Reconciliation

permalink THAMER
#bitcoin#payments#reconciliation#satoshis#wallet-accounting

Bitcoin applications often need a ledger that is more specific than a wallet's aggregate balance. A merchant may track invoices, a payment service may reserve funds, and a wallet interface may distinguish confirmed from pending receipts. These are application records derived from Bitcoin transactions rather than separate consensus accounts.

Represent values as integer satoshis

Bitcoin Core JSON-RPC monetary values are expressed in BTC. Parse the decimal representation exactly and convert to integer satoshis. One BTC equals 100000000 satoshis. For example, 0.00012345 BTC equals 12345 satoshis. Reject unexpected precision instead of silently rounding a payment amount. Use signed integers for ledger debits and credits and check arithmetic bounds.

Separate observations from obligations

An observed UTXO belongs to a specific outpoint. An invoice belongs to an application identifier. A reservation represents a local commitment to fund a future transaction. These objects should not be collapsed into one balance field. A useful ledger records the outpoint, amount, observed confirmation depth, invoice association and current state. Record outgoing transaction fees separately from recipient amounts.

For example, a wallet with 50000 satoshis in confirmed eligible outputs may have 12000 satoshis reserved for another operation. The remaining 38000 satoshis is an application-level budget before additional fees and funding constraints, not a promise that a transaction of that exact amount will succeed.

Reconcile against the node

Use getbalances for aggregate wallet accounting, listunspent for eligible output observations and gettransaction for individual wallet transaction records. Record chain identity and wallet scope. When the observed chain tip changes during a multi-request read, repeat the relevant queries or mark the result as provisional. A matching tip alone does not guarantee that mempool state remained unchanged.

Handle retries and reorganizations

Persist an application operation identifier before initiating an outgoing payment. A network timeout does not prove that broadcast failed. Recover the known transaction or operation state before retrying a payment. Use database transactions or equivalent synchronization to prevent two workers from reserving the same funds.

When a block is disconnected, reduce confirmation depth and reassess settlement. A transaction may return to the mempool, conflict with another transaction, or disappear from the local mempool. Preserve the audit trail and update the current state rather than deleting evidence of the previous observation.

Define availability explicitly

Expose separate confirmed, pending, reserved and estimated available amounts. Document the confirmation and safety policy used for each field. The final funding decision must still account for input selection, fees, signing authority and current network state. A well-defined ledger makes discrepancies diagnosable without pretending that an application database replaces Bitcoin validation.

Primary references

https://bitcoincore.org/en/doc/28.0.0/rpc/wallet/getbalances/

https://bitcoincore.org/en/doc/28.0.0/rpc/wallet/listunspent/

https://bitcoincore.org/en/doc/28.0.0/rpc/wallet/gettransaction/

https://bitcoincore.org/en/doc/28.0.0/rpc/blockchain/getbestblockhash/

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects