Getting Started with Solana JSON-RPC API: A Complete Beginner’s Guide

How do wallet apps show your balance? How do blockchain explorers like Solscan display transaction details? How does any application, for that matter, pull live data from the Solana network? The answer to all these questions is the same: they all “talk” to the blockchain using its native language, the JSON-RPC API.
For a beginner, the term “API” can sound intimidating, but the concept is surprisingly simple. Think of the Solana network as a massive, public database and the API as its public “menu” of commands. You can ask it questions like “What’s the balance of this wallet?” or “Show me the details of this transaction,” and it will answer you in a clean, predictable format.
This guide will demystify that process. We’re not going to build a complex application. We’re going to learn the fundamental language of Solana communication. You will learn what an RPC endpoint is, how to structure a request from scratch, and how to make your first live API calls to get real data from the blockchain using a simple command-line tool.
Part 1: The Fundamentals – What Are You Connecting To?
Before we make a request, we need to know where to send it.
What is an RPC Node and an Endpoint? Imagine the Solana blockchain is a giant, decentralized library with identical copies of every book (the ledger) in many different branches around the world. An RPC Node is like one of these library branches. It’s a computer running the Solana software that holds a full copy of the blockchain’s history.
The RPC Endpoint is simply the public address (the URL) of that library branch. It’s the address we send our questions (API calls) to.
Public vs. Dedicated Endpoints
- Public Endpoints: These are free, publicly available addresses (like
api.mainnet-beta.solana.com
). They are perfect for learning and light development but are shared by thousands of people. This means they are often slow and have strict rate limits (if you ask too many questions too quickly, they’ll temporarily block you). - Dedicated Endpoints: These are private, high-performance endpoints provided by services like Helius, QuickNode, or Triton. When you build a real application, you’ll need a dedicated endpoint to ensure your users get a fast and reliable experience.
For this guide, we’ll use Solana’s public Devnet endpoint so you can get started without signing up for anything.
Part 2: Anatomy of a JSON-RPC Request
“JSON-RPC” sounds complex, but it just means we are sending a Remote Procedure Call (a command to a remote server) formatted in JavaScript Object Notation (JSON).
Let’s look at a complete request made with curl
, a simple command-line tool for making web requests.
curl https://api.devnet.solana.com \ -X POST \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "getBalance", "params": [ "So11111111111111111111111111111111111111112" ] }'
Let’s break down the JSON data payload (-d
):
"jsonrpc": "2.0"
: This is the protocol version. You always include this."id": 1
: This is a request ID that you set. When the server replies, it will include the same ID so you can match your request to its response."method": "getBalance"
: This is the important part—the specific command from the “menu” you want to run. In this case, we’re asking for a wallet’s balance."params": [...]
: This is a list of arguments (parameters) that the method needs. ThegetBalance
method needs just one parameter: the public key (address) of the wallet you want to check.
Part 3: Your First Live API Calls – Practical Examples
Open your terminal and try these commands yourself!
Example 1: Get the SOL Balance of a Wallet
This is the “Hello, World!” of the Solana API. We’ll ask for the balance of the official Solana “System Program” address on the Devnet.
Request:
curl https://api.devnet.solana.com \ -X POST \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "getBalance", "params": [ "So11111111111111111111111111111111111111112" ] }'
Response:
{ "jsonrpc": "2.0", "result": { "context": { "apiVersion": "1.18.15", "slot": 286823351 }, "value": 130386866930 }, "id": 1 }
Understanding the Response: The value
is the balance in lamports, the smallest unit of SOL. There are 1,000,000,000 lamports in 1 SOL. So, this account has roughly 130.38 SOL.
Example 2: Get Details of a Transaction
Let’s look up a specific transaction on the Mainnet this time.
Request:
curl https://api.mainnet-beta.solana.com \ -X POST \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "getTransaction", "params": [ "2n1bK2t4iEURG24L5s2k4V9Pz2B1m6n2aV9aY3c3v1bK8eY2n2V7m6n2aV9aY3c3v1bK8eY2n2", "json" ] }'
(Note: Replace the signature with a recent one from an explorer like Solscan).
Response: You’ll get a huge JSON object containing everything about that transaction: who signed it, which accounts were involved, how much SOL was moved, and any log messages from the programs it interacted with.
Example 3: Get Information about an SPL Token Balance
You don’t just have to check SOL balances. Let’s check the balance of a specific USDC token account.
Request:
curl https://api.mainnet-beta.solana.com \ -X POST \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "getTokenAccountBalance", "params": [ "FzbfvK8Yd3t2Y9sApS29Y1T1gWc6P2dYc8Z3zX1nB8a" ] }'
Response:
{ "jsonrpc": "2.0", "result": { "context": { ... }, "value": { "amount": "15000000", "decimals": 6, "uiAmount": 15.0, "uiAmountString": "15" } }, "id": 1 }
Understanding the Response: The API helpfully gives you the raw amount
(15,000,000) and the number of decimals
(6 for USDC), as well as the human-readable uiAmount
(15.0).
Part 4: Common Pitfalls and Best Practices
- Rate Limiting: If you start getting errors or empty responses, you’ve likely been rate-limited by the public node. This is the #1 sign you need a dedicated endpoint for your project.
- Commitment Levels: You can add a configuration object to your
params
to specify a “commitment level.”processed
: Fast but might be rolled back.confirmed
: Voted on by a supermajority, less likely to be rolled back.finalized
: Cemented in the blockchain, cannot be rolled back. For fetching data,finalized
is the safest.
- WebSockets for Real-Time Data: The JSON-RPC API is great for fetching historical data. If you want to listen for new events in real-time (like when an account’s balance changes), you’ll need to use the WebSocket (
wss://
) endpoint, which is a slightly more advanced topic.
Conclusion: Your Gateway to On-Chain Data
You now understand the fundamental communication layer of the Solana network. The JSON-RPC API is your gateway to an ocean of on-chain data. You can build market analytics tools, wallet trackers, NFT dashboards, or simply satisfy your own curiosity about how the blockchain works under the hood.
From here, your next steps are to:
- Explore the full Solana JSON-RPC API documentation to see the entire “menu” of available methods.
- Try making these requests in your favorite programming language (e.g., using
axios
in JavaScript orrequests
in Python). - Think of a simple question you have about on-chain activity, and try to answer it using the API.
You no longer need to rely on third-party websites to interpret the blockchain for you. You can now talk to it directly.