Query API Quickstart

This quickstart shows how to make a first Query API request over HTTPS using JSON-RPC 2.0.

Prerequisites

Before you start, make sure you have:

  • A W3api project with Advanced API access.
  • A project API key copied from the W3api platform.
  • A terminal with curl.

Keep your API key private. Do not commit it to source control or expose it in frontend code.


Set Your Endpoint

Query API requests use the Advanced API multichain endpoint:

$https://rpc.ankr.com/multichain/<apiKey>

Replace <apiKey> with your project API key. In the examples below, store the full URL as YOUR_ADVANCED_API_ENDPOINT.


Make a Request with curl

Use ankr_getBlocks to request indexed block data for a block range:

$curl -X POST YOUR_ADVANCED_API_ENDPOINT \
> -H "Content-Type: application/json" \
> -d '{
> "jsonrpc": "2.0",
> "method": "ankr_getBlocks",
> "params": {
> "blockchain": "eth",
> "fromBlock": 19000000,
> "toBlock": 19000010
> },
> "id": 1
> }'

A successful response returns a JSON-RPC result object with indexed block data for the requested range:

1{
2 "jsonrpc": "2.0",
3 "id": 1,
4 "result": {
5 "blocks": [
6 {
7 "blockchain": "eth",
8 "number": "0x121eac0",
9 "hash": "0x9f1b8b76b0f5d8f6e0a2b9c8f4a3b7d6e5c4a1f8b2d9c7e6f5a4b3c2d1e0f9a8",
10 "parentHash": "0x4d5c6b7a8f9e0d1c2b3a4958675645342312f0e9d8c7b6a5f4e3d2c1b0a99887",
11 "timestamp": "0x659bf2a8",
12 "transactions": []
13 }
14 ]
15 }
16}