Skip to content

Examples

Real uses, ready to copy

Five patterns for selling and buying with Vault402 on Robinhood Chain. Each one runs as written once your tokens and wallets are set.

01

Sell Premium Data

You have proprietary market data. Charge 0.50 USDC per request, paid gaslessly by the agent.

server.ts
import express from 'express';
import { requirePayment, defineToken } from 'vault402';

const USDC = defineToken({
  symbol: 'USDC', address: process.env.USDC_ADDRESS, decimals: 6,
  eip3009: { name: 'USD Coin', version: '2' },
});

const app = express();

app.get('/api/market-data',
  requirePayment({
    network: 'robinhood',
    payTo: process.env.TREASURY,
    price: { token: USDC, amount: '0.50' },
    settlementKey: process.env.SETTLER_KEY,
  }),
  (req, res) => res.json({ eth: 3200, timestamp: Date.now() })
);

app.listen(3000);

02

Agent Buys Data Autonomously

Your agent needs weather data to make decisions. It pays automatically, but never more than its budget allows.

agent.ts
import { createAgentClient, ETH } from 'vault402';

const agent = createAgentClient({
  account: process.env.AGENT_PRIVATE_KEY,
  network: 'robinhood',
  budget: [
    { token: USDC, maxPerPayment: '1', maxTotal: '25' },
    { token: ETH,  maxPerPayment: '0.0005' },
  ],
});

const res = await agent.fetch('https://api.weatheragent.ai/forecast');
const weather = await res.json();

03

Passes and Prepaid Credits

Sell a one-hour pass to a data feed, or a bundle of 100 calls, with a single payment. The agent client reuses the access token automatically.

server.ts
// One payment = unlimited calls for an hour
app.get('/api/feed',
  requirePayment({
    network: 'robinhood', payTo: TREASURY,
    price: { token: USDC, amount: '5' },
    access: { type: 'pass', durationSeconds: 3600 },
  }),
  feedHandler
);

// One payment = 100 calls
app.post('/api/inference',
  requirePayment({
    network: 'robinhood', payTo: TREASURY,
    price: { token: USDC, amount: '2' },
    access: { type: 'credits', credits: 100 },
  }),
  inferenceHandler
);

04

Multiple Tokens, Including Stock Tokens

List several prices and let the agent pay in whichever token its budget allows: a stablecoin, ETH, or a Robinhood Stock Token.

server.ts
import { requirePayment, defineToken, ETH } from 'vault402';

const TSLA = defineToken({
  symbol: 'TSLA', address: process.env.TSLA_TOKEN, decimals: 18,
});

app.get('/api/research',
  requirePayment({
    network: 'robinhood',
    payTo: TREASURY,
    price: [
      { token: USDC, amount: '10' },
      { token: ETH,  amount: '0.003' },
      { token: TSLA, amount: '0.04' },
    ],
  }),
  researchHandler
);

05

Test on Robinhood Chain Testnet

Use testnet (chain ID 46630) with faucet ETH before going live. Change only the network value.

server.ts
import { requirePayment, ETH } from 'vault402';

app.get('/api/demo',
  requirePayment({
    network: 'robinhood-testnet',
    payTo: process.env.TREASURY,
    price: { token: ETH, amount: '0.0001' },
  }),
  (req, res) => res.json({ ok: true, paidBy: req.vault402?.payer })
);

What happens inside agent.fetch()

  1. 01The server responds 402 with a paymentId and the accepted tokens.
  2. 02The client picks the first offer that fits the budget, preferring gasless EIP-3009.
  3. 03It pays on Robinhood Chain: a transfer carrying the paymentId, or a signed authorization.
  4. 04It retries the request with an X-PAYMENT header.
  5. 05The server verifies, marks the paymentId as used, and returns the data plus a receipt.