Getting Set Up

In this lesson, you're going to create the JavaScript component of the oracle that fetches the ETH price from the Binance API. Then, you'll build a basic client that interacts with the oracle.

Take a look at the screen to the right. To get everything ready for you, we've:

Things to note:

☞ Spend a couple of minutes to give the code a read-through before moving on!

Instantiate the Oracle Contract

The build artifacts live inside of a JSON file, and we've imported them using the following line of code:

const OracleJSON = require('./oracle/build/contracts/EthPriceOracle.json')

As an example, based on the information stored in this file, your application knows that the setLatestEthPrice function takes three uint256s as arguments (_ethPrice_callerAddress, and _id), and it can create a transaction that calls this function.

But before that, interacting with a deployed contract from JavaScript requires you to instantiate it using the web3.eth.Contract. Let's look at an example to make the concept clear:

const myContract = new web3js.eth.Contract(myContractJSON.abi, myContractJSON.networks[networkId].address)

Note that the above example uses a variable called networkId that identifies the network on which your contract has been deployed. The networkId for Extdev is 9545242630824, so you could declare the networkId variable as follows:

const networkId = 9545242630824

Easy peasy! But no matter how simple the above line of code looks, it's not such a good idea to hardcode the identifier of the network like this. Why not? Well, because doing so would require you to update networkId every time your contract gets deployed to a different network.