Advanced API
Query API

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:

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, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai.
      • Chains combination: [arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai].
      • All chains: leave the value empty to query all the chains available.
{
  "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, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai).
    • decodeLogs (boolean): set to true to decode logs, or to false if you don't need this kind of info.
    • decodeTxData (boolean): set to true to decode transaction data, or to false if not interested in it.
    • descOrder (boolean): choose data order, either descending (if true) or ascending (if false).
    • 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 to true to include logs, or to false to exclude them. Note that logs are stored inside transactions, so make sure the includeTxs parameter is also set to true if you'd like to include logs.
    • includeTxs (boolean): set to true to include transactions, or to false 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, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai.
      • Chains combination: [arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai].
      • All chains: leave the value empty to query all the chains available.
    • decodeLogs (boolean): set to true to decode logs, or to false if you don't need this kind of info.
    • descOrder (boolean): choose data order, either descending (if true) or ascending (if false).
    • 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, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai.
      • Chains combination: [arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai].
      • All chains: leave the value empty to query all the chains available.
    • transactionHash (string): a hash of the transactions you'd like to request the details for.
    • decodeLogs (boolean): set to true to decode logs, or to false if you don't need this kind of info.
    • decodeTxData (boolean): set to true to decode transaction data, or to false if not interested in it.
    • includeLogs (boolean): set to true to include logs, or to false 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, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai.
      • Chains combination: [arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, stellar, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai].
      • All chains: leave the value empty to query all the chains available.
    • 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 to true to include logs, or to false to exclude them.
    • descOrder (boolean): choose data order, either descending (if true) or ascending (if false).
    • 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"
    ]
  }
}

ankr_getInternalTransactionsByBlockNumber

Retrieves info on internal transactions by block number.

Internal transactions are callbacks that happen during contract-to-contract interactions.

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:

    • blockNumber (integer): number of the block that contains the transaction.
    • blockchain (string; required): either of the supported chains (arbitrum, avalanche, base, bsc, eth, fantom, flare, gnosis, linea, optimism, polygon, polygon_zkevm, rollux, scroll, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai).
    • onlyWithValue (boolean): set to true to receive only the responses containing the value parameter, or false — to receive all responses.
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "ankr_getInternalTransactionsByBlockNumber",
    "params": {
      "blockNumber": 0,
      "blockchain": "string",
      "onlyWithValue": true
    }
}

Response

Returns info on internal transactions specified by block number.

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_getInternalTransactionsByBlockNumber",
              "params": {
                "blockNumber": 15218456,
                "blockchain": "eth",
                "onlyWithValue": true
              }
            }'

Response

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "internalTransactions": [
            {
                "blockHash": "0xbb07ad76eca8b2a1ed8f58ce107eceb720a1468affa20223fc8cb562efa9639a",
                "blockHeight": 15218456,
                "blockchain": "eth",
                "callPath": "call_2",
                "callStack": [
                    2
                ],
                "contractAddress": "0x00000000006c3852cbef3e08e8df289169ede581",
                "error": "",
                "fromAddress": "0x00000000006c3852cbef3e08e8df289169ede581",
                "input": null,
                "output": null,
                "timestamp": "1658843328",
                "toAddress": "0x8de9c5a032463c561423387a9648c5c7bcc5bc90",
                "transactionHash": "0xdfca28001e023c90ab8d67f2b4099df76cda0493865821387734640425637696",
                "transactionIndex": 4,
                "value": "33750000000000000"
            }
        ]
    }
}

ankr_getInternalTransactionsByParentHash

Retrieves info on internal transactions by parent transaction hash.

Internal transactions are callbacks that happen during contract-to-contract interactions.

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, syscoin, avalanche_fuji, eth_goerli, optimism_testnet, polygon_mumbai).
    • onlyWithValue (boolean): set to true to receive only the responses containing the value parameter.
    • parentTransactionHash (string, hex encoded; required): the hash of a parent transaction.
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "ankr_getInternalTransactionsByParentHash",
    "params": {
      "blockchain": "string",
      "onlyWithValue": true,
      "parentTransactionHash": "string"
    }
}

Response

Returns info on internal transactions specified by a parent transaction hash.

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_getInternalTransactionsByParentHash",
              "params": {
                "blockchain": "eth",
                "onlyWithValue": true,
                "parentTransactionHash": "0xa50f8744e65cb76f66f9d54499d5401866a75d93db2e784952f55205afc3acc5"
              }
            }'

Response

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "internalTransactions": [
            {
                "blockHash": "0xee3d5db51c965922f589c9ac9a16f5c77ba36ca55df651dccc1ccabdb5146b5f",
                "blockHeight": 15219110,
                "blockchain": "eth",
                "callPath": "call_2",
                "callStack": [
                    2
                ],
                "contractAddress": "0x00000000006c3852cbef3e08e8df289169ede581",
                "error": "",
                "fromAddress": "0x00000000006c3852cbef3e08e8df289169ede581",
                "input": null,
                "output": null,
                "timestamp": "1658852109",
                "toAddress": "0x8de9c5a032463c561423387a9648c5c7bcc5bc90",
                "transactionHash": "0xa50f8744e65cb76f66f9d54499d5401866a75d93db2e784952f55205afc3acc5",
                "transactionIndex": 6,
                "value": "250000000000000"
            },
            {
                "blockHash": "0xee3d5db51c965922f589c9ac9a16f5c77ba36ca55df651dccc1ccabdb5146b5f",
                "blockHeight": 15219110,
                "blockchain": "eth",
                "callPath": "call_3",
                "callStack": [
                    3
                ],
                "contractAddress": "0x00000000006c3852cbef3e08e8df289169ede581",
                "error": "",
                "fromAddress": "0x00000000006c3852cbef3e08e8df289169ede581",
                "input": null,
                "output": null,
                "timestamp": "1658852109",
                "toAddress": "0xcc71606c7a3eda45ae010e5a125312f0bad1bae7",
                "transactionHash": "0xa50f8744e65cb76f66f9d54499d5401866a75d93db2e784952f55205afc3acc5",
                "transactionIndex": 7,
                "value": "9750000000000000"
            }
        ]
    }
}