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

Designing a Python Bitcoin Receive Tool for AI Agents

permalink THAMER
#ai-agents#bitcoin#sdk#wab-engine

Research question

A Python function can expose a narrow receive-address operation without giving the model an HTTP URL or credential. The caller chooses only the address type.

This is an independent educational reference example for WAB Engine API v5, not a required SDK or a live-tested integration. The wallet must already be restored by its owner. All wallet requests in this study use Testnet.

Reference implementation

Python · 25 lines
1import json, os, urllib.request
2class NoRedirect(urllib.request.HTTPRedirectHandler):
3    def redirect_request(self, req, fp, code, msg, headers, newurl):
4        return None
5
6def receive(address_type: str) -> str:
7    if address_type not in ("segwit", "taproot"):
8        raise ValueError("unsupported address type")
9    key = os.environ["WAB_BTC_KEY"]
10    req = urllib.request.Request(
11        "http://127.0.0.1:7070/api/v5/btc/wallet/receive",
12        data=json.dumps({"net":"test", "type":address_type}).encode(),
13        headers={"Content-Type":"application/json", "X-BTC-KEY":key}, method="POST")
14    opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
15    with opener.open(req, timeout=10) as response:
16        raw = response.read(1048577)
17    if len(raw)>1048576:
18        raise ValueError("oversized response")
19    data=json.loads(raw)
20    if data.get("ok") is not True:
21        raise RuntimeError("receive unavailable")
22    address=data["result"]["address"]
23    if not isinstance(address,str) or not address.startswith("tb1q" if address_type=="segwit" else "tb1p"):
24        raise ValueError("unexpected address")
25    return address

How to apply the example

Python 3 standard library only. Import receive from receive.py in a trusted local application and call receive("segwit") after configuring WAB_BTC_KEY privately. Importing the module does not make a request.

Engineering trade-offs and failure modes

Receive may advance wallet address state and should not be blindly retried. Prefix checking is a sanity check, not full Bech32 validation. Treat the returned address as wallet data and disclose it only to authorized callers.

The engine remains authoritative for wallet state and transaction execution. Do not expose wallet credentials, raw private wallet data or recovery material to the model. No SEND is performed by this study. Review the deployed API contract before adapting the example; no live engine tests have been performed.

References

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