Create and Send Data Requests on the Witnet Network

This post covers the simple steps needed to send a data request to Witnet’s decentralized oracle network.

Claudia Bartoli Duncan
The Witnet Oracle Blog
4 min readJul 14, 2020

--

Data requests are live on the Witnet Network

Firstly, get a node running

More details about the process of running a node can be found here. As an example, if you’re using docker, you’ll just need to run the following command:

With your node up and running, you can interact with the Testnet by sending data requests. You can do so in two steps, which we will cover below:

1. Create a data request: In this section, we will describe how to create a data request, add sources, define necessary parameters, decide on how data is aggregated and define other features. You will also be introduced to RADON, a domain-specific language, which will help you build data requests.

2. Send a data request and retrieve the results: If you are interested in seeing how the request is managed through the blockchain, how collateral works, or any other network behavior when resolving a data request, you may be interested in this section.

1. Create a data request

You can create a data request in Witnet using the truffle box. To begin, create a folder and unbox the truffle-box using the following command:

The truffle box will create a directory with all the files needed to execute the data request creation.

We are now ready to create the data request. You will need to create a JavaScript file in the request folder first_data_request.js. Now fill the request with the following parameters.

Parameter 1: Select the Sources

Decide from which public API you would like to pull the data from. In this example, we are using the API https://www.bitstamp.net/api/ticker/ , and we specify the RADON methods as follows to retrieve that data.

Note: you can add multiple sources. To do so, just add the sources as with the bitstamp constant below.

Parameter 2: Define the Aggregation

Aggregators define how results from multiple sources are reduced or merged into a single data point.

Parameter 3: Define the Tally

Tallies are similar to aggregators, but instead of merging multiple sources, they merge the results reported by multiple Witnet nodes.

Adding in the final touches

The setQuorum, setFees and schedule parameters allow you to further customize the data request:

  • setQuorum specifies the number of witnesses you desire your request to be fulfilled by, and the minimum consensus that needs to be achieved by the network in order to consider the result as valid
  • setFees specifies how much you want to pay for rewarding each of the Witnet nodes implicated in resolving the request
  • schedule allows you to set the date and time that you’d like the request to be fulfilled

You can find more information on these methods here.

Once you’ve set all the parameters, execute:

That’s it! The data request is created and ready to be deployed in Witnet.

If you check the contracts file, you will see that a hexadecimal expression of the request is now available; this will be used to send the data request to Witnet.

NOTE: the truffle box allows you to do even more. If you check the bitcoin-pricefeed tutorial you will see how you can connect your data request to a smart contract in Ethereum and deploy it.

Send a data request and retrieve the results

In this section, we will explain how to send data requests to Witnet and retrieve information.

Important: you need some WIT tokens (or UXTOs that have been through a 1000 block maturation coin age) to send the data request to the network.

Firstly, you’ll need the hexadecimal representation of the data requests you want to deploy. You can get it from the request smart contract that is automatically created when compiling the request. You can use a data request you created or use one of the examples available. When using examples, simply clone the relevant repository and run the command:

As mentioned before, the hexadecimal of the request can be found in the request contract, for instance, the eth_price.js requests look like this:

With this hex you can now send the request to Witnet, using the following command:

If you check your node logs, you might see that it has been sent, and you can see the different stages of the request. You can also get the status of the request with the following command:

States of the data request: If you are not familiar with the states of the data request when in Witnet, here’s a brief explanation:

  • Commit: This stage sees nodes resolve the request and secretly publish results
  • Reveal: Once every node has committed the results (whilst ensuring they can’t copy one another), those results are revealed to the network
  • Tally: The last stage is the aggregation of the reveals and the publication of the result

Congratulations! You’ve sent your first data request 🎊

--

--