Open app

Flag an unpaid tab

Prove on chain that an agent didn't settle, with its own last voucher.

When a tab passes its settlement window without being settled, its service can flag it. The flag puts the agent's last signed voucher on chain; the program checks the signature and marks the tab unpaid with its cumulative amount public. The agent's unpaid count goes up where every service can read it.

When you can flag

  • The tab is open, or settling with a transfer that doesn't match the last voucher.
  • The settlement window has passed: the chain clock is later than the tab's opened_at plus your settlement_window_seconds. The middleware's flag also waits a grace period after that, a third of the window or 60 seconds, whichever is less, so an agent settling at the last moment isn't flagged.
  • You hold the last voucher the agent signed on that tab.
  • The transaction is signed with the service's signing key, which the middleware holds as AYO_SERVICE_KEY and your browser can derive.

A tab that is settling with a matching transfer is paid. Confirm it instead, with confirm(tabId). A tab with no voucher at all has nothing to flag; close it with void(tabId).

On your service's page at /app/services/[id], open tabs show their running totals, and a tab past its window shows Flag unpaid.

From your server

The middleware keeps the last accepted voucher of each tab in its journal, so it can flag directly:

flag.ts
import { Hono } from 'hono'
import { serve } from '@ayo/sdk/hono'

const payments = serve({ price: '0.002', unit: 'call' })
const app = new Hono()
app.use('/v1/*', payments)

// later, for a tab past its window
export async function flagOverdue(tabAddress: string) {
  await payments.flag(tabAddress)
}

flag checks the tab's status and the window against the chain clock, then sends one transaction: the Ed25519 precompile instruction verifying the voucher's signature against the agent's signing key, followed by flag_unpaid. It throws The settlement grace period has not elapsed. before the window and its grace period pass, and No accepted voucher is available as evidence. if the journal has no voucher for the tab.

From the app

  1. Find the voucher

    Copy the tab's last Ayo-Voucher header value from your middleware's log or journal.

  2. Flag unpaid

    On your service's page, press Flag unpaid on the overdue tab, paste the header value, and press Flag unpaid on chain. The app decodes the voucher, checks it belongs to that tab, and builds the flag transaction.

What changes on chain

FieldAfter the flag
Tab statusUnpaid
Tab flagged_amountThe voucher's cumulative amount
Tab closed_atThe time of the flag
Agent and service tabs_unpaidUp by one

The program refuses the flag if the window hasn't passed (WindowNotElapsed), if the tab already ended (TabFinal), or if the voucher doesn't match a verified Ed25519 instruction for this tab and agent (InvalidVoucher). See Errors.