Quickstart
Create an API key and make an authenticated Mainnet RPC request.
Create an API key
Sign in, open a project, and create a key from its Solana page. The key is shown once, so store it in a secret manager or environment variable.
export OPENINFRA_API_KEY=sk_live_xxxxxxxxxxxxMake your first request
Fetch the current slot using
getSlot:import { Connection } from "@solana/web3.js"; const conn = new Connection("https://rpc.sol.openinfra.sh", { commitment: "confirmed", httpHeaders: { "x-api-key": process.env.OPENINFRA_API_KEY! },}); console.log("Current slot:", await conn.getSlot());Expected JSON-RPC response shape:
{ "jsonrpc": "2.0", "result": 312445981, "id": 1 }Subscribe over WebSockets
Connect to the separate WebSocket endpoint and authenticate with either the
x-api-keyupgrade header or the verifiedapi-keyquery parameter:const key = process.env.OPENINFRA_API_KEY;const ws = new WebSocket("wss://ws.sol.openinfra.sh?api-key=" + encodeURIComponent(key)); ws.onopen = () => { ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "slotSubscribe", }));}; ws.onmessage = (event) => { const message = JSON.parse(event.data); console.log(message);};Choose a streaming API
Use Yellowstone gRPC for filterable Solana account and transaction updates, or Datastream and Eventstream for OpenInfra topic streams.