Look for the line that looks like:

OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)

Note

If you’re using a different mnemonic than the standard Truffle one, the ETH address shown in between the round brackets will be different.

Make sure you write down (copy paste) the complete OAR line, so we can use it in the constructor of our contract later. Again, leave your terminal running.

At this point you should have 2 active terminal windows:

Your Truffle develop testnet

Your ethereum-bridge

Write the Solidity Smart Contract

Let’s get started with a sample Smart Contract. Look for the contracts folder in the oraclize-test folder and add a new file OraclizeTest.sol . This will become the Smart Contract that sends transactions to the Oracle to fetch API data. Copy paste the following gist into the file:

Note

Make sure you replace the OAR = OraclizeAddrResolverI(0x...); line with the one you wrote down in the previous step.

Don’t forget to remove this OAR variable from your constructor before production, this is just for testing, in production it will automatically fetch the OAR depending on the chain you’re running it, currently the Mainnet, Ropsten, and browser-solidity VM environment are supported.

OraclizeTest.sol

Upon contract creation, the OraclizeTest() constructor is being run, which sets the owner to the address deploying the contract and initialises the Oracle. Afterwards, it calls the update() function once to fetch the current ETH price from the Coinbase API.

The update() function checks if the contract holds enough funds to create an URL request, and continues to make the request to Oraclize if it has.

The __callback() function is being called by Oraclize as soon as the request has completed, you can use JSONPATH to slice the response. See documentation here.

We can use the first parameter id in the __callback() function to handle different requests. We’ll be skipping this, as this is only a basic example.

Compile the code

Look for the contracts folder in oraclize-test and delete ConvertLib.sol and MetaCoin.sol . These are example files, we won’t be needing them.

Copy paste the contract code mentioned above into OraclizeTest.sol and compile the code using

$ truffle compile

If it compiled successfully, you should see a new folder in oraclize-test called build . This folder contains the compiled version of your Smart Contracts. In it, you’ll find some *,json files that contain the bytecode that will be deployed by Truffle.

Now, let’s prepare Truffle to deploy our code to our development testnet.