Use this page when you run the facilitator yourself: as a separate service for several resource servers, or by calling verify and settle directly. If you use PaymentGate or the in-process setup on Paywall an HTTP API, a facilitator is already running and you can skip this page.

Verify and settle without HTTP

This script builds a 10,000 microALGO payment with the client scheme, then verifies and settles it with the facilitator scheme, on LocalNet:
localnet/manual_flow.py
Source: examples/localnet/manual_flow.py
It prints both addresses, the network, the verification result, the settled transaction id and the confirmed round.

Create the facilitator

The facilitator needs a signer that implements FacilitatorAvmSigner: it manages one or more fee payer accounts and talks to algod. ServerAvmSigner is a ready-made one:
  • Constructors: from_private_key(key, algod_client=None, *, algod_url=None, algod_token=None), from_mnemonic(...), or ServerAvmSigner([key1, key2], algod_client) for several fee payers, of which the facilitator picks one at random per request. ServerAvmSigner also implements ClientAvmSigner.
  • With an algod client (or algod_url= / algod_token=), the first use for a network checks that the node’s genesis hash matches it and raises NetworkMismatchError otherwise. Without one, the signer uses the algod URL configured for the network in NETWORK_CONFIGS: AlgoNode for MainNet and TestNet, or a network added with register_network.
  • simulate_group raises SimulationError when algod reports that the group would fail; sign_transaction / sign_group raise SigningError for an address the signer does not manage. A malformed key or mnemonic also raises SigningError.
  • Keys stay in private attributes and are not shown by repr(), exception messages or logs. signer.address is the first managed address, handy as pay_to.
To keep fee payer keys in a KMS or HSM, implement the protocol yourself. DefaultAvmSigner(private_key, algod_client=...) from ai-economy-sdk also implements it. register_exact_avm_facilitator takes one network id or a list, and also registers the scheme for the x402 v1 names algorand-mainnet and algorand-testnet. Use the sync x402FacilitatorSync with Flask and other WSGI code.

What verify and settle do

  • facilitator.verify(payload, requirements) checks the group against the requirement, checks every transaction sent by one of its own addresses (a 0-amount self-payment, no close-out or rekey, fee at most 16,000 microALGO), signs the fee payer transaction and simulates the group on algod. It returns VerifyResponse(is_valid=True, payer=<buyer>), or is_valid=False with invalid_reason set to an error code. Nothing is submitted.
  • facilitator.settle(payload, requirements) verifies again, signs the fee payer transaction, submits the group, waits up to 4 rounds for confirmation and returns SettleResponse(success=True, transaction=<txid>, network=<id>). transaction is the ID of the buyer’s payment (paymentGroup[paymentIndex]), as the specification requires. If submission fails it returns success=False with error_reason="transaction_failed".
An invalid payment never raises; verify() and settle() return a code. The facilitator refuses a payment whose sender is one of its own fee payer addresses (invalid_exact_avm_payload_fee_payer_transferring_funds), so the fee payer can never be the buyer. The full order of checks: AVM exact scheme.

Next