Idempotency and Ambiguous Bitcoin Payment Outcomes
Research scope
This is Stage 01, study 05, of Bitcoin for AI Agents. It is an educational reference design, not a live-tested integration or production SDK. The WAB Engine remains independent; wallet creation belongs to the Factory.
Architecture and rationale
A payment intent needs its own unique identifier. Two legitimate payments with identical amounts and destinations are not the same intent. Retries of one intent must retain its original idempotency key.
Reference implementation
This Python example creates an intent record before any network request. Persist the complete immutable record before execution; the example does not implement a database or retry transport.
1from dataclasses import dataclass
2from uuid import uuid4
3
4
5@dataclass(frozen=True)
6class PaymentIntent:
7 intent_id: str
8 wallet: str
9 destination: str
10 total_debit_sat: int
11
12
13def new_intent(wallet: str, destination: str, total: int) -> PaymentIntent:
14 if type(total) is not int or total <= 0:
15 raise ValueError("invalid total debit")
16 return PaymentIntent(str(uuid4()), wallet, destination, total)Security and limitations
A timeout after submission is an ambiguous outcome, not proof of failure. Reconcile using the engine contract and known transaction identifiers. Do not create a fresh key or blindly resend after an uncertain outcome.
Applying the pattern
Keep the model-facing interface separate from trusted execution. Review the current engine API before mapping fields or response data. Use a dedicated test wallet and explicit network configuration for any future live evaluation. The example does not change the engine, its signed fee law, or Bitcoin Core.
