Fuel SQD Network API
SQD Network API distributes the requests over a (potentially decentralized) network of workers. The main gateway URL points at a router that provides URLs of workers that do the heavy lifting. Each worker has its own range of blocks on each dataset it serves. Suppose you want to retrieve an output of some query on a block range starting atfirstBlock (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 data on Fuel receipts from block
1000000. We begin by finding the main URL for the Fuel Mainnet dataset. Then we have to:-
Retrieve the dataset height from the router with
Output
-
Save the value
1000000to some variable, saycurrentBlock. -
Query the router for an URL of a worker that has the data for
currentBlockOutput -
Retrieve the data from the worker
Output:
-
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.
In Python
In Python
Router API
GET /height (get height of the dataset)
GET /height (get height of the dataset)
Example response:
16576911.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://rb03.sqd-archive.net/worker/query/czM6Ly9mdWVsLXRlc3RuZXQ.Worker API
POST / (query inputs and receipts)
POST / (query inputs and receipts)
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.
- receipts: (optional) A list of receipts requests. An empty list requests no data.
- inputs: (optional) A list of inputs requests. An empty list requests no data.
- outputs: (optional) A list of outputs requests. An empty list requests no data.
- transactions: (optional) A list of transactions requests. An empty list requests no data.
Example Request
Example Request
Example Response
Example Response
