RPC - communication protocol


What is RPC (Remote Procedure Call)? 🤖

RPC is a way for one computer (usually an client application) to ask another (like a blockchain node) to run a specific function — remotely.

⚡ TL;DR: How Computers Talk over the internet

🍽️ Imagine you're at a restaurant — here's how different protocols handle a pizza order, especially in terms of when things happen:

  • Protocol: REST
    You browse the menu and place an order:
    “GET me this pizza.”
    ⏱️ You wait, and the server brings the pizza in the same request-response cycle.

  • Protocol: RPC
    You walk into the kitchen and say:
    “Run make_pizza() with these ingredients.”
    ⏱️ The chef makes it and gives it back to you immediately in the same call.

  • Protocol: gRPC
    You hand over a tightly structured, binary order form:
    “Execute MakePizza() with encoded details.”
    ⏱️ Fast, efficient — ideal for internal kitchen-to-kitchen ops, not for casual diners.

  • Protocol: GraphQL
    You fill out a form:
    “I want a pizza margeritta with only a tomato base and crust.”
    ⏱️ You get exactly what you asked for — no more, no less — in a single response.

  • Protocol: WebSockets
    You sit in the kitchen and keep a channel open:
    “Let me know when the pizza is in the oven, done, or eaten.”
    ⏱️ The chef pushes updates to you in real time, whenever something happens — no need to ask again.

  • Protocol: Pub/Sub
    You leave a number at the counter:
    “Text me when the pizza is out of the oven.”
    ⏱️ You leave. When the event happens, the kitchen sends a notification — one-way, event-based.

📊 RPC vs REST at a glance

| Feature | RPC (Remote Procedure Call) | REST (Representational State Transfer) | |----------------|-----------------------------------------------|-----------------------------------------------| | Style | Action-based (“do this thing”) | Resource-based (“get this object”) | | Focus | Call methods/functions | Access and manipulate resources | | Common Use | Blockchain APIs (Solana, Ethereum), microservices | Web APIs (Twitter, GitHub, etc.) | | Example Call | eth_getBalance("0x123...") | GET /users/123/balance | | Transport | JSON over HTTP | JSON/XML over HTTP | | HTTP Method | Always POST | GET, POST, PUT, etc. | | Endpoint | Single endpoint (e.g. /) | Multiple endpoints (/users, /posts) | | Payload | method + params in JSON-RPC format | Resource-based JSON | | Routing | Based on method field in payload | Based on HTTP verb and URL |

🚀 So what is RPC in practice?

In the context of web3 (like Solana), RPC calls are just HTTP POST requests with a JSON-RPC formated payload.

You're not calling a URL like /getBalance — you're sending a JSON body that says:

"Hey, run the getBalance method with these parameters."

💻 Example: Get wallet balance using @solana/web3.js.

An client application would write say:

import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://api.mainnet-beta.solana.com");
const pubkey = new PublicKey("PublicKeyHere");
const balance = await connection.getBalance(pubkey);

Under the hood, @solana/web3.js is doing something like:

// REQUEST 
fetch("https://api.mainnet-beta.solana.com", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getBalance",
    params: ["0xabc123...", "latest"],
  })
});

And the RPC node responds with:

{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 23012345 },
    "value": 22000000
  },
  "id": 1
}

🧩 Conclusion

RPC is typically how a client application communicates with a blockchain — and JSON-RPC is simply the format used (based on REST) to structure those requests.

In Solana, these requests are sent to RPC nodes, which are special-purpose servers designed to handle API traffic. While validator nodes can expose an RPC interface, in real-world scenarios, RPC nodes are usually separated from main validation clusters. ➡️ One would not want public users overloading a validator node's CPU or memory, responsible for producing blocks and participating in the consensus process. Any performance degradation could directly impact the stability and security of the network. For most blockchains, running an RPC node typically means running a node that syncs with the network, but is not responsible for block production or consensus. In many cases, it's the same codebase as a full validator node, but configured differently — running in a separate cluster or setup, dedicated to serving API (RPC) traffic.

👉 Bottom line:

  • RPC defines what function to run
  • It's transported over HTTP POST
  • It's not resource-based like REST — it's function-first.

We hope that the above has provided you with some understanding of the RPC protocol. Communication is fun. Get out there, consolidate, investigate!