ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
ORACLES
Role of blockchain oracles
Oracle demo
5/7/2020
CONSULTING THE ORACLE
DEFINITION
Blockchain Oracles are third-party services that
provide smart contracts with external information.
They serve as bridges between blockchains and
the outside world.
WHAT ORACLES DO?
Provide information to the smart contracts on the blockchain
Translate information from outside platforms
Trigger smart contracts
Deliver information from smart contracts to outside world
ORACLES ON ETHEREUM
Ethereum
Network
Stock
Market
Data
Currency
Exchange
Rates
Bank
payments
Other
blockchains
Web API
IOT Events
MANY TYPES OF ORACLES
Software
Oracles
Inbound
Oracles
Hardware
Oracles
Outbound
Oracles
Consensus-
based Oracles
DEMO
Use case
Create oracle contract and
deploy to blockchain
Configure event listener
on IoT device
OPEN SESAME!
USE CASES
Seller
Put treasure is safe
Lock safe
Set unlock price in
smart contract
Pay on blockchain to
smart contract
Open safe
Get treasure
Buyer
ARCHITECTURE
User Interface Blockchain Raspberry Pi Safe
CREATE SMART CONTRACT IN
REMIX
OPEN SESAME SMART
CONTRCT
Oracle
SMART CONTRACT
pragma solidity >=0.4.22 <0.6.0;
contract OpenSesame{
enum State { Locked, Unlocked }
State public state;
uint public value; //value to unlock
address payable public seller;
event Unlock();
event Lock();
¡­
SMART CONTRACT (UNLOCK AND
LOCK FUNCTIONS)
function unlock()
public
inState(State.Locked)
condition(msg.value >
value)
payable
{
state = State.Unlocked;
emit Unlock();
}
function lock(uint _value)
public
onlySeller
inState(State.Unlocked)
{
value = _value;
state = State.Locked;
emit Lock();
}
DEPLOY TO TEST
NETWORK
GENERATE MNEMONIC
LOG IN TO METAMASK
CONNECT REMIX TO METAMASK
GET SOME TEST ETHER (1ETH)
COMPILE THE CONTRACT
REQUEST PUBLISHING THE
CONTRACT TO ROPSTEN TEST
NETWORK
AND ¡°PAY¡± FOR PUBLISHING THE
CONTRACT
WAIT FOR THE CONTRACT TO BE
PUBLISHED
PAY >1000 WEI TO UNLOCK
CONFIRM SENDING TRANSACTION
TO UNLOCK
CONFIRM ON ETHERSCAN THAT
EVENT WAS CREATED
LOCK AND SET UNLOCK FEE TO
10,000 WEI
CHECK THAT THE STATE IS 0
(LOCKED) AND VALUE IS SET TO
10,OOO (WEI)
IOT SIDE Raspberry PI
RASPBERRY PI ? Raspbian OS
? NodeJS
? Web3JS Node module
? Onoff Node module
SCHEMATICS AND REALITY
GET BALANCE ON SESAME
CONTRACT
const Web3 = require("web3")
const web3 = new Web3(new
Web3.providers.HttpProvider("https://ropsten.infura.io/v3/edb1d45f792244bfa97c13d84
a809090"))
web3.eth.getBalance("0x126A01a11b7fD2a4C7c62887af21D2C69FB29bd5", function(err,
result) {
if (err) {
console.log(err);
} else {
console.log("Account balance: " + result + " [WEI]");
}
})
LISTEN TO SESAME¡¯S EVENTS
const Web3 = require("web3");
const fs = require('fs¡¯);
const contractAddress =
"0x032D472C05ff870cf800dbaD
4B14A50c031432aB";
const web3 = new Web3(new
Web3.providers.WebsocketProvid
er("wss://ropsten.infura.io/ws/v
3/edb1d45f792244bfa97c13d84
a809090"))
var myContract = new
web3.eth.Contract(JSON.parse(ab
i), contractAddress);
console.log("Listening for events
on", contractAddress);
myContract.events.allEvents()
.on('data', (event) => {
console.log(event);
})
.on('error', console.error);
UNLOCK EVENT
LOCK EVENT
STAY IN TOUCH
Gene Leybzon https://www.linkedin.com/in/leybzon/
https://www.meetup.com/members/90744
20/
https://www.leybzon.com
CODE FOR THE EVENT LISTENER
1/3const Web3 = require("web3");
const fs = require('fs');
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var LED = new Gpio(23, 'out'); //use GPIO pin 18, and specify that it is output
var blinkInterval = setInterval(blinkLED, 250); //run the blinkLED function every 250ms
const contractAddress = "0x032D472C05ff870cf800dbaD4B14A50c031432aB";
function blinkLED() { //function to start blinking
if (LED.readSync() === 0) { //check the pin state, if the state is 0 (or off)
LED.writeSync(1); //set pin state to 1 (turn LED on)
} else {
LED.writeSync(0); //set pin state to 0 (turn LED off)
}
}
CODE FOR THE EVENT LISTENER
2/3function endBlink() { //function to stop blinking
clearInterval(blinkInterval); // Stop blink intervals
LED.writeSync(0); // Turn LED off
//LED.unexport(); // Unexport GPIO to free resources
}
endBlink();
var abi = fs.readFileSync('OpenSesame_sol_OpenSesame.abi', 'utf8');
//console.log("ABI", abi);
const web3 = new Web3(new
Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws/v3/edb1d45f792244bfa97c13d84
a809090"))
var myContract = new web3.eth.Contract(JSON.parse(abi), contractAddress);
console.log("Listening for events on", contractAddress);
CODE FOR THE EVENT LISTENER
3/3myContract.events.allEvents()
.on('data', (event) => {
console.log("Event:", event);
console.log("Event Type:", event.event);
if (event.event == "Unlock") {
console.log("Will unlock the safe");
blinkLED();
}
if (event.event == "Lock") {
console.log("Will lock the safe");
endBlink();
}
})
.on('error', console.error);

More Related Content

Similar to Oracles (20)

Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business ApplicationsEclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Matthias Zimmermann
?
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
Amarjeetsingh Thakur
?
Blockchain com JavaScript
Blockchain com JavaScriptBlockchain com JavaScript
Blockchain com JavaScript
Beto Muniz
?
Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018
Mikhail Kuznetcov
?
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso
?
web3j Overview
web3j Overviewweb3j Overview
web3j Overview
Conor Svensson
?
Socket.IO - Alternative Ways for Real-time Application
Socket.IO - Alternative Ways for Real-time ApplicationSocket.IO - Alternative Ways for Real-time Application
Socket.IO - Alternative Ways for Real-time Application
Vorakamol Choonhasakulchok
?
Solidity Contract: the code, compilation, deployment and accessing
Solidity Contract: the code, compilation, deployment and accessing Solidity Contract: the code, compilation, deployment and accessing
Solidity Contract: the code, compilation, deployment and accessing
KC Tam
?
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump Start
Haim Michael
?
Demystifying Apple 'Pie' & TouchID
Demystifying Apple 'Pie' & TouchIDDemystifying Apple 'Pie' & TouchID
Demystifying Apple 'Pie' & TouchID
Sebasti¨¢n Guerrero Selma
?
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.js
Felix Crisan
?
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksEssential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Amazon Web Services
?
Java and the blockchain - introducing web3j
Java and the blockchain - introducing web3jJava and the blockchain - introducing web3j
Java and the blockchain - introducing web3j
Conor Svensson
?
Building Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and GrizzlyBuilding Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and Grizzly
Justin Lee
?
Html5 websockets
Html5 websocketsHtml5 websockets
Html5 websockets
AbhishekMondal42
?
presentation in .net programming web sockets.pptx
presentation in .net programming web sockets.pptxpresentation in .net programming web sockets.pptx
presentation in .net programming web sockets.pptx
ArvieJayLapig
?
FIWARE Internet of Things
FIWARE Internet of ThingsFIWARE Internet of Things
FIWARE Internet of Things
Miguel Garc¨ªa Gonz¨¢lez
?
FIWARE Internet of Things
FIWARE Internet of ThingsFIWARE Internet of Things
FIWARE Internet of Things
Miguel Gonz¨¢lez
?
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Amazon Web Services
?
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
Wim Godden
?
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business ApplicationsEclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Matthias Zimmermann
?
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
Amarjeetsingh Thakur
?
Blockchain com JavaScript
Blockchain com JavaScriptBlockchain com JavaScript
Blockchain com JavaScript
Beto Muniz
?
Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018
Mikhail Kuznetcov
?
Socket.IO - Alternative Ways for Real-time Application
Socket.IO - Alternative Ways for Real-time ApplicationSocket.IO - Alternative Ways for Real-time Application
Socket.IO - Alternative Ways for Real-time Application
Vorakamol Choonhasakulchok
?
Solidity Contract: the code, compilation, deployment and accessing
Solidity Contract: the code, compilation, deployment and accessing Solidity Contract: the code, compilation, deployment and accessing
Solidity Contract: the code, compilation, deployment and accessing
KC Tam
?
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump Start
Haim Michael
?
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.js
Felix Crisan
?
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksEssential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Amazon Web Services
?
Java and the blockchain - introducing web3j
Java and the blockchain - introducing web3jJava and the blockchain - introducing web3j
Java and the blockchain - introducing web3j
Conor Svensson
?
Building Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and GrizzlyBuilding Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and Grizzly
Justin Lee
?
presentation in .net programming web sockets.pptx
presentation in .net programming web sockets.pptxpresentation in .net programming web sockets.pptx
presentation in .net programming web sockets.pptx
ArvieJayLapig
?
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Essential Capabilities of an IoT Cloud Platform - April 2017 AWS Online Tech ...
Amazon Web Services
?
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
Wim Godden
?

Recently uploaded (20)

Tenorshare 4uKey Crack Fre e Download
Tenorshare  4uKey  Crack  Fre e DownloadTenorshare  4uKey  Crack  Fre e Download
Tenorshare 4uKey Crack Fre e Download
oyv9tzurtx
?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
?
DevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdfDevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
?
EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]
bhagasufyan
?
Online Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi NcrOnline Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi Ncr
Home
?
AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio: Preprocessing, ...
AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio:  Preprocessing, ...AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio:  Preprocessing, ...
AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio: Preprocessing, ...
Alluxio, Inc.
?
Instagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo websiteInstagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo website
AxisTechnolabs
?
A Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman BhaumikA Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman Bhaumik
Raman Bhaumik
?
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
haroonsaeed605
?
Hire Odoo Developer ¨C OnestopDA Experts.
Hire Odoo Developer ¨C OnestopDA Experts.Hire Odoo Developer ¨C OnestopDA Experts.
Hire Odoo Developer ¨C OnestopDA Experts.
OnestopDA
?
How John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talkHow John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talk
Nacho Cougil
?
SE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.pptSE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.ppt
theworldimagine985
?
salesforce development services - Alt digital
salesforce development services - Alt digitalsalesforce development services - Alt digital
salesforce development services - Alt digital
Alt Digital Technologies
?
Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025
saniasabbba
?
Why Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your BusinessWhy Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your Business
Mypcot Infotech
?
Computer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .pptComputer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .ppt
jaysen110
?
Wondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free DownloadWondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free Download
arshadkhokher01
?
AI/ML Infra Meetup | How Uber Optimizes LLM Training and Finetune
AI/ML Infra Meetup | How Uber Optimizes LLM Training and FinetuneAI/ML Infra Meetup | How Uber Optimizes LLM Training and Finetune
AI/ML Infra Meetup | How Uber Optimizes LLM Training and Finetune
Alluxio, Inc.
?
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
Alluxio, Inc.
?
Douwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-LatestDouwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-Latest
mubeen010khan
?
Tenorshare 4uKey Crack Fre e Download
Tenorshare  4uKey  Crack  Fre e DownloadTenorshare  4uKey  Crack  Fre e Download
Tenorshare 4uKey Crack Fre e Download
oyv9tzurtx
?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
?
DevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdfDevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
?
EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]
bhagasufyan
?
Online Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi NcrOnline Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi Ncr
Home
?
AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio: Preprocessing, ...
AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio:  Preprocessing, ...AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio:  Preprocessing, ...
AI/ML Infra Meetup | Optimizing ML Data Access with Alluxio: Preprocessing, ...
Alluxio, Inc.
?
Instagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo websiteInstagram Feed Snippet, Instagram posts display in odoo website
Instagram Feed Snippet, Instagram posts display in odoo website
AxisTechnolabs
?
A Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman BhaumikA Brief Introduction About Raman Bhaumik
A Brief Introduction About Raman Bhaumik
Raman Bhaumik
?
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
haroonsaeed605
?
Hire Odoo Developer ¨C OnestopDA Experts.
Hire Odoo Developer ¨C OnestopDA Experts.Hire Odoo Developer ¨C OnestopDA Experts.
Hire Odoo Developer ¨C OnestopDA Experts.
OnestopDA
?
How John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talkHow John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talk
Nacho Cougil
?
SE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.pptSE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.ppt
theworldimagine985
?
salesforce development services - Alt digital
salesforce development services - Alt digitalsalesforce development services - Alt digital
salesforce development services - Alt digital
Alt Digital Technologies
?
Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025Adobe After Effects Crack latest version 2025
Adobe After Effects Crack latest version 2025
saniasabbba
?
Why Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your BusinessWhy Hire Python Developers? Key Benefits for Your Business
Why Hire Python Developers? Key Benefits for Your Business
Mypcot Infotech
?
Computer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .pptComputer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .ppt
jaysen110
?
Wondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free DownloadWondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free Download
arshadkhokher01
?
AI/ML Infra Meetup | How Uber Optimizes LLM Training and Finetune
AI/ML Infra Meetup | How Uber Optimizes LLM Training and FinetuneAI/ML Infra Meetup | How Uber Optimizes LLM Training and Finetune
AI/ML Infra Meetup | How Uber Optimizes LLM Training and Finetune
Alluxio, Inc.
?
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
Alluxio, Inc.
?
Douwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-LatestDouwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-Latest
mubeen010khan
?

Oracles

  • 1. ORACLES Role of blockchain oracles Oracle demo 5/7/2020
  • 3. DEFINITION Blockchain Oracles are third-party services that provide smart contracts with external information. They serve as bridges between blockchains and the outside world.
  • 4. WHAT ORACLES DO? Provide information to the smart contracts on the blockchain Translate information from outside platforms Trigger smart contracts Deliver information from smart contracts to outside world
  • 6. MANY TYPES OF ORACLES Software Oracles Inbound Oracles Hardware Oracles Outbound Oracles Consensus- based Oracles
  • 7. DEMO Use case Create oracle contract and deploy to blockchain Configure event listener on IoT device
  • 9. USE CASES Seller Put treasure is safe Lock safe Set unlock price in smart contract Pay on blockchain to smart contract Open safe Get treasure Buyer
  • 13. SMART CONTRACT pragma solidity >=0.4.22 <0.6.0; contract OpenSesame{ enum State { Locked, Unlocked } State public state; uint public value; //value to unlock address payable public seller; event Unlock(); event Lock(); ¡­
  • 14. SMART CONTRACT (UNLOCK AND LOCK FUNCTIONS) function unlock() public inState(State.Locked) condition(msg.value > value) payable { state = State.Unlocked; emit Unlock(); } function lock(uint _value) public onlySeller inState(State.Unlocked) { value = _value; state = State.Locked; emit Lock(); }
  • 17. LOG IN TO METAMASK
  • 18. CONNECT REMIX TO METAMASK
  • 19. GET SOME TEST ETHER (1ETH)
  • 21. REQUEST PUBLISHING THE CONTRACT TO ROPSTEN TEST NETWORK
  • 22. AND ¡°PAY¡± FOR PUBLISHING THE CONTRACT
  • 23. WAIT FOR THE CONTRACT TO BE PUBLISHED
  • 24. PAY >1000 WEI TO UNLOCK
  • 26. CONFIRM ON ETHERSCAN THAT EVENT WAS CREATED
  • 27. LOCK AND SET UNLOCK FEE TO 10,000 WEI
  • 28. CHECK THAT THE STATE IS 0 (LOCKED) AND VALUE IS SET TO 10,OOO (WEI)
  • 30. RASPBERRY PI ? Raspbian OS ? NodeJS ? Web3JS Node module ? Onoff Node module
  • 32. GET BALANCE ON SESAME CONTRACT const Web3 = require("web3") const web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/edb1d45f792244bfa97c13d84 a809090")) web3.eth.getBalance("0x126A01a11b7fD2a4C7c62887af21D2C69FB29bd5", function(err, result) { if (err) { console.log(err); } else { console.log("Account balance: " + result + " [WEI]"); } })
  • 33. LISTEN TO SESAME¡¯S EVENTS const Web3 = require("web3"); const fs = require('fs¡¯); const contractAddress = "0x032D472C05ff870cf800dbaD 4B14A50c031432aB"; const web3 = new Web3(new Web3.providers.WebsocketProvid er("wss://ropsten.infura.io/ws/v 3/edb1d45f792244bfa97c13d84 a809090")) var myContract = new web3.eth.Contract(JSON.parse(ab i), contractAddress); console.log("Listening for events on", contractAddress); myContract.events.allEvents() .on('data', (event) => { console.log(event); }) .on('error', console.error);
  • 36. STAY IN TOUCH Gene Leybzon https://www.linkedin.com/in/leybzon/ https://www.meetup.com/members/90744 20/ https://www.leybzon.com
  • 37. CODE FOR THE EVENT LISTENER 1/3const Web3 = require("web3"); const fs = require('fs'); var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO var LED = new Gpio(23, 'out'); //use GPIO pin 18, and specify that it is output var blinkInterval = setInterval(blinkLED, 250); //run the blinkLED function every 250ms const contractAddress = "0x032D472C05ff870cf800dbaD4B14A50c031432aB"; function blinkLED() { //function to start blinking if (LED.readSync() === 0) { //check the pin state, if the state is 0 (or off) LED.writeSync(1); //set pin state to 1 (turn LED on) } else { LED.writeSync(0); //set pin state to 0 (turn LED off) } }
  • 38. CODE FOR THE EVENT LISTENER 2/3function endBlink() { //function to stop blinking clearInterval(blinkInterval); // Stop blink intervals LED.writeSync(0); // Turn LED off //LED.unexport(); // Unexport GPIO to free resources } endBlink(); var abi = fs.readFileSync('OpenSesame_sol_OpenSesame.abi', 'utf8'); //console.log("ABI", abi); const web3 = new Web3(new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws/v3/edb1d45f792244bfa97c13d84 a809090")) var myContract = new web3.eth.Contract(JSON.parse(abi), contractAddress); console.log("Listening for events on", contractAddress);
  • 39. CODE FOR THE EVENT LISTENER 3/3myContract.events.allEvents() .on('data', (event) => { console.log("Event:", event); console.log("Event Type:", event.event); if (event.event == "Unlock") { console.log("Will unlock the safe"); blinkLED(); } if (event.event == "Lock") { console.log("Will lock the safe"); endBlink(); } }) .on('error', console.error);

Editor's Notes

  • #3: John William Waterhouse, 1884
  • #6: https://www.buybitcoinworldwide.com/ethereum/mining-pools/
  • #7: http://blockchainhub.net/blockchain-oracles/
  • #9: https://me.me/i/his-password-was-crypt-ic-bizarrocomics-com-open-sesame-our-uername-your-username-18507547
  • #12: https://remix.ethereum.org/
  • #15: https://github.com/leybzon/solidity-baby-steps/blob/master/contracts/95_open_sesame.sol
  • #17: https://iancoleman.io/bip39/
  • #19: We use Ropsten?Test Network
  • #20: https://faucet.ropsten.be/
  • #33: pi@raspberrypi:~ $ node app.js Account balance: 10000 [WEI]