Query API
Query API is an Advanced API's collection of methods that comes as a unique feature along with other extensive capabilities provided to our Premium Plan users.
Query API is an access-ready solution that enables your projects to interact with multiple blockchains in a single request. By indexing blockchain data on all supported chains, searching through large amounts of data is easier and faster than ever before. Query API can boast almost instantaneous processing speeds (due to the key-value filtering supported) for the searches that might ordinarily take hours to process.
Query API serves to request info on the ranges of blocks (max range is 100) for a full list of block metadata.
Query API implements the JSON-RPC 2.0 specification (opens in a new tab) for interaction.
Query API Methods
Query API consists of the following methods to request info on the ranges of blocks (max range is 100) for a full list of block metadata:
ankr_getBlockchainStats
— retrieves blockchain statistics.ankr_getBlocks
— retrieves full info of a particular block.ankr_getLogs
— retrieves historical data for the specified range of blocks.ankr_getTransactionsByHash
— retrieves the details of a transaction specified by hash.ankr_getTransactionsByAddress
— retrieves the details of a transaction specified by address.ankr_getInteractions
— retrieves blockchains interacted with a particular wallet.
Prefer interactive docs? See our OpenAPI specification (opens in a new tab) for Query API methods.
ankr_getBlockchainStats
Retrieves blockchain statistics.
Request
Build your request using the parameters below.
Parameters
-
id
(int64; required): a request ID (example: 1). -
jsonrpc
(string; required): a JSON RPC spec used (example: 2.0). -
method
(string; required): a method used for the request. -
params
(object): the data object containing request body parameters:blockchain
(string): a chain or a combination of chains to query:- Single chain:
arbitrum
,avalanche
,base
,bsc
,eth
,fantom
,flare
,gnosis
,linea
,optimism
,polygon
,polygon_zkevm
,rollux
,scroll
,stellar
,syscoin
,telos
,xai
,xlayer
,avalanche_fuji
,base_sepolia
,eth_holesky
,eth_sepolia
,optimism_testnet
,polygon_amoy
. - Chains combination:
[arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, stellar, syscoin, telos, xai, xlayer, avalanche_fuji, base_sepolia, eth_holelsky, eth_sepolia, polygon_amoy]
. - All chains: leave the value empty to query all the chains available.
- Single chain:
{
"id": 1,
"jsonrpc": "2.0",
"method": "ankr_getBlockchainStats",
"params": {
"blockchain": "string"
}
}
Response
Returns statistics for the blockchains specified.
Code Examples
Request
curl --location --request POST 'https://rpc.ankr.com/multichain' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "ankr_getBlockchainStats",
"params": {},
"id": 1
}'
Response
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"stats": [
{
"blockchain": "eth",
"totalTransactionsCount": 2064546464,
"totalEventsCount": 3026535069,
"latestBlockNumber": 17927196,
"blockTimeMs": 12000,
"nativeCoinUsdPrice": "1822.653417893923688098"
},
{
"blockchain": "bsc",
"totalTransactionsCount": 4623925358,
"totalEventsCount": 14415335315,
"latestBlockNumber": 30902238,
"blockTimeMs": 3000,
"nativeCoinUsdPrice": "234.460486572761055868"
}
]
}
}
ankr_getBlocks
Retrieves the blocks' data.
Retrieves the details for the block range specified.
Request
Build your request using the parameters below.
Parameters
-
id
(int64; required): a request ID (example: 1). -
jsonrpc
(string; required): a JSON RPC spec used (example: 2.0). -
method
(string; required): a method used for the request. -
params
(object): the data object containing request body parameters:blockchain
(string; required): either of the supported chains (arbitrum
,avalanche
,base
,bsc
,eth
,fantom
,flare
,gnosis
,linea
,optimism
,polygon
,polygon_zkevm
,rollux
,scroll
,stellar
,syscoin
,telos
,xai
,xlayer
,avalanche_fuji
,base_sepolia
,eth_holesky
,eth_sepolia
,optimism_testnet
,polygon_amoy
).decodeLogs
(boolean): set totrue
to decode logs, or tofalse
if you don't need this kind of info.decodeTxData
(boolean): set totrue
to decode transaction data, or tofalse
if not interested in it.descOrder
(boolean): choose data order, either descending (iftrue
) or ascending (iffalse
).fromBlock
(uint64; quantity|tag): the first block of the range. Supported value formats: hex, decimal, "earliest", "latest".toBlock
(uint64; quantity|tag): the last block of the range. Supported value formats: hex, decimal, "earliest", "latest".includeLogs
(boolean): set totrue
to include logs, or tofalse
to exclude them. Note that logs are stored inside transactions, so make sure theincludeTxs
parameter is also set totrue
if you'd like to include logs.includeTxs
(boolean): set totrue
to include transactions, or tofalse
to exclude them.
{
"id": 1,
"jsonrpc": "2.0",
"method": "ankr_getBlocks",
"params": {
"blockchain": "string",
"decodeLogs": true,
"decodeTxData": true,
"descOrder": true,
"fromBlock": 0,
"includeLogs": true,
"includeTxs": true,
"toBlock": 0
}
}
Response
Returns complete information for the block specified by request parameters.
Code Examples
Request
curl --location --request POST 'https://rpc.ankr.com/multichain' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "ankr_getBlocks",
"params": {
"blockchain": "eth",
"fromBlock": 14500000,
"toBlock": 14500000,
"decodeLogs": false,
"decodeTxData": true,
"includeLogs": true,
"includeTxs": true
},
"id": 1
}'
Response
Code: 200 OK
{
"error": {},
"id": 1,
"jsonrpc": "2.0",
"result": {
"blocks": [
{
"blockHash": "string",
"blockHeight": "string",
"blockchainLogo": "string",
"blockchainName": "string",
"details": {
"ethBlock": {
"difficulty": "string",
"extraData": "string",
"gasLimit": 0,
"gasUsed": 0,
"miner": "string",
"nonce": "string",
"sha3Uncles": "string",
"size": "string",
"stateRoot": "string",
"totalDifficulty": "string"
}
},
"parentHash": "string",
"timestamp": "string",
"transactionsCount": 0
}
]
}
}
ankr_getLogs
Retrieves historical data for the specified range of blocks.
Request
Build your request using the parameters below.
Parameters
-
id
(int64; required): a request ID (example: 1). -
jsonrpc
(string; required): a JSON RPC spec used (example: 2.0). -
method
(string; required): a method used for the request. -
params
(object): the data object containing request body parameters:address
(array of strings): a contract address or a list of addresses from which the logs originate. Supported value formats: hex or array of hexes.blockchain
(string): a chain or a combination of chains to query:- Single chain:
arbitrum
,avalanche
,base
,bsc
,eth
,fantom
,flare
,gnosis
,linea
,optimism
,polygon
,polygon_zkevm
,rollux
,scroll
,stellar
,syscoin
,telos
,xai
,xlayer
,avalanche_fuji
,base_sepolia
,eth_holesky
,eth_sepolia
,optimism_testnet
,polygon_amoy
. - Chains combination:
[arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, stellar, syscoin, telos, xai, xlayer, avalanche_fuji, base_sepolia, eth_holelsky, eth_sepolia, polygon_amoy]
. - All chains: leave the value empty to query all the chains available.
- Single chain:
decodeLogs
(boolean): set totrue
to decode logs, or tofalse
if you don't need this kind of info.descOrder
(boolean): choose data order, either descending (iftrue
) or ascending (iffalse
).fromBlock
(string): the first block of the range. Supported value formats: hex, decimal, "earliest", "latest".fromTimestamp
(uint64): the first timestamp of the range.pageSize
(string): a number of result pages you'd like to get.pageToken
(string): a current page token provided at the end of the response body; can be referenced in the request to fetch the next page.toBlock
(string): the last block included in the range. Supported value formats: hex, decimal, "earliest", "latest".toTimestamp
(uint64): the last timestamp of the range.topics
(uint8): the data the log contains.
{
"id": 1,
"jsonrpc": "2.0",
"method": "ankr_getLogs",
"params": {
"address": [
[
0
]
],
"blockchain": [
"string"
],
"decodeLogs": true,
"descOrder": true,
"fromBlock": 0,
"fromTimestamp": 0,
"pageSize": 0,
"pageToken": "string",
"toBlock": 0,
"toTimestamp": 0,
"topics": [
[
[
0
]
]
]
}
}
Response
Returns history data for the blocks specified by request body parameters.
Code Examples
Request
curl --location --request POST 'https://rpc.ankr.com/multichain' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "ankr_getLogs",
"params": {
"blockchain": "eth",
"fromBlock": "0xdaf6b1", // hex, decimal, "earliest", "latest" are supported
"toBlock": 14350010, // hex, decimal, "earliest", "latest" are supported
"address": ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"], // hex or array of hexes are supported
"topics": [
[],
[
"0x000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff"
]
]
},
"id": 1
}'
Response
Code: 200 OK
{
"error": {},
"id": 1,
"jsonrpc": "2.0",
"result": {
"logs": [
{
"address": "string",
"blockHash": "string",
"blockNumber": "string",
"data": "string",
"event": {
"anonymous": true,
"id": "string",
"inputs": [
{
"indexed": true,
"name": "string",
"size": 0,
"type": "string",
"valueDecoded": "string"
}
],
"name": "string",
"signature": "string",
"string": "string",
"verified": true
},
"logIndex": "string",
"removed": true,
"topics": [
"string"
],
"transactionHash": "string",
"transactionIndex": "string"
}
],
"nextPageToken": "string"
}
}
ankr_getTransactionsByHash
Retrieves data for the hash-specified transaction.
Retrieves the details for a transaction specified by hash.
Request
Build your request using the parameters below.
Parameters
-
id
(int64; required): a request ID (example: 1). -
jsonrpc
(string; required): a JSON RPC spec used (example: 2.0). -
method
(string; required): a method used for the request. -
params
(object): the data object containing request body parameters:blockchain
(string): a chain or a combination of chains to query:- Single chain:
arbitrum
,avalanche
,base
,bsc
,eth
,fantom
,flare
,gnosis
,linea
,optimism
,polygon
,polygon_zkevm
,rollux
,scroll
,stellar
,syscoin
,telos
,xai
,xlayer
,avalanche_fuji
,base_sepolia
,eth_holesky
,eth_sepolia
,optimism_testnet
,polygon_amoy
. - Chains combination:
[arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, stellar, syscoin, telos, xai, xlayer, avalanche_fuji, base_sepolia, eth_holelsky, eth_sepolia, polygon_amoy]
. - All chains: leave the value empty to query all the chains available.
- Single chain:
transactionHash
(string): a hash of the transactions you'd like to request the details for.decodeLogs
(boolean): set totrue
to decode logs, or tofalse
if you don't need this kind of info.decodeTxData
(boolean): set totrue
to decode transaction data, or tofalse
if not interested in it.includeLogs
(boolean): set totrue
to include logs, or tofalse
to exclude them.
{
"id": 1,
"jsonrpc": "2.0",
"method": "ankr_getTransactionsByHash",
"params": {
"blockchain": [
"string"
],
"decodeLogs": true,
"decodeTxData": true,
"includeLogs": true,
"transactionHash": "string"
}
}
Response
Returns all transactions' metadata for the hash specified in request body parameters.
Code Examples
Request
curl --location -g --request POST 'https://rpc.ankr.com/multichain' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "ankr_getTransactionsByHash",
"params": {
"transactionHash": "0x82c13aaac6f0b6471afb94a3a64ae89d45baa3608ad397621dbb0d847f51196f",
"decodeLogs": true,
"decodeTxData": true
},
"id": 1
}'
Response
Code: 200 OK
{
"error": {},
"id": 1,
"jsonrpc": "2.0",
"result": {
"transactions": [
{
"blockHash": "string",
"blockNumber": "string",
"blockchain": "string",
"contractAddress": "string",
"cumulativeGasUsed": "string",
"from": "string",
"gas": "string",
"gasPrice": "string",
"gasUsed": "string",
"hash": "string",
"input": "string",
"logs": [
{
"address": "string",
"blockHash": "string",
"blockNumber": "string",
"data": "string",
"event": {
"anonymous": true,
"id": "string",
"inputs": [
{
"indexed": true,
"name": "string",
"size": 0,
"type": "string",
"valueDecoded": "string"
}
],
"name": "string",
"signature": "string",
"string": "string",
"verified": true
},
"logIndex": "string",
"removed": true,
"topics": [
"string"
],
"transactionHash": "string",
"transactionIndex": "string"
}
],
"logsBloom": "string",
"method": {
"id": "string",
"inputs": [
{
"name": "string",
"size": 0,
"type": "string",
"valueDecoded": "string"
}
],
"name": "string",
"signature": "string",
"string": "string",
"verified": true
},
"nonce": "string",
"r": "string",
"s": "string",
"status": "string",
"timestamp": "string",
"to": "string",
"transactionHash": "string",
"transactionIndex": "string",
"type": "string",
"v": "string",
"value": "string"
}
]
}
}
ankr_getTransactionsByAddress
Retrieves transactions by address.
Retrieves the details of transactions specified by address.
Request
Build your request using the parameters below.
Parameters
-
id
(int64; required): a request ID (example: 1). -
jsonrpc
(string; required): a JSON RPC spec used (example: 2.0). -
method
(string; required): a method used for the request. -
params
(object): the data object containing request body parameters:address
(string; required): an address to search for transactions.blockchain
(string): a chain or a combination of chains to query:- Single chain:
arbitrum
,avalanche
,base
,bsc
,eth
,fantom
,flare
,gnosis
,linea
,optimism
,polygon
,polygon_zkevm
,rollux
,scroll
,stellar
,syscoin
,telos
,xai
,xlayer
,avalanche_fuji
,base_sepolia
,eth_holesky
,eth_sepolia
,optimism_testnet
,polygon_amoy
. - Chains combination:
[arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, stellar, syscoin, telos, xai, xlayer, avalanche_fuji, base_sepolia, eth_holelsky, eth_sepolia, polygon_amoy]
. - All chains: leave the value empty to query all the chains available.
- Single chain:
fromBlock
(integer): narrow your search indicating the block number to start from (inclusive;>= 0
). Supported value formats: hex, decimal, "earliest", "latest".toBlock
(integer): narrow your search indicating the block number to end with (inclusive;>= 0
). Supported value formats: hex, decimal, "earliest", "latest".fromTimestamp
(integer): narrow your search indicating the timestamp to start from (inclusive;>= 0
).toTimestamp
(integer): narrow your search indicating the timestamp to end with (inclusive;>=0
).includeLogs
(boolean): set totrue
to include logs, or tofalse
to exclude them.descOrder
(boolean): choose data order, either descending (iftrue
) or ascending (iffalse
).pageSize
(int32): a number of result pages you'd like to get.pageToken
(string): a current page token provided at the end of the response body; can be referenced in the request to fetch the next page.
{
"id": 1,
"jsonrpc": "2.0",
"method": "ankr_getTransactionsByAddress",
"params": {
"blockchain": "string",
"includeLogs": true,
"descOrder": true,
"pageSize": 0,
"pageToken": "string",
"toTimestamp": 0,
"address": "string"
}
}
Response
Returns the transactions specified by address.
Code Examples
Request
curl --location -g --request POST 'https://rpc.ankr.com/multichain' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": 1,
"jsonrpc": "2.0",
"method": "ankr_getTransactionsByAddress",
"params": {
"address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
}
}'
Response
Code: 200 OK
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"transactions": [
{
"blockHash": "string",
"blockNumber": "string",
"blockchain": "string",
"cumulativeGasUsed": "string",
"from": "string",
"gas": "string",
"gasPrice": "string",
"gasUsed": "string",
"hash": "string",
"input": "string",
"nonce": "string",
"r": "string",
"s": "string",
"status": "string",
"timestamp": "string",
"to": "string",
"transactionIndex": "string",
"type": "string",
"v": "string",
"value": "string"
}
]
}
}
ankr_getInteractions
Retrieves blockchains interacted with a particular address.
Retrieves a list of blockchains on which interactions (tokens, NFTs, transactions) were registered for the address specified.
Request
Build your request using the parameters below.
Parameters
-
id
(int64; required): a request ID (example: 1). -
jsonrpc
(string; required): a JSON RPC spec used (example: 2.0). -
method
(string; required): a method used for the request. -
params
(object): the data object containing request body parameters:address
(string): an address of the wallet or contract created the logs.
{
"id": 1,
"jsonrpc": "2.0",
"method": "ankr_getInteractions",
"params": {
"address": "string"
}
}
Response
Returns the list of blockchains interacted with the address specified in request body parameters.
Code Examples
Request
curl --location -g --request POST 'https://rpc.ankr.com/multichain' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "ankr_getInteractions",
"params": {
"address":"0xF977814e90dA44bFA03b6295A0616a897441aceC"
},
"id": "1"
}
'
Response
Code: 200 OK
{
"error": {},
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockchains": [
"string"
]
}
}