Blockchain APIs are not a single product category. They span raw JSON-RPC node access, indexed data services, and higher-level REST or GraphQL gateways, each with different consistency and latency characteristics. This article explains the mental model behind each layer, shows runnable curl and Python examples for querying and verifying responses, and provides a diagnostic procedure for common failures. It also covers how to measure performance yourself rather than relying on vendor claims, and when to move from shared endpoints to dedicated infrastructure.
Direct answer and scope
A blockchain API is any programmatic interface that lets an application read from or write to a blockchain network without running its own node. The term covers at least three distinct layers: raw JSON-RPC endpoints that expose node methods, indexed data APIs that pre-process chain state into queryable schemas, and gateway APIs that wrap common operations such as token balances or transaction submission.
This article focuses on how these layers differ, how to integrate them correctly, and how to verify that what you receive is accurate and current. It does not recommend a specific provider for every network; for concrete endpoint and provider choices, use the RPC Assistant or browse supported networks.
- Raw JSON-RPC: closest to the node, standard methods, you handle decoding and indexing.
- Indexed data APIs: pre-processed tables, faster for historical queries, but with indexing lag.
- Gateway APIs: simplified REST or GraphQL surfaces, convenient but less transparent about freshness.
Prerequisites and assumptions
The examples assume you have an RPC endpoint URL for an EVM-compatible chain and, optionally, an API key for an indexed data service. Replace RPC_URL and API_KEY with your own values. No public endpoint is hard-coded because public endpoints often rate-limit or change without notice.
You should be comfortable with HTTP requests, JSON, and basic command-line tools. Python examples use only the standard library so they run without installing packages. If you are new to node access, start with the RPC endpoints guide before continuing.
Mental model: three layers of blockchain access
Think of blockchain access as a stack. At the bottom, a node maintains the canonical chain state and exposes JSON-RPC methods such as eth_blockNumber, eth_getBalance, and eth_getLogs. This layer is authoritative but raw: you must know which block to query and how to decode results.
Above that, indexers consume blocks and write derived data into databases. An indexed API might answer "all transfers of token X in the last 24 hours" in one request, whereas raw RPC would require scanning logs across many blocks. The tradeoff is indexing lag: the indexed view may trail the chain head by seconds or minutes.
At the top, gateway APIs combine multiple sources behind a simplified interface. They are convenient for prototypes but can obscure which block height a response reflects. For financial or compliance use cases, always confirm the block context of any response.
Runnable JSON-RPC request and response verification
The following curl command queries the latest block number and then the balance of an address at that block. Run it in a terminal and compare the returned block number with a block explorer.
A correct response contains a result field with a hexadecimal block number. If you receive an error object instead, check the endpoint URL, authentication headers, and method name.
curl -s -X POST "$RPC_URL" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}'
# Then query balance at that block (replace BLOCK_HEX and ADDRESS)
curl -s -X POST "$RPC_URL" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":2,"method":"eth_getBalance","params":["ADDRESS","BLOCK_HEX"]}'Python client with block-pinned queries
Pinning queries to a specific block height makes results reproducible. The script below fetches the latest block, then requests the balance at that exact block. It also prints the block number so you can verify against an explorer.
This pattern is essential for testing and for any workflow where consistency matters. If you query "latest" twice, you may get different blocks and therefore different balances.
import json, urllib.request, os
RPC_URL = os.environ["RPC_URL"]
ADDRESS = "0x0000000000000000000000000000000000000000"
def rpc(method, params):
payload = json.dumps({"jsonrpc":"2.0","id":1,"method":method,"params":params}).encode()
req = urllib.request.Request(RPC_URL, data=payload, headers={"Content-Type":"application/json"})
with urllib.request.urlopen(req, timeout=10) as resp:
body = json.loads(resp.read())
if "error" in body:
raise RuntimeError(body["error"])
return body["result"]
block_hex = rpc("eth_blockNumber", [])
balance_hex = rpc("eth_getBalance", [ADDRESS, block_hex])
print("block:", int(block_hex, 16))
print("balance wei:", int(balance_hex, 16))Indexed data API request pattern
Indexed APIs typically use REST or GraphQL. The example below uses a generic REST pattern with placeholders. The key verification step is to check whether the response includes a block height or timestamp, and whether that height is close to the chain head.
If the response lacks block context, treat it as a convenience view rather than an authoritative record. For settlement or accounting, cross-check against raw RPC at a known block.
curl -s "https://INDEXER_API_URL/v1/transfers?address=ADDRESS&limit=10" \
-H "Authorization: Bearer $API_KEY"
# Inspect the response for a block number or timestamp field.
# Compare that height with eth_blockNumber from your RPC endpoint.Measurement procedure and results table
Vendor latency claims are difficult to compare because they depend on your location, request type, and payload size. Measure from your own environment. Run at least 100 sequential requests for each method and record the median and 95th percentile latency. Also record the block height returned at the start and end of the run to detect lag.
Use a table like the one below to record your results. Do not fill in numbers from this article; these are placeholders for your own measurements.
| Endpoint | Method | Median latency (ms) | p95 latency (ms) | Block lag (blocks) |
|---|---|---|---|---|
| RPC_URL_A | eth_blockNumber | |||
| RPC_URL_A | eth_getBalance | |||
| RPC_URL_B | eth_blockNumber | |||
| Indexer | transfers query |
Run the measurement at the same time of day across endpoints to reduce diurnal bias. If you need dedicated capacity for consistent results, review dedicated node options and RPC pricing.
Troubleshooting common integration failures
Most blockchain API failures fall into a few categories: authentication, rate limiting, malformed parameters, and stale data. The diagnostic order below moves from cheapest to most expensive checks.
If you receive HTTP 401 or 403, verify the API key and header format. If you receive HTTP 429, you have hit a rate limit; back off with exponential jitter and consider a higher tier or dedicated endpoint. If you receive a JSON-RPC error with code -32602, your parameters are invalid; check address checksums and block tags. If responses are valid but stale, compare the returned block height with a public explorer.
- Check HTTP status before parsing JSON.
- Log the JSON-RPC error code and message, not just the exception.
- Pin queries to a block height when consistency matters.
- Compare indexed data against raw RPC at the same height.
Limitations and tradeoffs
Raw RPC gives you authority and flexibility but shifts indexing and decoding work to your application. Indexed APIs reduce query complexity but introduce lag and vendor-specific schemas. Gateway APIs are fastest to integrate but least transparent about data provenance.
No single layer is correct for every use case. A wallet might use raw RPC for balance checks and an indexer for transaction history. A trading system might require dedicated nodes to control latency. Document which layer each feature depends on so you can reason about failure modes.
Next steps
Start by pinning one critical query to a block height and verifying it against an explorer. Then add a second endpoint and run the measurement procedure above. If you need help selecting an endpoint for a specific network, consult the RPC Assistant. For broader infrastructure planning, read the blockchain node hosting guide and the multi-chain RPC endpoints guide.