A settlement pays for one call. A service answers a call with HTTP 402 and a price, the agent signs an authorization for that call, and the service submits the authorization to the program, which checks it against the agent's policy and moves the USDC. The service pays the network fee for the transaction; Civitas sponsors none.
The quote
The service answers an unpaid call with status 402 and an x402 version 1 body: an accepts list of offers and an error sentence. A Civitas offer has scheme: "civitas". It names the payee (payTo, the service's agent key), the mint (asset), the price in base units (maxAmountRequired) and the resource, and its extra carries what the Civitas scheme adds: the 32-byte callId that identifies this quote, the program ID, the fee terms, the fee for this call and the authorization's expiry. A real one, from a sample service charging 0.2 USDC on a local validator:
{
"x402Version": 1,
"accepts": [
{
"scheme": "civitas",
"network": "localnet",
"maxAmountRequired": "200000",
"resource": "http://127.0.0.1:27431/feed",
"description": "One service call",
"mimeType": "application/octet-stream",
"payTo": "7rAhGgYhJgfiskiVo6XrL5yv88uNp1ZVC3pBR9YaXHhT",
"maxTimeoutSeconds": 60,
"asset": "D1tHNwY4UXsc7xwKgjMEgNhjDxiVnazp5YRvPs4eFC8f",
"extra": {
"callId": "0c418ff1efcb661068530a5bb17e91a3ad747e48490a467dfd5b1b0ea2447516",
"programId": "Bhxc3t3tDe5BWYhDEqWtPiaQKUrFxareR6Fd8LfXy5ht",
"feeBps": 25,
"feeFloor": "500",
"fee": "500",
"expiresAt": "2026-11-26T11:11:02.000Z"
}
}
],
"error": "PaymentRequired"
}Every field is under PaymentRequirements. The price goes to the payee. The protocol fee, extra.fee, comes on top, from the same vault.
The authorization
The agent pays by signing 209 bytes with its agent key. They name the program, the mint, both parties, the amount, the fee, the agent's nonce, the call ID from the quote and an expiry, with no length prefixes or padding:
| Bytes | Length | Value |
|---|---|---|
| 0..17 | 17 | civitas.settle.v2, ASCII |
| 17..49 | 32 | the Civitas program ID |
| 49..81 | 32 | the USDC mint |
| 81..113 | 32 | the payer's agent key |
| 113..145 | 32 | the payee's key |
| 145..153 | 8 | amount, u64 little-endian |
| 153..161 | 8 | the protocol fee, u64 little-endian |
| 161..169 | 8 | the agent's nonce, u64 little-endian |
| 169..201 | 32 | the call ID |
| 201..209 | 8 | expiry, Unix seconds, i64 little-endian |
The agent signs the exact outflow it agrees to: the amount and the fee. If the fee terms change between the quote and the settlement, the program refuses the authorization with FeeMismatch instead of charging a fee the agent never saw. Because the mint is in the signed bytes, an authorization made on a local cluster can't settle on mainnet. authorizationBytes in @civitas/contract builds exactly these bytes:
import { authorizationBytes, PROGRAM_ID } from '@civitas/contract'
declare const usdcMint: string, agentKey: string, serviceKey: string, callId: string
declare function sign(message: Uint8Array): Promise<Uint8Array>
const message = authorizationBytes({
programId: PROGRAM_ID,
asset: usdcMint,
payer: agentKey,
payee: serviceKey,
amount: '5000',
fee: '500',
nonce: '42',
callId,
expiresAt: '2026-11-26T12:06:00Z',
})
const signature = await sign(message) // Ed25519, with the agent keyThe agent sends the authorization and its signature back in the X-PAYMENT header: base64 of the UTF-8 JSON { "x402Version": 1, "scheme": "civitas", "network", "payload": { "authorization", "signature" } }. Its fields are under Authorization and PaymentPayload.
What the program checks
The service submits a transaction with two instructions: the native Ed25519 instruction carrying the agent's signature and the authorization bytes, then settle. settle reads the instruction just before it through the instructions sysvar, so the signature is verified by the runtime and matched by the program. Then it checks the agent's status, the policy's expiry and the authorization's, that the signed fee is the one its config gives for the amount, the nonce, the counterparties, the per-call limit and the period cap. Any failed check refuses the whole transaction with a named error. The exact order is under settle.
When every check passes, the vault pays the amount to the payee and the fee to the fee recipient, in the same instruction. A payee that is a chartered agent is paid into its vault; any other key is paid into its USDC associated token account. The program then emits Settled with the policy version the payment ran under.
Nonces
The agent picks a nonce for each authorization and counts up. The agent account keeps the highest nonce settled and a 256-bit map of the 256 nonces at and below it. A nonce above the highest moves the range up; one inside it settles once; one below it is refused with NonceReplayed. Calls can run at the same time and land in any order, and no account is created per call, so a settlement pays no rent.
The answer
After the settlement lands, the service serves the call and answers with the X-PAYMENT-RESPONSE header: base64 of the UTF-8 JSON with success, network, transaction (the settlement's signature), payer and the service's signed receipt. Civitas then indexes the settlement and the filter classes it.