Querying
Last updated
Last updated
Once the data is indexed and available in your tables, it is time to query it. It was already mentioned there are two ways of doing that, and they are:
Utilize our GraphQL API, which offers standardized queries and returns data in base64 XDR format.
Call a where you can customize various aspects, including the response format.
This is the most straightforward way of querying Zephyr's data. You just have to craft a request and send it to our GraphQL API. Testnet and Mainnet endpoints can be found in the section. From the Zephyr dashboard, you have to find the name of the table to want to query and insert it in the request body.
Following the example on the quickstart, to request the data on our table zephyr_85b036892719b0a99aa987b1f62e9b10
, the query will look like this:
Under "node" make sure to insert the names of the table's columns you need to query.
The request will be the following:
What you get as a response will be base-64 XDR encoded and look like this:
Here you can see all the contents of the table's column "hello". To decode the data we can use the Stellar Laboratory (in this case we have saved the data as ScVals).
To better understand how to decode the return types on your client, you can jump to the "work with data structures" section.
This approach requires a bit more work at the beginning but is the best and most efficient choice for querying data as it allows you to work with Soroban data structures from the program using the Soroban and Rust type system.
That means that after calling the function from the client, your data will be returned directly in the format you decide. To create these customized endpoints, a better and more technical explanation of serverless functions is required.
To learn how to create your custom API endpoints using serverless functions, go to the serverless functions section.
It is also important to note that up to now it's not possible to customize the tables' names. You will have to remember them or explore the table structure in the (under "nodes" you can find the different columns) to find the right table.
It is also possible to use the GraphQL playground to perform your queries (you can find it in the section). It could be particularly useful especially when you start understanding Zephyr, and for crafting the queries.
Just remember, before sending the request from the playground, to put your Mercury access token in the authentication headers. An example of how to use the playground can be found in Mercury's tutorial.