This is an implementation of an Ethereum oracle using web3. An oracle is simply a messenger which relays data from one source to another.
- Node.js
- NPM
- Web3
- node-fetch
- Cron
Oracle.js consists of 2 core functions:
- update_oracle: This function fetches data from the api, which in this example is the average gas price for mined transactions on the main ethereum network. This is then set as the input for the setNumber function in the deployed sample smart contract. This input is set as the object for the second function (sendTx).
- sendTx: This function sets all the parameters for the transaction, signs the transaction and sends the transaction.
In order to deploy and test the oracle:
- Clone the repository.
- Set up an ethereum wallet with ropsten ether (metamask is easiest).
- Deploy "*.sol" (remix is easiest).
- Obtain a provider for the Ethereum network, you can run your own node via Ganache however for simplicity we are using Infura which is a public gateway to the blockchain.
- Run oracle_*.js.