# Three ways of creating and deploying data requests in Witnet This document describes three ways of creating and deployind a data request in Witnet. We will consider the user creating a data request has a node running, for more information about how to run a node in Witnet click [here](https://hackmd.io/VL3az9oLTDylsEhFB4qGqQ). ## First step Always, when creating a data request, the first and most important thing we need to do is selecting the public API (one or more) from which we want Witnet to get the data. Once we have it, you need to check the steps to get that data. With this in mind, we can continue. ## 1. (Almost) From scratch The first option is to create the data request by changing some existing scripts to create our own data request. ### Get the CBOR values We need to clone the [rad-script repository](git@github.com:lrubiorod/rad-script.git) in order to get the CBOR values later and add them to the json file. Once we have the roporistoy, from it we change the file main.rs ![](https://i.imgur.com/UHqQp93.png) and from here we change the steps to get the data. Then we run the command ``` cargo run ``` In the console it should appear something like [131, 24, 119, 130, 24, 102, 97, 51, 130, 24, 102, 101, 112, 114, 105, 99, 101]. These are the CBOR values to be added in the json file. ### Create the data_request.json Go to the [wintet-rust](git@github.com:witnet/witnet-rust.git) repository once cloned and from here copy an already existing data request. Change the URL, the CBOR values and the parameters that you consider necessary (aggregation, tally, reward, fee... ). Suppose we call our data request _data_request.json_, then we are ready to deploy it. NOTE: Remember that the json file mut be one line! ### Deploy the data request This is the simplest step, just run the command ``` cat data_request.json | cargo run -- -c witnet.toml node raw ``` This command will print the hexadecimal corresponding to the data request. Using this hexadecimal we can track the data request in the node logs or get information about it using the command: ``` cargo run -- -i wintet.toml node dataRequestRepost <hex> ``` ## 2. Sheikah This is the nicest way to do it. Just follow the [tutorial to deploy Sheikah](https://hackmd.io/GI0m_GqPS7u3AAKfztBYSA). Once we have Sheikah deployed and we have some wits in our account, we can deploy a Data request to Witnet. Let's take as an example the data request created in the section above _data_request.json_. We can import it to sheikah and then deploy it. For making it work, first we need to make the request readeable to Sheikah. The next command will automatically create a request valid to Sheikah: ``` witnetrequest2template ./data_request ./sheikah_data_request ``` Now from Sheikah, in the data request section, we can import the _sheikah_data_request_ and deploy it. NOTE: In Sheikah templates can be used for creating data request. ## 3. Connecting Smart Contracts and Witnet This last option describes the depoloyment of a deta request through a Solidity contract. This is actually the most important since it's actually what Witnet is here for, connecting smart contracts to the real, off-chain world! Here's how we do it: 1. We are going to work from a template, so create a directory and just unbox the truffle box that contains all the dark side of the implementation. `mkdir bitcoin-price-feed` `cd bitcoin-price-feed` `truffle unbox witnet/truffle-box` 2. In this new directory we create the data request. The first thing we need to do is decide the API we want to get the data from and the steps to get to that data. Then we'll add it in a java script file, as in this example // Retrieves EUR price of gols from the API https://www.inversoro.es/precio-del-oro/ const bitstamp = new Witnet.Source("https://www.inversoro.es/ajax/price-updates/305f0d9506260/") .parseMapJSON() // Parse a `Map` from the retrieved `String` .getMap("3") // Get the `Map` value associated to the `3` key .getInteger("price") // Get the integer associated to `price` NOTE: in the js of the dr we need to import the Witnet Java Script Libray `import * as Witnet from "witnet-requests"` 3. We add the agregstors and the tally as in the options above. 4. Add what we will export when compiling it. This is basiccally a summery of what we want to be done when deploying the DR ```solidity const request = new Witnet.Request() .addSource(nameSource) // Use source .setAggregator(aggregator) // Set the aggregation script .setTally(tally) // Set the tally script .setQuorum(4, 2) // Set witness count .setFees(10, 1, 1, 1) // Set economic incentives .schedule(0) // Make this request immediately solvable export { request as default } ``` From here the steps are the same as described [here](https://hackmd.io/Za5skczvQ7OOy9bofVg1Kw).