Created
October 20, 2025 17:55
-
-
Save mgild/35a16ec913e079c6416d6818182b3c8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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