Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

A decentralized gold price feed example built with Solidity, Truffle and Witnet

Notifications You must be signed in to change notification settings

stampery-labs/witnet-goldprice-example

Repository files navigation

⚠️ This repository has been deprecated in favor of price-feed-examples repository.

Witnet Gold Price Feed Example

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!

How is the price feed designed?

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.

How decentralized is this example?

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.

Understanding the project

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:

Compile Witnet Requests

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.

Compile PriceFeed contract

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

Deploy 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

About

A decentralized gold price feed example built with Solidity, Truffle and Witnet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •