In our first demonstration of Paralink Node Query Editor, we have used an example of a price feed query. Oracles today are mainly used for price feeds, but in the future, oracle use cases will expand to other areas where data collection is needed.
This blog post will demonstrate how developers can use Paralink Node Query Editor to query an API for a sports match result. Such use cases are useful for everyone who requires data ingress for sports betting dapps or any other smart contract application where such data ingress type is needed.
We need an NBA match result from the Atlanta Hawks vs. Milwaukee Bucks that was played on July 4, 2021.
Creating a new PQL query
First, we will need to open a new query. Click the “Add new PQL” button under the “Query list” tab.
Since our node currently supports one whole number result (at the time), we will create two separate queries (requests), one for the home team (Atlanta Hawks) and one for the away team (Milwaukee Bucks).
Naming the query
To give your query (or project) a name, start writing in this field (shown below).
Now let’s start with extracting the data from our selected data provider.
First, we need some data sources, and we have decided to use the following free API: https://www.thesportsdb.com/api.php
All leagues results are located here: https://www.thesportsdb.com/api/v1/json/1/all_leagues.php – (tip: if you open this link in Firefox, you will get a more readable version of this file).
Since we are interested in NBA matches, we need an NBA league ID. The NBA league ID is 4387.
Now we need to find the latest results by this league ID.
We can find these results at this URL: https://www.thesportsdb.com/api/v1/json/1/eventspastleague.php?id=4387 – (again, FireFox will automatically read the JSON file and show its structure)
Now we can start with data extraction.
Click “Add loader” and then select “Http Get”.
As mentioned above, we will use the following Request URL: https://www.thesportsdb.com/api/v1/json/1/eventspastleague.php?id=4387
Now we need to traverse the data in this JSON file. First, we need to traverse the “events,” and then select the correct index (location) of our requested match.
Click on “Add operator” and then click “Traverse”.
All matches are sorted under “events,” so this is what we have to enter “events” in this field (as shown below).
Now we have to select the requested match. Our match is indexed (located) as “0”. Again, click on “Add operator” and then select “Get index”.
Enter 0 and click Submit.
All you have to do now is get the home team’s score (Atlanta Hawks). We have to traverse the data to find the home team score. It is located here: “intHomeScore”.
Click “Add operator” and then select “Traverse”.
Enter “intHomeScore” as shown below and click Submit.
Now you can Compile the code, and click Run.
You should get the score for the home team (Atlanta Hawks): 107
All that remains is to repeat all steps again, but now for the away team (Milwaukee Bucks). The only difference will be the last step, where we traverse the data for the following data point: “intAwayScore”.
If you compile the code and run the query, you should get “118,” which was the Milwaukee Bucks score at the end.
How to get started?
This guide is made for developers who want to use Paralink as an oracle solution for their smart contracts and node operators who want to provide a trusted oracle service or create their own oracle quorum.
We also invite you to visit our Github page to find more detailed information and documentation about Paralink solutions. Our documentation is available here.
You can join our official Discord server, where we have a dedicated channel for developers. You can join here: