Introduction
Request the data you need by POSTing to /stream
and you shall receive a stream of newline-separated JSON objects that package your data by block. For example
outputs
Here, we requested all records on instructions executed against the MoonCVV...Trg
program, with a bare minimum of fields. One such record was found for block 325000000. There were no records of such instructions being executed in block 325000001, but the block was included anyway to indicate the range boundary.
By using this general approach, you can
- Get data on instructions, transactions, logs, balance updates and rewards.
- Ensure that you only get the data you need by using a rich palette of filters.
- Request data related to the data that matches your filters. In the example above we could request all transactions that contain matching instructions, or even all token balance updates caused by such transactions.
Solana data is updated in real time and includes unfinalized blocks, enabling latencies of 1-2 s. Just omit the toBlock
field in the request and you’ll get the latest data.
Making your own client
Real life protocols and infra introduce a couple of complications that you need to know about to actually build a client:
-
The endpoint may terminate the stream of blocks at any point. To resume the stream the client must update the
fromBlock
and the optionalparentBlockHash
fields of its request and send the request to the API again.Note that that does mean that our example theoretically could have taken two requests instead of one.
If your request specifies a
toBlock
you can tell that it’s done when you get either a block with this slot number or an empty HTTP 200 response.If the range of your request is entirely above the range of available blocks you’ll get an HTTP 204 (No Content).
-
Ensuring data correctness when streaming unfinalized blocks is somewhat complicated. If you don’t want to deal with that complexity and don’t mind that the newest available data is up to several hours old, use the alternative
/finalized-stream
endpoint; otherwise read on.Some of the shared code for pipes and the Squid SDK will deal with unfinalized blocks for you under the hood.
Base URL
For Solana use
Other SVM networks TBA.
Other endpoints
- GET /metadata - dataset metadata. Includes the number of the lowest available slot.
- GET /head - slot number and hash of the highest block of the dataset.
- GET /finalized-head - same, but only for finalized blocks. In the current implementation it will be behind
/head
by some thousands of slots. - POST /finalized-stream - same as the main endpoint POST /stream, but will only return finalized blocks, up to the height you can get from GET /finalized-head