You want to read data from Solana. This guide gets you there in 5 minutes.
What you'll build: A script that queries a wallet balance from Solana mainnet using FluxRPC.
TL;DR
TypeScript:
import { Connection, PublicKey, LAMPORTS_PER_SOL } from '@solana/web3.js';
const connection = new Connection('https://eu.fluxrpc.com?key=YOUR_API_KEY', 'confirmed');
const balance = await connection.getBalance(new PublicKey('YOUR_WALLET_ADDRESS'));
console.log(balance / LAMPORTS_PER_SOL, 'SOL');
cURL:
curl -s -X POST https://eu.fluxrpc.com?key=YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["YOUR_WALLET_ADDRESS"]}' | jq
Output:
{
"jsonrpc": "2.0",
"result": {
"context": { "slot": 123456789 },
"value": 35737443
},
"id": 1
}
Get your API key → dashboard.fluxbeam.xyz
Prerequisites
- Node.js 18+
- FluxRPC API key (free, takes 30 seconds)
Step 1 — Get Your API Key
- Go to dashboard.fluxbeam.xyz
- Sign in (Google, GitHub, or Solana wallet)
- Click Create API Key
- Copy the key
Step 2 — Create Project
mkdir fluxrpc-quickstart && cd fluxrpc-quickstart
npm init -y
npm install @solana/web3.js tsx
Step 3 — Write the Code
Create index.ts:
import { Connection, PublicKey, LAMPORTS_PER_SOL } from '@solana/web3.js';
const API_KEY: string = 'your-api-key-here';
const RPC_URL: string = `https://eu.fluxrpc.com?key=${API_KEY}`;
const WALLET: string = 'YOUR_WALLET_ADDRESS';
async function main(): Promise<void> {
const connection = new Connection(RPC_URL, 'confirmed');
const publicKey = new PublicKey(WALLET);
const start: number = Date.now();
const lamports: number = await connection.getBalance(publicKey);
const ms: number = Date.now() - start;
console.log(`Wallet: ${WALLET}`);
console.log(`Balance: ${lamports / LAMPORTS_PER_SOL} SOL`);
console.log(`Latency: ${ms}ms`);
}
main();
Replace your-api-key-here with your API key.
Step 4 — Run
npx tsx index.ts
Output:
Wallet: Wallet Address
Balance: 0.035737443 SOL
Latency: 142ms
You just read from Solana mainnet.
What Just Happened
Connection — Opens a connection to FluxRPC. The second param 'confirmed' is the commitment level (how finalized the data needs to be).
PublicKey — Parses the wallet address string into a format Solana understands.
getBalance — Returns the wallet balance in lamports. 1 SOL = 10^9 lamports.
This pattern repeats for all RPC calls: connect → query → handle response.
Why FluxRPC
Fresh Data
Most providers cache responses. FluxRPC returns HEAD slot data, the latest confirmed state. No stale reads.
No Rate Limits
Pay for bandwidth, not requests. $0.06 per GB. That getBalance call? About 0.5KB. 2 million calls = 6 cents.
Free tier: 10GB.
Built for Load
Consistent performance when Solana's congested. No slowdowns during high traffic.
Want Sub-Millisecond?
Lantern caches account state locally. Response times: 0.1–0.25ms. Throughput: 10k+ req/sec.
More Methods
getLatestBlockhash
Required before sending transactions.
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
console.log('Blockhash:', blockhash);
getAccountInfo
Returns account details, owner, balance, executable flag, data.
import type { AccountInfo } from '@solana/web3.js';
const account: AccountInfo<Uint8Array> | null = await connection.getAccountInfo(publicKey);
if (account) {
console.log('Owner:', account.owner.toBase58());
console.log('Lamports:', account.lamports);
console.log('Executable:', account.executable);
console.log('Data length:', account.data.length);
}
Reference
Endpoints
| Region | URL |
|---|---|
| EU | https://eu.fluxrpc.com?key=API_KEY |
| US | https://us.fluxrpc.com?key=API_KEY |
Choose the closest region. Wrong region adds ~100ms latency.
Commitment Levels
| Level | Meaning |
|---|---|
processed |
Node has seen it |
confirmed |
Supermajority voted |
finalized |
Won't be rolled back |
Common Errors
| Error | Fix |
|---|---|
Invalid public key input |
Check wallet address is valid base58 |
Failed to fetch |
Verify API key and endpoint URL |
403 Forbidden |
Regenerate API key from dashboard |
TypeError: fetch failed |
Upgrade to Node.js 18+ |
try {
const balance = await connection.getBalance(publicKey);
} catch (error) {
console.error('RPC error:', error);
}
Next Steps
- Transactions — Build and send SOL transfers
- WebSockets — Subscribe to account changes
Docs: fluxrpc.com
Top comments (0)