price-feed-examples
repository.
witnet-goldprice-example
is a price feed example that aims to illustrate how to build data feeds by using Witnet and their development tools. It was developed following the steps described in the Witnet documentation.
DISCLAIMER: This code is experimental and APIs are subject to change. Use it at your own risk!
The gold price feed included in this example:
- Queries 4 different APIs for the EUR price of 1 Gold onz using 4 witnessing nodes from Witnet.
- Defines how to aggregate the values from both APIs and report the result.
- Defines how to tally the results reported by the different nodes into a single data point that can be trustlessly consumed by an Ethereum smart contract.
None of the parties involved in the process of deploying, updating and using the price feed will have any power to tamper with the integrity of the data points it provides:
- Once deployed, no one will be able to prevent the price feed from being updated or queried.
- Nobody can set the price directly. The only way to update it is through a Witnet request.
- The price is averaged from different public APIs, thus mitigating their influence in the final price.
- The data is relayed by different Witnet nodes, whose reported data points get aggregated and averaged, filtering out any outliers so as to cancel any malicious reporter who may try to leverage a slight drift of the data point.
In this project you will find the following structure:
witnet-goldprice-example
├── contracts // Where your Solidity contracts will be
│ └── requests // Where Witnet requests end up after compilation
├── migrations // Deployment scripts
├── requests // Witnet request source code (.js files)
└── test // Scripts for testing your contracts
In the requests
folder, you will find the code that defines how data is retrieved, aggregated and tallied. More information is available at:
First, you need to compile the Witnet requests as follows:
npm run compile-requests
yarn compile-requests
It will compile the requests into Witnet bytecode and write for you the Truffle migrations scripts.
Second, you need to compile the PriceFeed
solidity smart contract. This contract inherits UsingWitnet
and provides functions to request and complete price feed updates.
npm run compile-contracts
yarn compile-contracts
Finally, you could deploy the previous smart contract and Witnet request by using Truffle migrate
. Be sure to configure properly truffle-config.js
.
For example, the following commands will migrate the contracts into the development network:
npm run migrate
yarn migrate