Hosted payment example
One governed payment against a hosted Veyto sandbox — agent, guardrails, a real Base Sepolia settlement, a signed receipt, and a deliberate Blocked.
It boots no Veyto backend. Veyto is a URL.
npm install
export VEYTO_API_URL=https://sandbox.veyto.io
export VEYTO_API_KEY=… # your Veyto sandbox key
export VEYTO_PAYER_PRIVATE_KEY=0x… # a THROWAWAY Base Sepolia key, funded with test USDC
npm run payFund the key at faucet.circle.com (choose Base Sepolia). You do not need ETH — the facilitator submits the transaction and pays the gas. You sign.
⚠️ Use a throwaway key. Your key stays in this process and Veyto never receives it, but there is no reason to point a key with real value at a testnet demo.
Dependencies
@veyto/sdk and viem are what an integration needs. express is only for the little
x402 test merchant in merchant.mjs — in real use you pay somebody else's endpoint and
you do not need it.
What it proves
- your API key authenticates against the hosted API;
- an agent is created and given guardrails;
payingFetchruns the whole flow;- Veyto returns unsigned EIP-3009 material and your process signs it;
- USDC moves from your address on Base Sepolia;
- a signed receipt comes back carrying its
policy_digest; - a second payment is Blocked by the daily cap, with no money moved.
Options
| variable | default |
|---|---|
VEYTO_PAYEE_ADDRESS | a fresh throwaway address |
VEYTO_FACILITATOR_URL | https://x402.org/facilitator |
VEYTO_RPC_URL | https://sepolia.base.org |
VEYTO_AMOUNT_MINOR | 10000 ($0.01) |
VEYTO_MERCHANT_PORT | 4081 |
If your deployment sits behind an edge gateway that authenticates callers, set
CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET; with a public edge they are unused.
The source
| file | what it is |
|---|---|
| pay.mjs | the example itself — agent, guardrails, payment, Blocked, receipt |
| merchant.mjs | a throwaway x402 endpoint to pay, so the example needs nobody else |
| package.json | the three dependencies |
Save the three into a directory and run them exactly as above.