Skip to main content

Call the API

1

Install

npm install @faremeter/payment-solana @faremeter/fetch @faremeter/info @solana/web3.js
2

Call with payment

import { wrap } from "@faremeter/fetch";
import { createPaymentHandler } from "@faremeter/payment-solana/exact";

// Setup payment handler with your wallet
const fetchWithPayer = wrap(fetch, {
  handlers: [createPaymentHandler(wallet, usdcMint, connection)]
});

// Call the API - payment happens automatically
const response = await fetchWithPayer("https://helius.api.corbits.dev", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getBlockHeight",
  }),
});
3

Get result

{
  "jsonrpc": "2.0",
  "result": 348510722,
  "id": 1
}

Next steps

Now that you have made your first x402 request, it’s time to explore what else is possible:
Need help? Speak with our team or join our community.