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().
Set up your payment handler with full control:import {
clusterApiUrl,
Connection,
Keypair,
PublicKey,
} from "@solana/web3.js";
import { createLocalWallet } from "@faremeter/wallet-solana";
import { lookupKnownSPLToken } from "@faremeter/info/solana";
import {
createPaymentHandler,
} from "@faremeter/payment-solana/exact";
import { wrap as wrapFetch } from "@faremeter/fetch";
// Load keypair from environment
const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");
const network = "mainnet-beta";
// Lookup USDC mint address automatically
const usdcInfo = lookupKnownSPLToken(network, "USDC");
if (!usdcInfo) throw new Error("Could not find USDC mint");
const keypair = Keypair.fromSecretKey(
Uint8Array.from(JSON.parse(PAYER_KEYPAIR)),
);
const connection = new Connection(clusterApiUrl(network));
const mint = new PublicKey(usdcInfo.address);
const wallet = await createLocalWallet(network, keypair);
const fetchWithPayer = wrapFetch(fetch, {
handlers: [createPaymentHandler(wallet, mint, connection)],
});
This approach gives you full control over wallet creation, network configuration, and payment handlers.
Required for browser apps and custom wallet integration.