Skip to content

Instantly share code, notes, and snippets.

@mgild
Created October 20, 2025 17:55
Show Gist options
  • Save mgild/35a16ec913e079c6416d6818182b3c8b to your computer and use it in GitHub Desktop.
Save mgild/35a16ec913e079c6416d6818182b3c8b to your computer and use it in GitHub Desktop.
import { wrap as wrapFetch } from "@faremeter/fetch";
import { Keypair, PublicKey, Connection } from "@solana/web3.js";
import { createLocalWallet } from "@faremeter/wallet-solana";
import { exact } from "@faremeter/payment-solana";
import * as fs from "fs";
(async function main() {
const keypair = Keypair.fromSecretKey(
Uint8Array.from(JSON.parse(fs.readFileSync(process.env.SOL_KEY_PATH!, "utf-8"))),
);
const connection = new Connection(process.env.RPC_URL!);
// Create wallet from keypair
const wallet = await createLocalWallet("solana", keypair);
// USDC mint address on Solana mainnet
const mint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const fetchWithPayer = wrapFetch(fetch, {
handlers: [exact.createPaymentHandler(wallet, mint, connection
)]
});
const paywalledRpcUrl = "https://helius.api.corbits.dev";
const response = await fetchWithPayer(paywalledRpcUrl, {
method: "POST",
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "getBlockHeight" })
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment