A software-only tool for paying an API per request in Nano (XNO) where the number of payments does not appear on the ledger. Pure Python standard library plus one small C file. No exchange, no facilitator, no hosted service, no change to the Nano protocol.
Status: built and verified on a local ledger that applies the Nano node's own block rules. Not yet run on mainnet (see "What is not verified").
The research (in .ledger/benchmark.md and .ledger/ranking.md) found:
- "x402 on Nano" already exists several times (x402nano, x402.Nano, Feeless402). Porting it again adds nothing.
- The incumbent, x402 over USDC, wins on usage-shaped payments (
upto, batch vouchers with an escrow contract). Nano has no scripts, so it has no equivalent. - Nano's own obstacle for agents is not fees but proof-of-work: one send costs about 33 seconds of 8-core CPU on this laptop (measured: 16.3 MH/s, 2^29 hashes expected). An agent paying per request on the ledger needs a GPU, and every payment becomes a permanent block on every node.
Fifty brainstormed ideas were evaluated. Seven of them proposed "one block per chunk" streaming and fail on that measured cost. The winner removes the per-payment block altogether.
Two facts about Nano make this possible, both read from the node source:
- A block states the account's resulting balance and is valid only if its
previousis the account head. Two blocks with the samepreviousare rivals; only one is ever confirmed. - Proof-of-work is computed over
previous. Rival blocks therefore share one valid work nonce.
So a payment can be a real send block that is signed but not broadcast. To pay more, sign a rival block with a lower remaining balance. The seller keeps the latest and broadcasts it once.
The buyer funds a session account it controls and signs vouchers from it. Zero setup beyond funding.
The buyer could still broadcast something else at that head, so the seller is exposed for what it has served
since its last settlement; SoloSeller.exposure measures that and head_moved detects the cheat.
The session account is a 2-of-2 aggregated key (nanotab/cosign.py, the MuSig2 construction over Nano's
Ed25519-Blake2b; the network sees an ordinary account). Its whole life is three blocks:
| Block | Does | previous |
|---|---|---|
| O | receives the buyer's deposit | 0 |
| V(n) | sends n (total owed) to the seller | hash(O) |
| R(n) | sends the remainder to the buyer | hash(V(n)) |
- The buyer only ever gives a partial signature on V(n). Only the seller can complete a voucher, so the buyer cannot move the account before settlement.
- Before signing V(n) the buyer must hold a complete signature on R(n). R(n) extends V(n), so it is invalid until the seller confirms exactly V(n); after that the buyer needs nobody to get the remainder.
TabServer answers an unpaid request with 402 and its terms; TabClient opens a channel on the first
402 and then pays per request with two small calls. Settlement is one block; the refund is one block.
| Measure | Result | Where |
|---|---|---|
| Ledger blocks added by 60 paid HTTP requests | 0 | tests/test_paywall_meter.py |
| Proof-of-work searches for 1,000 solo vouchers | 1 | tests/test_voucher_work.py |
| Blocks for a whole co-signed session | deposit, open, voucher, refund, plus the two receives | examples/end_to_end.py |
| Solo payments per second (pure Python) | about 160 | python3 bench.py |
| Co-signed payments per second (pure Python, localhost HTTP) | about 14 | python3 bench.py |
| One on-ledger send, native 8-thread work on this laptop | about 33 s expected, 3.6 to 60.6 s observed over 6 runs | tools/pow.c |
The co-signed rate is limited by Python big-integer arithmetic, not by the design.
- Python 3.8 or newer (developed and tested on 3.14). Standard library only; nothing to
pip install. - A C compiler (
cc) only if you want native proof-of-work (tools/pow.c). Everything else runs without it. - No Nano node, no account with any service, no API key.
git clone https://github.com/dhyabi2/nanotab.git
cd nanotab
python3 examples/end_to_end.py
Or as a package: pip install .
Solo mode, three payments, one signature each and no ledger block:
import os
from nanotab import ed25519b
from nanotab.voucher import SoloPayer, SoloSeller
EASY = 0xF000000000000000 # demo work threshold; mainnet is block.SEND_THRESHOLD
buyer_key = os.urandom(32)
session = ed25519b.public_key(buyer_key)
seller = ed25519b.public_key(os.urandom(32))
head = os.urandom(32) # current head of the funded session account
payer = SoloPayer(buyer_key, head, cap=1000, seller=seller, representative=seller, threshold=EASY)
shop = SoloSeller(seller, session, head, cap=1000, threshold=EASY)
for _ in range(3):
shop.accept(payer.pay(10)) # raises ValueError if the voucher must be refused
print(shop.owed) # 30
print(shop.best.to_json()) # the one block the seller broadcasts to settleFor the co-signed channel and the HTTP paywall, read examples/end_to_end.py; it is the shortest complete use.
python3 -m unittest discover -s tests -t . # 87 tests
python3 examples/end_to_end.py # the whole story in 15 checked steps
python3 bench.py
Nano has no timelock, so no design can give the buyer an exit that needs no seller action without also
letting the buyer exit with a stale state. (Three alternative refund designs proposed in the brainstorm were
checked and each breaks seller safety; see .ledger/ranking.md.) The risk is therefore assigned, not removed:
| Mode | Seller can lose | Buyer can lose |
|---|---|---|
| Solo | what it served since its last settlement | nothing |
| Co-signed | nothing | the unspent deposit, only if the seller never settles, which also forfeits all the seller earned |
Keep co-signed deposits small and renew the channel. A seller that goes offline permanently strands the deposit; there is no recovery path in this version.
- No mainnet run. Signatures, hashes and work are checked against real confirmed mainnet blocks, and the
local ledger mirrors
state_block_implfrom nano-node check for check, but no channel has been opened on the live network. That needs a small amount of XNO and was not attempted without approval. - Fork resolution is modelled as first-seen. The live network resolves rival blocks by representative vote; the local ledger applies the first valid block it is given.
- No independent cryptographic review. The co-signing code follows the published MuSig2 construction and has tests for rogue keys, nonce reuse, small-order keys and tampered partials, but it has not been audited. Do not put meaningful funds in it.
- The seller trusts its ledger view.
TabServertakes aledger_viewcallable; pointing it at a single hosted RPC means trusting that RPC about the deposit. Vote-quorum receipts were ranked second and not built: three public websocket endpoints were tested and none relays representative votes, so it needs a direct peer-to-peer client. - One pending payment per channel. The seller holds one in-flight request per channel; concurrent requests need one channel each.
nanotab/ed25519b.py Ed25519 with Blake2b-512 (Nano's signature scheme)
nanotab/address.py nano_ address encoding
nanotab/block.py state blocks, hashing, work value
nanotab/simledger.py local ledger with the node's state-block rules
nanotab/voucher.py solo mode
nanotab/cosign.py two-round aggregated signatures
nanotab/channel.py co-signed mode
nanotab/wire.py JSON form of messages
nanotab/paywall.py HTTP 402 server and client
nanotab/native_work.py wrapper for tools/pow.c
.ledger/ benchmark, ranking of all 50 ideas, law ledger with receipts
Every design decision is a "law" with a runnable check, recorded in .ledger/ledger.json: 16 laws, each with
an oracle command and a mutation check, plus an end-to-end probe. .ledger/benchmark.md holds the sourced
comparison with x402 over USDC and .ledger/ranking.md the evaluation of all 50 candidate ideas.
Experimental software. It has not been audited and has not been run on Nano mainnet. Do not use it with funds you cannot afford to lose. Please report problems through GitHub issues.
MIT. See LICENSE.