Skip to main content

Try it now in Val Town

Interactive playground to test Triton API calls
Click “Remix” to fork the playground, add your PAYER_KEYPAIR as an environment secret, and run live API calls.

Setup

Set up your payment handler in just 3 lines:
import { payer } from "@faremeter/rides";

const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");

await payer.addLocalWallet(PAYER_KEYPAIR);
@faremeter/rides automatically detects your network, looks up USDC, and sets up payments using your existing wallet. All examples below use payer.fetch().

Example 1: getBalance

Query account balance through the proxy:
const url = "https://triton.api.corbits.dev";
const payload = {
  jsonrpc: "2.0",
  id: 1,
  method: "getBalance",
  params: ["corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"]
};

const response = await payer.fetch(url, {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});

if (!response.ok) {
  const text = await response.text().catch(() => "");
  throw new Error(`HTTP ${response.status} ${response.statusText} ${text}`);
}

const data = await response.json();
console.log("Balance:", data.result.value / 1e9, "SOL");
Response:
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "context": {
      "slot": 123456789
    },
    "value": 1000000000
  }
}

Example 2: getBlockHeight

Get current block height:
const url = "https://triton.api.corbits.dev";
const payload = {
  jsonrpc: "2.0",
  id: 1,
  method: "getBlockHeight"
};

const response = await payer.fetch(url, {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});

if (!response.ok) {
  const text = await response.text().catch(() => "");
  throw new Error(`HTTP ${response.status} ${response.statusText} ${text}`);
}

const data = await response.json();
console.log("Latest Block Height:", data.result);
Response:
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": 298765432
}

Payment Flow

When you make a request, the following happens automatically:
  1. Initial Request: Client sends RPC request
  2. 402 Response: Proxy returns payment requirements
{
  "accepts": [{
    "network": "solana-mainnet-beta",
    "maxAmountRequired": 10000,
    "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "payTo": "corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"
  }]
}
  1. Payment: Payment handler processes USDC transfer (0.01 USDC)
  2. Success: Proxy fulfills original request with 200 OK
All of this is handled automatically by payer.fetch() or fetchWithPayer!

External Resources