SlideShare une entreprise Scribd logo
1  sur  39
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);

Contenu connexe

Similaire à Oracles

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 ApplicationsMatthias 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 JavaScriptBeto 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 2018Mikhail Kuznetcov
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
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 ApplicationVorakamol 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 StartHaim Michael
 
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.jsFelix 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 TalksAmazon Web Services
 
Java and the blockchain - introducing web3j
Java and the blockchain - introducing web3jJava and the blockchain - introducing web3j
Java and the blockchain - introducing web3jConor 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 GrizzlyJustin Lee
 
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 websocketsWim Godden
 
以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界Amazon Web Services
 

Similaire à 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
 
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)
 
Blockchain com JavaScript
Blockchain com JavaScriptBlockchain com JavaScript
Blockchain com JavaScript
 
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
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
web3j Overview
web3j Overviewweb3j Overview
web3j Overview
 
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
 
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
 
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump Start
 
Demystifying Apple 'Pie' & TouchID
Demystifying Apple 'Pie' & TouchIDDemystifying Apple 'Pie' & TouchID
Demystifying Apple 'Pie' & TouchID
 
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.js
 
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
 
Java and the blockchain - introducing web3j
Java and the blockchain - introducing web3jJava and the blockchain - introducing web3j
Java and the blockchain - introducing web3j
 
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
 
Html5 websockets
Html5 websocketsHtml5 websockets
Html5 websockets
 
FIWARE Internet of Things
FIWARE Internet of ThingsFIWARE Internet of Things
FIWARE Internet of Things
 
FIWARE Internet of Things
FIWARE Internet of ThingsFIWARE Internet of Things
FIWARE Internet of Things
 
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 ...
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界
 

Dernier

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 

Dernier (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

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);

Notes de l'éditeur

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