firstBlock (can be the genesis block) and ending at the highest available block. Proceed as follows:
-
Retrieve the dataset height from the router with
GET /heightand make sure it’s abovefirstBlock. -
Save the value of
firstBlockto some variable, saycurrentBlock. -
Query the router for an URL of a worker that has the data for
currentBlockwithGET /${currentBlock}/worker. -
Retrieve the data from the worker by posting the query (
POST /), setting the"fromBlock"query field to${currentBlock}. -
Parse the retrieved data to get a batch of query data plus the height of the last block available from the current worker. Take the
header.numberfield of the last element of the retrieved JSON array - it is the height you want. Even if your query returns no data, you’ll still get the block data for the last block in the range, so this procedure is safe. -
Set
currentBlockto the height from the previous step plus one. - Repeat steps 3-6 until all the required data is retrieved.
Manually with cURL
Manually with cURL
Suppose we want all token burns starting from block 58_000_000. We have to:
-
Verify that the dataset has reached the required height:
Output
- Remember that your current height is 58000000.
-
Get a worker URL for the current height
Output is a worker URL, e.g.
-
Retrieve the data from the worker
The output is a JSON array of per-block data. Its last element holds the highest block available from this worker:
-
Observe the
header.numberof the last list item, say59286799. To get the rest of the data, request a worker that has blocks from 59286800 on:This part of the dataset may be located on another host. - Repeat steps 4 and 5 until the dataset height is reached.
In Python
In Python
Router API
GET /height (get height of the dataset)
GET /height (get height of the dataset)
Example response:
84700964.GET ${firstBlock}/worker (get a suitable worker URL)
GET ${firstBlock}/worker (get a suitable worker URL)
The returned worker will be capable of processing
POST / requests in which the "fromBlock" field is equal to ${firstBlock}.Example response: https://rb06.sqd-archive.net/worker/query/czM6Ly90cm9uLW1haW5uZXQ.Worker API
POST / (query logs and transactions)
POST / (query logs and transactions)
Query Fields
- fromBlock: Block number to start from (inclusive).
- toBlock: (optional) Block number to end on (inclusive). If this is not given, the query will go on for a fixed amount of time or until it reaches the height of the dataset.
- includeAllBlocks: (optional) If true, the Network will include blocks that contain no data selected by data requests into its response.
- fields: (optional) A selector of data fields to retrieve. Common for all data items.
- logs: (optional) A list of log requests. An empty list requests no data.
- transactions: (optional) A list of general transaction requests. An empty list requests no data.
- transferTransactions: (optional) A list of “transfer” transaction requests. An empty list requests no data.
- transferAssetTransactions: (optional) A list of “transfer asset” transaction requests. An empty list requests no data.
- triggerSmartContractTransactions: (optional) A list of “trigger smart contract” transaction requests. An empty list requests no data.
- internalTransactions: (optional) A list of internal transaction requests. An empty list requests no data.
Example Request
Example Request
This requests USDT
Transfer(address,address,uint256) event logs together with their parent transactions on a single block:header.number, header.hash and header.parentHash always present and the rest of the fields as requested by the fields selector.Data requests
Logs
address: the set of addresses of contracts emitting the logs. Omit to subscribe to events from all contracts in the network.topicN: the set of values of topicN.
null request matches any log.
With transaction: true all parent transactions will be included into the response.
Transactions
General
type: the set of acceptable transaction types.
type request in this case). An empty array matches no transactions; omitted or null request matches any transaction.
With logs: true all logs emitted by the transactions will be included into the response. With internalTransactions: true all the internal transactions induced by the selected transactions will be included into the response.
“transfer”
owner: the set of owner addresses for which the transfer transactions should be retrieved.to: the set of destination addresses.
null request matches any transaction.
With logs: true all logs emitted by the transactions will be included into the response. With internalTransactions: true all the internal transactions induced by the selected transactions will be included into the response.
“transfer asset”
owner: the set of owner addresses for which the transfer transactions should be retrieved.to: the set of destination addresses.asset: the set of asset contract addresses.
null request matches any transaction.
With logs: true all logs emitted by the transactions will be included into the response. With internalTransactions: true all the internal transactions induced by the selected transactions will be included into the response.
“trigger smart contract”
owner: the set of addresses of call owners.contract: the set of addresses of contracts being called.sighash: the set of 4-byte signature hashes of the called functions, hex-encoded without a0xprefix.
null request matches any transaction.
With logs: true all logs emitted by the transactions will be included into the response. With internalTransactions: true all the internal transactions induced by the selected transactions will be included into the response.
Internal transactions
caller: the set of addresses of caller contracts.transferTo: the set of addresses of receivers of TRX or TRC10 tokens.
null request matches any transaction.
With transaction: true all parent transactions for the selected internal transactions will be included into the response.
Data fields selector
A selector of fields for the returned data items. Its structure is as follows:transaction field selector is common for all transaction types except for the internal transactions.
A valid field selector of any given type is a JSON that has a subset of that type’s fields as keys and true as values, e.g. {"hash": true, "timestamp": true}. Fields marked always present below are returned regardless of the selector.
Block fields
number, hash and parentHash are always present. The selectable fields are:
Log fields
logIndex and transactionIndex are always present. The selectable fields are:
Transaction fields
transactionIndex is always present. The selectable fields are:
Internal transaction fields
transactionIndex and internalTransactionIndex are always present. The selectable fields are: