34
Ethereum Smart Contracts in der Java-Welt Jan Paul Buchwald YOPITER GmbH Java Forum Stuttgart 2017, 06.07.2017

EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Ethereum Smart Contracts in der Java-Welt

Jan Paul BuchwaldYOPITER GmbH

Java Forum Stuttgart 2017, 06.07.2017

Page 2: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Agenda

1. Einführung:Blockchain, Ethereum Smart Contracts

2. Bewertung:Vorteile, Einsatzmöglichkeiten, Herausforderungen

3. Architektur und Technologien:Clients, Libraries, Integrationsszenarien

Page 3: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Blockchain

"an open, distributed ledger that can record transactions between two parties efficiently and in a verifiable and permanent way.”

Iansiti,Marco;Lakhani,KarimR.(Januar 2017)

Page 4: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Distributed Ledger

NodesMiners

Block n

Hash

Block n-1

Hash Txs

Tx Pool

Block n-2

Hash Txs

Validierung

Neue Transaktionen

ZusammenstellungTransaktionenin neuen Block

Page 5: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Ethereum Factsheet

§ Plattform zur Ausführung von Smart Contracts

§Basierend auf eigener öffentlicher Blockchain

§ Kryptowährung Ether (ETH) als Zahlungsmittel fürRechenleistung

§ Entstehung Ende 2013, produktiv seit 2015

§Open Source Entwicklung gesteuert von EthereumFoundation

Page 6: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Ethereum Smart Contract

§Auf der Ethereum Blockchain ausführbares Programm

§ Eigene Programmiersprachen kompilieren zu Bytecode undABI (Application Binary Interface)§ Solidity (~JavaScript Syntax mit C-Datentypen)§ Serpent (~Python)

§ LLL (~Lisp)

§Bytecode wird in Blockchain gespeichert und von EthereumVirtual Machine (EVM) auf jedem Node ausgeführt

Page 7: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Smart Contract Lebenszyklus

Ethereum Network

SmartContract

Adresse

Bytecode

Zustandsdaten

Contract Owner

Init

Node Node

Self-destruct

Immutable!

Page 8: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Beispiel Contract mit SolidityVariablen

Funktionen

Konstruktor

Page 9: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Contract ABI[

{"constant": true,"inputs": [],"name": "owner","outputs": [

{"name": "","type": "address"

}],"payable": false,"type": "function"

},{

"constant": false,"inputs": [

{"name": "id","type": "address"

}],"name": "store","outputs": [],"payable": false,"type": "function"

},. . .

. . .

{"constant": true,"inputs": [

{"name": "id","type": "address"

}],"name": "statusFor","outputs": [

{"name": "status","type": "uint256"

}],"payable": false,"type": "function"

},. . .]

Page 10: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Vorteile

§Öffentliche, manipulationssichere Datenablage und Ausführungsumgebung§ Vertrauen zwischen unbekannten Transaktionspartnern§ “Trusted 3rd Party” / “Middleman” kann entfallen

§ Keine Zutrittsbarrieren

§ Standardisierte dezentrale Umgebung kann Aufwand füreigene Infrastruktur reduzieren§ Serverless - “Freies Amazon Lambda mit Traceability und

eingebautem Zahlungssystem”

Page 11: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Einsatzmöglichkeiten

§Werttransfer§ Zahlungen/Verrechnung in Ether oder über eigene Kryptowährung§ (Teil-)automatische Zahlungsauslösung über Smart Contract Logik

§Authentizitätsnachweis§ Nutzung privater Schlüssel und Smart Contract Logik als

Identitätsnachweis§ Ablage von Nachweisen aus der realen Welt in der Blockchain

(Provenance)

Page 12: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Anwendungsbeispiel (ideal)Automatische Bezahlung von Paket-Lieferungen nachEmpfangsbestätigung

DeliveriesSmart Contract

Lieferservice

AktualisiertStatus

Empfänger

BestätigtEmpfang,Zahlung

Versender

EthereumNetwork

Status öffentlichund unveränderbarabgelegt

Zahlung

Page 13: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Herausforderung: Wallets und Kosten§ Jede Zustandsänderung/schreibende Operation im Smart Contract

bringt Transaktionskosten mit sich

§ Kosten fallen immer beim Auslöser der Transaktion an

§ Auslöser der Transaktion benötigt Wallet mit Guthaben

Smart Contract

KundeDienstanbieter

Page 14: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Herausforderung: Externe Daten

§ Smart Contract Code kann keine Daten außerhalb der Blockchain abfragen

§ Externe Informationen müssen immer aktiv von außen in den Smart Contract gebracht werden

§ Lösung: Oracles§ Vertrauenswürdiger Mensch oder Dienst ruft Funktion in Smart

Contract auf

Page 15: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Herausforderung: Datenmenge

§Blockchain ist keine Datenbank

§Hohe Gas-Kosten abhängig von§ Länge/Größe des Bytecodes§ Größe und Menge von gespeicherten Daten bei schreibenden

Operationen

§ Zusätzlich Limit für Transaktionsdaten

§ Lösungen: Speichern von Nutzdaten außerhalb der Blockchain, Hashing

Page 16: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Herausforderung: Skalierung

