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
Create the facilitator
The facilitator needs a signer that implementsFacilitatorAvmSigner: 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(...), orServerAvmSigner([key1, key2], algod_client)for several fee payers, of which the facilitator picks one at random per request.ServerAvmSigneralso implementsClientAvmSigner. - 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 raisesNetworkMismatchErrorotherwise. Without one, the signer uses the algod URL configured for the network inNETWORK_CONFIGS: AlgoNode for MainNet and TestNet, or a network added withregister_network. simulate_groupraisesSimulationErrorwhen algod reports that the group would fail;sign_transaction/sign_groupraiseSigningErrorfor an address the signer does not manage. A malformed key or mnemonic also raisesSigningError.- Keys stay in private attributes and are not shown by
repr(), exception messages or logs.signer.addressis the first managed address, handy aspay_to.
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 returnsVerifyResponse(is_valid=True, payer=<buyer>), oris_valid=Falsewithinvalid_reasonset 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 returnsSettleResponse(success=True, transaction=<txid>, network=<id>).transactionis the ID of the buyer’s payment (paymentGroup[paymentIndex]), as the specification requires. If submission fails it returnssuccess=Falsewitherror_reason="transaction_failed".
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
- Go to MainNet: fund the fee payer.
- Security: what the facilitator refuses to sign.