// Expected response from Corbits Triton Val Town examplebigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)Balance of 5wjYK7BSesmte2HVpKHQYbAgdgd7Rw27ejW9UZjcCWc2 is 1020020 lamports!
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 environmentconst { PAYER_KEYPAIR } = process.env;if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");const network = "mainnet-beta";// Lookup USDC automaticallyconst 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)],});// Make a paid API requestconst url = "https://helius.api.corbits.dev";const payload = { jsonrpc: "2.0", id: 1, method: "getBlockHeight",};const response = await fetchWithPayer(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);
Copy
// Expected response from Corbits Triton Val Town examplebigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)Balance of 5wjYK7BSesmte2HVpKHQYbAgdgd7Rw27ejW9UZjcCWc2 is 1020020 lamports!