/my-oracle

Learning project: building a simple smart contract Oracle

Primary LanguageJavaScript

My First Oracle

This is a WIP project, to learn how Oracles work on blockchains. It was inspired by this article, and has been updated to current versions and language features/properties.

What does it do

It gets the current BTC market cap from CoinGecko into a smart contract, using an oracle script.

Prerequisits

  1. Truffle. I have it installed globally: npm i -g truffle
  2. You'll need a developer blockchain, like ethereumjs-testrpc or Ganache - which is what I'm using. If yours runs on a different port/address, update the networks:development section in truffle-config.js accordingly.

How to run

  1. Clone this repo
  2. Install dependencies: npm i
  3. Run your blockchain first, and wait for it to load
  4. Deploy the smart contract: truffle migrate
  5. Run the Oracle: npm run oracle or node src/oracle
  6. Open another terminal and run the client: npm run client or node src/client.
    You'll need to run it twice to see the value change from 0.

Tests

Run truffle test or node run test.

Tech

The oracle.js script uses ethers.js and JSONRpc provider to connect to Ganache, since the Web3.js HTTPProvider does not react to contract events.

I left the client.js using Web3.js for reference.