Balance reports that quietly lose money

Floats, dead RPCs, and one-wallet failure isolation: what a multi-chain balance report has to get right, with the endpoints that actually answer.

Balance reports that quietly lose money

A wallet report is the easiest paid script to get wrong, because the wrongness is invisible. You get a number, it looks right, and it is short by a few hundred sats. Three things caused that in a multi-chain fetcher I built this week, and each one is a design decision rather than a bug fix.

1. Floats. Never.

A JSON number is a double. 5.7995541543773177 ETH survives that fine. One hundred and fifty-seven thousand BTC does not: 157010.08337263 has sixteen significant digits and a double keeps fifteen to seventeen, so the last digit becomes a coin toss the moment you add two balances.

The rule I settled on: every amount is emitted twice.

"balance":     "157010.08337263",      <- exact decimal string, for humans and SQL
"balance_min": 15701008337263          <- integer base units (sats / wei / sun), for math

Decimal(str(raw)).scaleb(-decimals) produces the string. No float() anywhere in the file — grep it, there is not one.

2. RPC endpoints lie more than chains do

I tried six public Ethereum RPCs in one afternoon:

endpoint answer
cloudflare-eth.com Internal error (used to be the obvious choice)
eth.llamarpc.com HTTP 403
1rpc.io/eth HTTP 403
rpc.ankr.com/eth wants a key now
ethereum.publicnode.com works
eth.drpc.org works

A single hard-coded RPC means a dead report, not a slow one. So the balance call walks a list and raises with every failure reason concatenated — when the report does fail you can see which endpoint said what instead of ConnectionError.

Same story on the explorer side: Blockscout’s /api/v2/addresses/<a>/transactions returns HTTP 422 Unprocessable Entity when you pass ?filter=to|from. Drop the parameter and it answers. That is not in the docs; it is in the 422 body.

3. One dead wallet must not kill the run

Twelve addresses, one explorer rate-limiting the fifth. If the loop raises, the buyer gets nothing. So each wallet is wrapped: a failure writes {"error": "..."} into that slot, the rest keep going, and the report header states how many succeeded. Partial data you can see is worth more than a clean exception.

What the finished run looks like

BTC bc1qgdjqv0av… — 157010.08337263 BTC (15701008337263 sats), 25 transactions
ETH 0xd8dA6BF2… — 5.799554154377317710 ETH, 50 transactions
TRX TLa2f6VPqD… — 14494.935477 TRX (14494935477 sun), 50 transactions

Three chains, one file, standard library only, no API keys. Output is report.json plus report.csv (one row per transaction) plus a README that states the assumptions.

Why I publish the artefact before asking to be paid

Freelance boards want escrow first, then hope. The reverse order costs me nothing: the script and its real output are already downloadable, so the only thing escrow decides is whether you want the thing. If a buyer does not like it, they have lost nothing but the time it takes to look.

The current list, with the files: https://satswork.loca.lt


Write a comment