What are Oracles
An Oracle is, simply put, a smart contract that is able to interact with the outside world, in the world of Ethereum that is known as off-chain.
Example
I didn't find a lot of examples on how to combine a front-end to a Ethereum oracle. So as a little side project I build a little starter pack. Hoping that it can serve as a starting point or example for other developers who want to play around with oracles!
It gets the current ETH/USD price from the Coinbase API and pulls it into the smart contract
The example includes the following technologies
- Vue-cli 3.2.1
- TypeScript (class style components)
- Smart contract example
- Oraclize
- Truffle
marlowl / ethereum-oraclize-starter
Basic Ethereum Oracle example, using Oraclize, Truffle, Vue and Web3
Ethereum Oraclize starter
Front-end is generated with vue-cli version 3.2.1
Basic Ethereum Oracle example including Oraclize, Truffle, Coinbase API, Web3
Demo
Get the current ETH/USD price from the Coinbase API through an Ethereum Oracle
Project setup
Install dependencies
npm install
Install Truffle (Works on the truffle version below, newer versions might get a compile error later on)
npm install -g truffle@4.1.15
Run Truffle develop (spawns a development blockchain)
truffle develop
Open a seperate terminal and run the ethereum-bridge (see package.json for what it does)
npm run bridge
Wait till it is fully loaded and you see the following message
Please add this line to your contract constructor
OAR = OraclizeAddrResolverI(address)
Compile the contract inside the Truffle develop console
truffle(develop)> compile
Migrate the contract also inside the Truffle develop console
truffle(develop)> migrate --development --reset
Get the contract address from the ethereum-bridge terminal
Output should be something like this
"contract_myid": "0x9fa87c542cab950bd129f3d2d13cba6199741bd1984351c04e83c54620dfee1b"
"contract_address":
…Enjoy!
Top comments (0)