Architecture
x402 with Kora
The four application roles remain separate:- The client selects a payment requirement and signs the payment authorization.
- The resource server prices a route and fulfills it only after successful verification and settlement.
- The facilitator exposes x402’s
/supported,/verify, and/settleendpoints. - Kora signs only transactions allowed by its policy and can sponsor their Solana network fees.
Start the reference facilitator
You need Git, Node.js with pnpm (the demo’s scripts call pnpm), and thekora CLI
(installation). Clone the
latest stable Kora release and enter the x402 demo:
pnpm run setup generates a Kora signer keypair (KORA_SIGNER_ADDRESS and
KORA_SIGNER_PRIVATE_KEY) and a payer keypair (PAYER_ADDRESS and
PAYER_PRIVATE_KEY) and appends them to .env. The demo’s kora/signers.toml
reads the signer secret from KORA_PRIVATE_KEY, so add that variable to .env
with the same value as KORA_SIGNER_PRIVATE_KEY:
Use a disposable Devnet signerThe demo loads the Kora signer from an environment variable. Do not put a
production signing key in this demo or commit the
.env file.Note: The x402 demo has noWhen both servers are running, inspect the facilitator’s advertised capabilities from another terminal:docker-compose.ymlatv2.0.5. The one-commanddocker compose up --buildflow exists only onmainand thev2.2.0-beta.8pre-release tag.
2, the exact scheme, and the
Devnet CAIP-2 network identifier:
8080 and the facilitator on port 3000, on all network
interfaces; the commands on this page reach them at 127.0.0.1. The Kora
signer pays fees with real Devnet SOL, so firewall both ports from other
machines while the demo runs. Stop each process with Ctrl+C.
Connect a resource server
Configure the x402 resource server to use the local facilitator and the Kora signer’s public address as its recipient:PAYMENT-REQUIRED, the retry carries PAYMENT-SIGNATURE, and a successful
response carries PAYMENT-RESPONSE.
Do not copy examples that use X-PAYMENT, X-PAYMENT-RESPONSE, or the
solana-devnet network name. Those fields belong to x402 V1.
The Kora repository also includes a protected API and payment-aware client in
the same examples/x402/demo directory. Use those applications when you need to
exercise the complete local flow.
Configure the Kora policy
The referencekora/kora.toml is intentionally narrow. Its validation policy
controls:
- which Solana programs the signer permits;
- which SPL token mints can be used;
- the maximum sponsored lamports and signature count;
- which fee-payer operations are forbidden; and
- which Token-2022 extensions are rejected.
Warning: AtThe demo enables only the Kora RPC methods its facilitator needs:v2.0.5, the demo’skora/kora.tomllists the blocked Token-2022 extensions under[validation.token2022]. Kora 2.0.5 only reads[validation.token_2022]and silently ignores the other name, so the demo blocks no extensions. Rename the section to[validation.token_2022]before you rely on it, and checkvalidation_config.token_2022in thegetConfigresponse. See Token-2022 Extension Blocking.
signTransaction, signAndSendTransaction, getBlockhash, getPayerSigner,
and getConfig.
Treat the policy as the security boundary for the fee-payer key. For a
production service:
- Allowlist only the programs, token mints, and transaction forms your x402 scheme produces.
- Deny transfers, authority changes, account closure, and other instructions that can move value from the Kora signer.
- Set transaction and usage limits that bound the loss from a compromised facilitator credential.
- Use a managed signer backend instead of an environment-held private key.
Secure the facilitator-to-Kora connection
The demo enables Kora API-key authentication. The facilitator sends the value ofKORA_API_KEY, which must match [kora.auth].api_key in kora.toml.
For production, also:
- keep Kora on a private network and terminate TLS at a trusted boundary;
- store API credentials in a secret manager and rotate them;
- consider Kora’s HMAC request authentication for tamper and replay protection;
- separate fee-payer and payment-recipient keys when your accounting model requires it; and
- alert on policy rejections, settlement failures, fee consumption, and signer balance.
Harden payment settlement
Kora validates the Solana transaction, but the facilitator and resource server still own x402 protocol correctness. Before serving a resource, enforce:- the selected x402 version, scheme, network, asset, amount, and recipient;
- the authorization lifetime and exact Solana instruction layout;
- atomic replay protection and idempotent settlement;
- confirmation at the commitment level required by the product; and
- a durable mapping between the purchase, settlement result, and fulfillment.