Accepting vouchers and redemption
A receipt says what a request cost. A voucher is the buyer's signed promise to pay a running total. It is the only payable message in the protocol: the program pays you from a voucher, never from a receipt.
The voucher (IM/VOUCHER/1, 168 bytes)
| Field | Bytes | Value |
|---|---|---|
| tag | 16 | IM/VOUCHER/1, zero padded |
| domain | 64 | genesis hash ‖ program ID |
| channel | 32 | channel account |
| channel_epoch | 8 | channel epoch |
| seq | 8 | informational |
| settled_total | 8 | cumulative micro-USDC the buyer accepts on this channel |
| receipts_commitment | 32 | hash chain over the receipts covered so far |
Signed by the channel's session key. The commitment chain is:
C0 = SHA256("IM/EMPTY/1")
Ci = SHA256("IM/APPEND/1" ‖ C(i−1) ‖ SHA256(receipt_bytes))
Posting a voucher
POST /im/v1/vouchers with a JSON body of at most 1 MiB:
{ "voucher": "<base64 of 168 bytes>", "sig": "<base64 of 64 bytes>", "receipts": ["<base64 of 382 bytes>"] }
receipts holds the receipts this voucher adds since the last acknowledged voucher, at most 2,014 per post. On success the gateway answers {"ack": true, "settled_total": <integer>} after the acknowledgment is synced to disk.
What the gateway checks
| Check | Refusal (HTTP 400) |
|---|---|
| Body is valid protocol JSON with the right base64 lengths | malformed_voucher (413 when the body is too large) |
| Channel is in the gateway's view, epoch and domain match, and the channel names this gateway's settler and payout account | wrong_channel |
| The session key signed the voucher | bad_signature |
settled_total ≤ budget |
over_budget |
| The channel is not finalized and its close deadline has not passed | channel_closed |
settled_total is not below the last acknowledged total or the on-chain redeemed |
wrong_delta |
| Every receipt was issued by this gateway on this channel and epoch, byte for byte, and none is already acknowledged | invalid_receipt |
Receipts are in canonical order: ascending (created_at, request_id), no repeats (A3) |
receipt_order |
The receipts' charges sum exactly to settled_total − last acknowledged total |
wrong_delta |
The commitment, continued from the last acknowledged one with these receipts, equals receipts_commitment |
wrong_commitment |
Posting the exact same voucher, signature and receipts as the latest acknowledgment again is a no-op success, so buyers can retry an ambiguous post safely. Concurrent posts for one channel are serialized; two posts cannot both consume a receipt.
The buyer chooses what to cover (A25′)
A voucher may cover any batch of previously unacknowledged receipts, in canonical order. You cannot demand completeness. A receipt the buyer leaves out, including one it quarantined as possible equivocation, stays as your unvouchered exposure: it keeps counting against the channel in admission check 14, so you stop admitting new Holds before that exposure exceeds the channel's funds (admission).
A worked example: receipts of 2,210, 60 and 7,250 µUSDC are issued in that order. The buyer posts one voucher with settled_total: 9520 and all three receipts. Later it posts settled_total: 9580 with a single new 60 µUSDC receipt; the delta (60) must equal that receipt's charge exactly.
Redemption
Acknowledged vouchers are redeemed by the gateway's settler, not by the buyer:
- Every
settlementIntervalMs(2 s by default) the settler takes up tosettlementBatchSize(16) pending vouchers and relays up to four channels concurrently. - Each channel's latest cumulative voucher goes on-chain in one transaction: the native Ed25519 precompile instruction over the 168 voucher bytes immediately followed by
redeem(A24). The settler key pays the fee. - The program checks the session key's signature,
settled_total ≤ budget, and that the close deadline has not passed. It payssettled_total − redeemedinto the channel's payout account and recordsredeemed = settled_total. A voucher at or belowredeemedis a no-op success. - If an earlier submission for the channel is still unresolved, it takes priority over a newer acknowledgment.
So a channel that served a thousand requests settles in one transaction per relay pass, not a thousand.
| Outcome | Meaning |
|---|---|
confirmed |
This transaction landed and paid. |
already_redeemed |
The chain already covers this total (for example after a restart); nothing to pay. |
expired |
The channel is finalized or its close deadline passed. The voucher can no longer be paid. |
| deferred | RPC unavailable or the result is ambiguous; retried on a later pass. |
Before its first send, the settler writes the exact signed transaction and its validity horizon to the ledger and waits for the write to be durable. After a crash it looks up that exact signature in transaction history and rebroadcasts only those bytes while they can still land; it builds a replacement only once a finalized block height proves the original expired. Use a history-enabled RPC: lagging or pruned history defers settlement rather than risking a double send.
The deadline that matters
Redemption only works while now < close_deadline (D). When the vault owner, the Mandate's agent or your settler calls begin_close (or anyone calls close_on_revoked after the channel's Mandate is revoked or expired), D becomes min(service_end, now) + grace. The buyer's unused budget returns to its vault at finalize, after D. Keep your gateway and settler running, funded and connected through every open channel's grace period; an acknowledged voucher that is not redeemed before D is lost (payouts).