§Hoher Stromverbrauch durch Redundanz: Jeder Knoten§ führt alle Berechnungen durch§ speichert gesamte Blockchain§ validiert alle Transaktionen

§ Ethereum Blockchain§ Durchsatz ca. 15 Transaktionen / Sekunde§ Ca. 17 Sekunden Dauer für neuen Block

§ Lösungen: alternative Validierungsmechanismen, Offchain-Transaktionen

Page 17: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Anwendungsbeispiel (real)

DeliveriesSmart Contract

Lieferservice

Empfänger

Versender

EthereumNetwork

Tracking-Anwendung

Server

Status-DB

Öffentlicher Abgleichund Validierung Hashes

Page 18: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Clients und Schnittstellen

Ethereum Client / Node

JSON-RPC

EthereumNetwork

REST LibrariesCLI

geth (Go)Parity (Rust)eth (C++)pyethapp (Python)ethereumjs-lib ( JS)EthereumJ (Java)…

Page 19: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Java-Anwendung mit EthereumJ

Server / Desktop

EthereumNetwork

Java-Anwendung

Nutzer

EthereumJLibrary= Node

Page 20: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

EthereumJ

§ Java-Implementierungeines EthereumNodes

§ Kann als Dependency in eigene Anwendungeingebettet werden

Page 21: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Java-Anwendung und Ethereum Node

Server / Desktop

EthereumNode

EthereumNetwork

Java-Anwendung

Nutzer

JSON-RPCweb3j

Page 22: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

JSON-RPC Aufruf Ethereum Node

Page 23: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Smart Contract Interaktion in Java: web3j

§ Kommunikation mit Ethereum Node über Java Library

§ Java Klasse als Smart Contract Proxy

web3j Command LineTools zur Generierung

Page 24: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

web3j: Aufruf Smart Contract

Page 25: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Decentralized App (DApp)

Server

EthereumNode

EthereumNetwork

Web App

Nutzer

web3.jsBrowser mitWallet

Mist Browser

Browser

MetaMaskChrome Plugin

Page 26: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

web3.js

§ JavaScript Library zur Interaktion mit Ethereum Node

web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));

var abi = '[{"constant":true,"inputs":[] ...';var DeliverablesContract = web3.eth.contract(abi);

var deliverablesContractInstance = DeliverablesContract.at('0xc4ac...');

var deliveryAddress = '0xd4f...';

console.log(deliverablesContractInstance.statusFor(deliveryAddress));

deliverablesContractInstance.delivered(deliveryAddress, {value: 200});

Page 27: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Mobile App – Light Client

EthereumLight Client

EthereumNetwork

Nutzer

Native Android / iOS App

Smartphone

go-ethereumMobile Library(web3j)

Page 28: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Remote Ethereum Node API Services

EthereumNetwork

Mobile App

API Provider

EthereumNode

REST APIWeb App

Anwendung/API/ServiceEtherscan.ioBlockApps STRATOINFURA

Lesend + signierteTransaktionen

Page 29: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Zusammenfassung

§ Ethereum Smart Contracts eignen sich gut alsLösungsbausteine für Werttransfer und öffentlicheAuthentizitätsnachweise

§ Integration in eigene Lösung auf mehreren Ebenen möglich§ Embedded Ethereum Node mit EthereumJ§ Server-seitiger Ethereum Node und web3j Library§ Web App / Decentralized App mit web3js§ Native Mobile App mit Ethereum Light Client und Mobile Library§ Verwendung von Remote Ethereum Node API Services

Page 30: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Vielen Dank!

Jan-Paul Buchwald

YOPITER GmbH Stuttgart

[email protected]

https://www.yopiter.com http://blocklab.de

?

Page 31: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Quellenangaben

§ Verwendete Icons: Freepik from www.flaticon.com§ Produkte und Frameworks:

§ Ethereum Wiki https://github.com/ethereum/wiki/wiki§ Oraclize http://www.oraclize.it§ REALITY KEYS https://www.realitykeys.com§ Parity https://parity.io§ MetaMask https://metamask.io§ EthereumJ https://github.com/ethereum/ethereumj§ Web3j https://github.com/web3j/web3j§ Etherscan https://etherscan.io§ BlockApps STRATO http://blockapps.net§ INFURA https://infura.io

Page 32: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Quellenangaben

§ Artikel und Blogs:§ “An entrepreneur, programmer and user walk into a smart contract — The

ultimate Ethereum blockchain startup guide”https://hackernoon.com/an-entrepreneur-programmer-and-user-walk-into-a-smart-contract-the-ultimate-ethereum-blockchain-7b8dbd0c8463

§ “Blockchain – The Next Big Thing for Middleware” https://www.infoq.com/articles/blockchain-middleware

§ “Interfacing with Ethereum Smart Contracts in Java” https://medium.com/yopiter/interfacing-with-ethereum-smart-contracts-in-java-cf39b2e95b4e

Page 33: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Alternative: eth-contract-api

§ Library mit weitererAbstraktion fürEthereumJ und web3j

§Arbeitet ebenfalls mitSmart Contract Proxy Objekten

Page 34: EthereumSmart Contracts in der Java-Welt · Blockchain "an open, distributed ledgerthat can record transactionsbetween two parties efficiently and in a verifiable and permanentway.”

Decentralized Apps