Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time

5. Compile and try the request

!!! note "" This article is part of the beginner tutorial on creating a totally decentralized Bitcoin price feed on Ethereum with Solidity and Witnet.

Compile you data request

Compiling the request could not be easier:

=== "npm" console npm run compile:requests === "yarn" console yarn compile:requests

The compile:requests npm task will:

  1. Analyze your requests for syntactic and semantic errors.
  2. Warn you of any security issues and broken incentives.
  3. Try to compile the requests into Witnet bytecode.
  4. Put the bytecode into auxiliary Solidity contracts that you can import into your own contracts.
  5. Write migration files with default constructor arguments that you can later customize.

If you now take a look in the contracts/requests folder, you will notice a new file called BitcoinPrice.sol. It will contain something like this:

pragma solidity >=0.7.0 <0.9.0;

import "witnet-solidity-bridge/contracts/requests/WitnetRequestInitializableBase.sol";

// The bytecode of the BitcoinPrice request that will be sent to Witnet
contract BitcoinPriceRequest is WitnetRequestInitializableBase {
    constructor () {}  
    function initialize() public {

As you can see, the contract contains the byte code for the request you just wrote, exported as a Solidity contract that you can then import and instantiate from your own contracts.

Try your data request

Data requests can be easily tried and debugged locally using the try npm task:

=== "npm" console npm run try === "yarn" console yarn try

The first time you invoke the try npm task, it will tell you that it needs to download a native witnet_toolkit binary. Just press Enter and it will do it for you.

A few seconds later, you should be presented with a "Witnet data request local execution report". If you go to the latest part — the "Tally stage" — you can see what the result of your data request would be if executed right now:

║ Witnet data request local execution report ║
║ BitcoinPrice.sol                           ║
<multiple lines ommitted>
 │  ┌────────────────────────────────────────────────┐
 └──┤ Tally stage                                    │
    │ Execution time: 0.00123 ms                     │
    │ Result is Integer: 47742275                    │

Now that you have compiled and tried your data request, the next step is to write your main consumer contract.

!!! question "Remember: You are not alone!" Join the Witnet Community Discord or Telegram. Members of the Witnet community will be happy to answer your questions and assist you through this tutorial.