JSON-RPC

Use JSON-RPC for account reads, block data, transaction submission, and cluster status.

Before you start

You need a cubestech project with an active node.

  1. Create a project

    Sign in to the dashboard. Create a project and add a Solana node.

  2. Copy the key

    Open the node page. Copy its API key and store the value in NODE_API_KEY.

  3. Send a request

    Call the RPC endpoint with the key in the x-api-key header.

bash
export NODE_API_KEY="YOUR_API_KEY"

curl https://api.mainnet-beta.solana.com \
  -H "Content-Type: application/json" \
  -H "x-api-key: $NODE_API_KEY" \
  -d '{"jsonrpc":"2.0","id":"quickstart","method":"getHealth"}'

A healthy node returns:

json
{
  "jsonrpc": "2.0",
  "result": "ok",
  "id": "quickstart"
}

Read the current slot

javascript
const response = await fetch("https://api.mainnet-beta.solana.com", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": process.env.NODE_API_KEY,
  },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: "slot",
    method: "getSlot",
    params: [{ commitment: "confirmed" }],
  }),
})

const body = await response.json()
if (!response.ok || body.error) {
  throw new Error(body.error?.message ?? `HTTP ${response.status}`)
}

console.log(body.result)

Production checklist

  • Set a request timeout.
  • Retry 429, 500, and 503 responses with backoff.
  • Do not retry invalid parameters.
  • Keep your key on the server.
  • Log the JSON-RPC request ID with each error.