Creating a Wallet
Using Solana CLI
Install Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
Create a New Wallet
# Create a new wallet
solana-keygen new --outfile client-wallet.json
# Get the public address
solana address -k client-wallet.json
Secure Your Wallet
Store client-wallet.json securely and never commit it to version control.Add it to your .gitignore:client-wallet.json
*.json
 Using an Existing Wallet
If you already have a Solana wallet (Phantom, Solflare, etc.):
- Export your private key from your wallet application
- Convert it to the keypair JSON format required by the payment libraries
- Save it as client-wallet.json
Never share your private key or keypair file. Anyone with access can control your funds.
Funding Your Wallet
Your wallet needs two types of tokens on Solana mainnet:
- SOL - For transaction fees (~0.000005 SOL per transaction)
- USDC - For paying API requests (0.01 USDC per request, 0.001 USDC for Nansen)
Acquiring SOL
Purchase SOL
Buy SOL from a cryptocurrency exchange (Coinbase, Binance, Kraken, etc.)
Transfer to Wallet
Withdraw SOL to your wallet address on Solana mainnetRecommended amount: 0.05-0.1 SOL for transaction fees
Verify Balance
solana balance -k client-wallet.json
Acquiring USDC
Purchase USDC
Buy USDC on Solana from:
- Cryptocurrency exchanges like Coinbase, Kraken, or Binance (ensure it’s Solana USDC, not Ethereum USDC)
- DEXs like Jupiter or Raydium (swap SOL for USDC)
- Cross-chain bridges (if you have USDC on other chains)
 Transfer to Wallet
Send USDC to your wallet address on Solana mainnetUSDC Mint Address: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vAmount depends on your usage:
- 1 USDC = 1,000 API requests
- 10 USDC = 10,000 API requests
- 100 USDC = 100,000 API requests
 Verify Balance
spl-token balance EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v -k client-wallet.json
Start Small: Begin with 1-10 USDC to test the system before funding larger amounts.
Install Dependencies
Install the required packages in your project:
pnpm add @solana/web3.js @faremeter/fetch @faremeter/payment-solana @faremeter/wallet-solana @faremeter/info
Set PAYER_KEYPAIR
Create a .env file in your project root:
PAYER_KEYPAIR=[123,45,67,...]
// Using dotenv
import 'dotenv/config';
// Or with explicit loading
import { config } from 'dotenv';
config();
// Access the keypair
const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");
Security Best Practices
- Never commit .envfiles to version control
- Add .envto your.gitignore
- Never expose keypairs in logs or error messages
- Use different wallets for development and production
.gitignore:
.env
.env.*
*.json
client-wallet.json
Making Your First API Call
Here’s a complete example calling Helius RPC on mainnet:
import {
  clusterApiUrl,
  Connection,
  Keypair,
  PublicKey,
} from "@solana/web3.js";
import { createLocalWallet } from "@faremeter/wallet-solana";
import { lookupKnownSPLToken } from "@faremeter/info/solana";
import {
  createPaymentHandler,
  lookupX402Network,
} from "@faremeter/payment-solana/exact";
import { wrap as wrapFetch } from "@faremeter/fetch";
// Load keypair from environment
const PAYER_KEYPAIR = process.env.PAYER_KEYPAIR;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");
const keypair = Keypair.fromSecretKey(
  Uint8Array.from(JSON.parse(PAYER_KEYPAIR)),
);
// Setup for mainnet
const network = "mainnet-beta";
const x402Network = lookupX402Network(network);
// Lookup USDC mint address automatically
const usdcInfo = lookupKnownSPLToken(network, "USDC");
if (!usdcInfo) throw new Error("Could not find USDC mint");
// Create connection and payment handler
const connection = new Connection(clusterApiUrl(network));
const mint = new PublicKey(usdcInfo.address);
const wallet = await createLocalWallet(x402Network, keypair);
const fetchWithPayer = wrapFetch(fetch, {
  handlers: [createPaymentHandler(wallet, mint, connection)],
});
// Make API call
const 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);
Key Helper Functions
lookupKnownSPLToken
Instead of hardcoding mint addresses, use the info package:
import { lookupKnownSPLToken } from "@faremeter/info/solana";
const usdcInfo = lookupKnownSPLToken("mainnet-beta", "USDC");
// Returns: { address: "EPjF...", cluster: "mainnet-beta", name: "USDC", toUnit: fn }
const mint = new PublicKey(usdcInfo.address);
lookupX402Network
Maps Solana network names to x402 protocol format:
import { lookupX402Network } from "@faremeter/payment-solana/exact";
const x402Network = lookupX402Network("mainnet-beta");
// Returns: "solana-mainnet-beta"
Next Steps