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.
It gets the current BTC market cap from CoinGecko into a smart contract, using an oracle script.
- Truffle. I have it installed globally:
npm i -g truffle
- You'll need a developer blockchain, like
ethereumjs-testrpc
orGanache
- which is what I'm using. If yours runs on a different port/address, update thenetworks:development
section intruffle-config.js
accordingly.
- Clone this repo
- Install dependencies:
npm i
- Run your blockchain first, and wait for it to load
- Deploy the smart contract:
truffle migrate
- Run the Oracle:
npm run oracle
ornode src/oracle
- Open another terminal and run the client:
npm run client
ornode src/client
.
You'll need to run it twice to see the value change from 0.
Run truffle test
or node run test
.
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.