Skip to Content
Ethereum Cookbook
book

Ethereum Cookbook

by Manoj P R
August 2018
Intermediate to advanced
404 pages
11h 19m
English
Packt Publishing
Content preview from Ethereum Cookbook

How to do it...

  1. Solidity does not allow you to pull data from an external API source. Use an Oracle service to achieve this functionality.
  2. An oracle is an event listener that listens and responds to them by sending the results of a query back to the contract. In this way, contracts can interact with the external world.
  3. As an example, assume that we have a smart contract that uses an external data service to select a random number. Let's see how we can implement it using a custom Oracle service.
  4. Create a basic smart contract with a state variable to store the random number:
pragma solidity ^0.4.24;contract OracleRng {    uint public random;    ...}
  1. The Oracle service listens to the event logged in the contract and then uses the log details to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Ethereum Dapps

Building Ethereum Dapps

Roberto Infante
Ethereum For Dummies

Ethereum For Dummies

Michael G. Solomon

Publisher Resources

ISBN: 9781789133998Supplemental Content