Skip to main content
An agent (or payer) is any client that calls x402-gated endpoints. When the server returns 402 Payment Required, the agent signs a TransferFactory_Transfer (naming the merchant as receiver) but does not submit it — it attaches the payer-signed transfer as the payment proof and retries automatically. The facilitator relays that signed transfer and pays the network traffic fee; because the merchant holds a standing TransferPreapproval, it settles directly to the merchant in a single transaction.

Install

These examples target mainnet via the facilitator.ftptech.xyz relay. The CLI defaults to canton:testnet, so select mainnet first, otherwise a testnet wallet hits the mainnet facilitator and payments fail with a network mismatch:

CLI Commands

Create a wallet

Generates an Ed25519 key pair, allocates a Canton party, and saves the wallet to ~/.canton-agent/wallet.json.

Address

Print the party ID. Use this to receive CC from a wallet or another agent.

Balance

Claim

Accept incoming CC transfers (e.g. the initial funding from a wallet):

Pay

Fetch a URL, automatically paying any x402 402 challenge:
For POST endpoints (e.g. LLM inference with a request body), use makePayingFetch from the SDK instead.

Withdraw

Send CC to any Canton party:
--amount is in CC (decimal), so 5.0 = 5 CC. This differs from PaymentRequirements.amount in the 402 challenge, which is in atomic units (10^10 per CC).

Registry tokens (e.g. USDCx)

The wallet handles CIP-56 registry tokens (like USDCx) alongside Canton Coin. Two independent opt-ins keep them safe by default:
  • Trust a token’s registrar to verify and receive it — set CANTON_AGENT_REGISTRY_TRUSTED_PARTIES (USDCx’s registrar is trusted out of the box). An untrusted registrar’s incoming transfers are skipped by claim.
  • Consent to spend a token — set CANTON_AGENT_PAYABLE_INSTRUMENTS="<registrar>|USDCx". The default is Canton Coin only, so a merchant cannot make you pay in a token you did not opt into.
--admin/--id always travel together. pay needs no --admin/--id — the instrument comes from the merchant’s 402 challenge; you only opt in to spending it.

Export / Import

Back up and restore the wallet key:

Environment Variables

CANTON_AGENT_NETWORK defaults to canton:testnet. Always set it to canton:mainnet when connecting to mainnet.

SDK Usage

For programmatic use (e.g. embedding payments in a backend service):

Wallet File

The wallet is stored at ~/.canton-agent/wallet.json with permissions 0600. It contains the Ed25519 private key and the allocated Canton party ID. Back it up; losing the file loses access to the funds it holds.

How Payment Works

Payment settles in a single transaction. When the agent pays an x402-gated URL it signs — but does not submit — a TransferFactory_Transfer (CIP-56 Token Standard transfer instruction) naming the merchant as receiver:
  1. POST /v2/interactive-submission/prepare → gets preparedTransactionHash
  2. Agent signs the hash with its Ed25519 key (does not execute/submit)
  3. Retries the original request with PAYMENT-SIGNATURE: <base64 PaymentPayload> carrying the payer-signed transfer inline (the prepared transaction plus the signature)
The merchant’s server then calls the facilitator’s /verify and /settle. The facilitator relays the payer-signed transfer — it submits the transaction and pays the sequencer traffic fee. Because the merchant holds a live TransferPreapproval, the transfer resolves directly and moves CC from the payer’s own holdings to the merchant in one transaction. The agent never pays gas; the facilitator never holds custody and signs nothing on the payer’s behalf.

First-Request Latency

The first payment after a cold start is slower than subsequent ones. SV Scan caches AmuletRules (5 min TTL) and OpenMiningRound (30 s TTL); these caches are empty on startup, so the first request warms them. Subsequent payments typically complete in 10 to 25 seconds on Canton mainnet.