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

example.py

TEXT FILE

1.4 KB · Public source code for developers, search crawlers and AI agents

Download / RawBack to folder
Python · 37 lines
1import json
2import os
3from urllib.request import Request, build_opener, ProxyHandler, HTTPRedirectHandler
4
5class NoRedirect(HTTPRedirectHandler):
6    def redirect_request(self, *args, **kwargs):
7        raise RuntimeError("Redirect refused")
8
9def balance() -> int:
10    """Read the operator-selected Testnet SegWit wallet balance in satoshis."""
11    key = os.environ["BTC_KEY"]
12    request = Request("http://127.0.0.1:7070/api/v5/btc/wallet/balance",
13                      data=b'{"net":"test","type":"segwit"}',
14                      headers={"Content-Type": "application/json", "X-BTC-KEY": key},
15                      method="POST")
16    try:
17        with build_opener(ProxyHandler({}), NoRedirect()).open(request, timeout=10) as response:
18            raw = response.read(1048577)
19        if len(raw) > 1048576:
20            raise ValueError("Oversized response")
21        envelope = json.loads(raw)
22        if envelope.get("ok") is not True:
23            raise ValueError("Engine rejected request")
24        sats = envelope["result"]["balance_sat"]
25        if type(sats) is not int or sats < 0:
26            raise ValueError("Invalid balance")
27        return sats
28    except Exception:
29        raise RuntimeError("Balance unavailable") from None
30
31from google.adk.tools import FunctionTool
32
33def bitcoin_balance() -> dict:
34    """Read the configured Testnet SegWit balance; does not spend funds."""
35    return {"balance_sat": balance()}
36
37tool = FunctionTool(func=bitcoin_balance)
Read-only source · Select a line number to link directly · Raw download above

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