SlideShare a Scribd company logo
Java and the
Blockchain
Blockchain apps with web3j
@conors10
Decentralised
Immutable data structure
Blockchain Technologies
2008
2013
2014
2015+
Ethereum
• The world computer
• Turing-complete virtual machine
• Public blockchain (mainnet & testnet)
Ether
• The fuel of the Ethereum blockchain
• Pay miners to process transactions
• Market capitalisation ~$4.5bn USD (Bitcoin
~$20bn)
• Associated with an address + wallet file
0x19e03255f667bdfd50a32722df860b1eeaf4d635
1 Ether = $42.80 USD
Obtaining Ether
• Buy it
• Find someone
• Coinbase
• BTC Markets
• Mine it
• mainnet => requires dedicated GPUs
• testnet => quick using your CPU
• Refer to Geth/Parity mining docs
Smart Contracts
• Computerised contract
• Code + data that lives on the blockchain at an
address
• Transactions call functions => state transition
Transactions
• Transfer Ether
• Deploy a smart contract
• Call a smart contract
Transactions
Integration with Ethereum
web3j
• Complete Ethereum JSON-RPC implementation
• Sync/async & RX Observable API
• Ethereum wallet support
• Smart contract wrappers
• Command line tools
• Android compatible
web3j artefacts
• Maven’s Nexus & Bintray's JFrog repositories
• Java 8: org.web3j:core
• Android: org.web3j:core-android
• web3j releases page:
• Command line tools: web3j-<version>.zip
• Homebrew:
• brew tap web3j/web3j && brew install web3j
web3j transactions
Getting started with
Ethereum
Free cloud clients @ https://infura.io/
Run a local client (to generate Ether):
$ geth --rpcapi personal,db,eth,net,web3
--rpc --testnet
$ parity --chain testnet
Create a wallet
$ web3j wallet create
_ _____ _ _
| | |____ (_) (_)
__ _____| |__ / /_ _ ___
  / / / _  '_    | | | / _ 
 V V / __/ |_) |.___/ / | _ | || (_) |
_/_/ ___|_.__/ ____/| |(_)|_| ___/
_/ |
|__/
Please enter a wallet file password:
Please re-enter the password:
Please enter a destination directory location [/Users/Conor/
Library/Ethereum/testnet/keystore]: ~/testnet-keystore
Wallet file UTC--2016-11-10T22-52-35.722000000Z--
a929d0fe936c719c4e4d1194ae64e415c7e9e8fe.json successfully
created in: /Users/Conor/testnet-keystore
Wallet file{
"address":"a929d0fe936c719c4e4d1194ae64e415c7e9e8fe",
"id":"c2fbffdd-f588-43a8-9b0c-facb6fd84dfe",
"version":3,
"crypto":{
"cipher":"aes-128-ctr",
"ciphertext":"27be0c93939fc8262977c4454a6b7c261c931dfd8c030b2d3e60ef76f99bfdc6",
"cipherparams":{
"iv":"5aa4fdc64eef6bd82621c6036a323c41"
},
"kdf":"scrypt",
"kdfparams":{
"dklen":32,
"n":262144,
"p":1,
"r":8,
"salt":"6ebc76f30ee21c9a05f907a1ad1df7cca06dd594cf6c537c5e6c79fa88c9b9d1"
},
"mac":"178eace46da9acbf259e94141fbcb7d3d43041e2ec546cd4fe24958e55a49446"
}
}
View transactions
Using web3j
• Create client
Web3j web3 = Web3j.build(new HttpService());
// defaults to http://localhost:8545/
• Call method
web3.<method name>([param1, …, paramN).
[send()|sendAsync()|observable()]
Display client version
Web3j web3 = Web3j.build(new HttpService());
Web3ClientVersion clientVersion =
web3.web3ClientVersion()
.sendAsync().get();
System.out.println(“Client version: “ +
clientVersion.getWeb3ClientVersion());
Client version: Geth/v1.4.18-stable-c72f5459/
darwin/go1.7.3
Sending Ether
Web3j web3 = Web3j.build(new HttpService());
Credentials credentials = WalletUtils.loadCredentials(
"password", "/path/to/walletfile");
TransactionReceipt transactionReceipt =
Transfer.sendFundsAsync(
web3,
credentials, “0x<to address>",
BigDecimal.valueOf(0.2),
Convert.Unit.ETHER).get();
System.out.println(“Funds transfer completed…” + …);
Funds transfer completed, transaction hash:
0x16e41aa9d97d1c3374a4cb9599febdb24d4d5648b607c99e01a8
e79e3eab2c34, block number: 1840479
Block #1840479
web3j + RxJava
• Reactive-functional API
• Observables for all Ethereum client methods
Web3j web3 = Web3j.build(new HttpService()); //
defaults to http://localhost:8545/
web3j.web3ClientVersion().observable().subscribe(
x -> {
System.out.println(x.getWeb3ClientVersion());
});
Processing all new blocks
Web3j web3 = Web3j.build(new HttpService());
Subscription subscription =
web3j.blockObservable(false)
.subscribe(block -> {
System.out.println(
"Sweet, block number " +
block.getBlock().getNumber() +
" has just been created");
}, Throwable::printStackTrace);
TimeUnit.MINUTES.sleep(2);
subscription.unsubscribe();
Ethereum Smart Contracts
• Usually written in Solidity
• Statically typed high level language
• Compiled to Ethereum Virtual Machine (EVM) byte
code
• Create Java wrappers with web3j
Greeter.sol
contract mortal {
address owner;
function mortal() { owner = msg.sender; }
function kill() { if (msg.sender == owner) suicide(owner); }
}
contract greeter is mortal {
string greeting;
// constructor
function greeter(string _greeting) public {
greeting = _greeting;
}
// getter
function greet() constant returns (string) {
return greeting;
}
}
Smart Contract Wrappers
• Compile
$ solc Greeter.sol --bin --abi --
optimize -o build/
• Generate wrappers
$ web3j solidity generate build/
greeter.bin build/greeter.abi -p
org.web3j.example.generated -o src/main/
java/
Greeter.java
public final class Greeter extends Contract {

private static final String BINARY = “6060604052604....";

...



public Future<Utf8String> greet() {

Function function = new Function<Utf8String>("greet", 

Arrays.<Type>asList(), 

Arrays.<TypeReference<Utf8String>>asList(new
TypeReference<Utf8String>() {}));

return executeCallSingleValueReturnAsync(function);

}



public static Future<Greeter> deploy(Web3j web3j, Credentials
credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger
initialValue, Utf8String _greeting) {

String encodedConstructor =
FunctionEncoder.encodeConstructor(Arrays.<Type>asList(_greeting));

return deployAsync(Greeter.class, web3j, credentials,
gasPrice, gasLimit, BINARY, encodedConstructor, initialValue);

}
...
Hello Blockchain World!
Web3j web3 = Web3j.build(new HttpService());
Credentials credentials =
WalletUtils.loadCredentials(
"my password",
"/path/to/walletfile");
Greeter contract = Greeter.deploy(
web3, credentials, BigInteger.ZERO,
new Utf8String("Hello blockchain world!"))
.get();
Utf8String greeting = contract.greet().get();
System.out.println(greeting.getTypeAsString());
Hello blockchain world!
Smarter Contracts
Smarter Contracts
• Asset tokenisation
• Hold Ether
• EIP-20 smart contract token standard
• See web3j examples
Projects
• web3j-core
• web3j-android
• web3j Spring Boot Starter
• web3j-quorum
• JP Morgan’s private blockchain technology
web3j + Ethereum
• web3j simplifies working with Ethereum
• Plenty of documentation
• Smart contract integration tests
Further Information
• Project home https://web3j.io
• Mining http://docs.web3j.io/
transactions.html#obtaining-ether
• Useful resources http://docs.web3j.io/links.html
• Chat https://gitter.im/web3j/web3j
• Blog http://conorsvensson.com/
Join us

More Related Content

What's hot

Tcs
TcsTcs
Tcs
srpj30
 
Wipro Infrastructure Engineering Company Presentation - July, 2015
Wipro Infrastructure Engineering Company Presentation -  July, 2015Wipro Infrastructure Engineering Company Presentation -  July, 2015
Wipro Infrastructure Engineering Company Presentation - July, 2015
Wipro Infrastructure Engineering
 
My dream company project
My dream company projectMy dream company project
My dream company project
Albin Panalickal
 
Virtual reality
Virtual realityVirtual reality
Virtual reality
Shakib Sarar Arnab
 
Virtual Reality Presentation BY BMS B
Virtual Reality Presentation BY BMS BVirtual Reality Presentation BY BMS B
Virtual Reality Presentation BY BMS B
Basavaraj Shetty
 
Tcs company-details
Tcs company-detailsTcs company-details
Tcs company-details
sanju_ss1987
 
A project report on effectiveness of mentoring system in ongc
A project report on effectiveness of mentoring system in ongcA project report on effectiveness of mentoring system in ongc
A project report on effectiveness of mentoring system in ongc
Projects Kart
 
Virtual Reality
Virtual RealityVirtual Reality
Virtual Reality
Steffi Keran Rani J
 
合同会社エンジニアリングマネージメント会社・事業説明資料
合同会社エンジニアリングマネージメント会社・事業説明資料合同会社エンジニアリングマネージメント会社・事業説明資料
合同会社エンジニアリングマネージメント会社・事業説明資料
Tsuyoshi Hisamatsu
 
2016 Virtual Reality Presentation
2016 Virtual Reality Presentation2016 Virtual Reality Presentation
2016 Virtual Reality Presentation
Dave Jones
 
Augmented Reality: Merging Our Real World WIth The Virtual
Augmented Reality: Merging Our Real World WIth The VirtualAugmented Reality: Merging Our Real World WIth The Virtual
Augmented Reality: Merging Our Real World WIth The Virtual
Lynne d Johnson
 
VR in manufacturing
VR in manufacturingVR in manufacturing
VR in manufacturing
Dr. Stylianos Kampakis
 
Tata consultancy services
Tata consultancy servicesTata consultancy services
Tata consultancy services
ruchi mundi
 
Sixth Sense Seminar ppt
Sixth Sense Seminar pptSixth Sense Seminar ppt
Sixth Sense Seminar ppt
shwetha shwet
 
Vision Pro and visionOS.pptx with GIPHY
Vision Pro and visionOS.pptx with GIPHYVision Pro and visionOS.pptx with GIPHY
Vision Pro and visionOS.pptx with GIPHY
RohanDalmotra
 
Top 5 mnc profile
Top 5 mnc profileTop 5 mnc profile
Top 5 mnc profile
NISHANT JAIN
 
Screenless display
Screenless displayScreenless display
Screenless display
Abhilash Seth
 
Virtual reality Presentation
Virtual reality PresentationVirtual reality Presentation
Virtual reality PresentationAnand Akshay
 

What's hot (20)

Tcs
TcsTcs
Tcs
 
Wipro Infrastructure Engineering Company Presentation - July, 2015
Wipro Infrastructure Engineering Company Presentation -  July, 2015Wipro Infrastructure Engineering Company Presentation -  July, 2015
Wipro Infrastructure Engineering Company Presentation - July, 2015
 
My dream company project
My dream company projectMy dream company project
My dream company project
 
Virtual reality
Virtual realityVirtual reality
Virtual reality
 
Virtual Reality Presentation BY BMS B
Virtual Reality Presentation BY BMS BVirtual Reality Presentation BY BMS B
Virtual Reality Presentation BY BMS B
 
Tcs company-details
Tcs company-detailsTcs company-details
Tcs company-details
 
A project report on effectiveness of mentoring system in ongc
A project report on effectiveness of mentoring system in ongcA project report on effectiveness of mentoring system in ongc
A project report on effectiveness of mentoring system in ongc
 
Virtual Reality
Virtual RealityVirtual Reality
Virtual Reality
 
合同会社エンジニアリングマネージメント会社・事業説明資料
合同会社エンジニアリングマネージメント会社・事業説明資料合同会社エンジニアリングマネージメント会社・事業説明資料
合同会社エンジニアリングマネージメント会社・事業説明資料
 
2016 Virtual Reality Presentation
2016 Virtual Reality Presentation2016 Virtual Reality Presentation
2016 Virtual Reality Presentation
 
Jet aiwyas
Jet aiwyasJet aiwyas
Jet aiwyas
 
Augmented Reality: Merging Our Real World WIth The Virtual
Augmented Reality: Merging Our Real World WIth The VirtualAugmented Reality: Merging Our Real World WIth The Virtual
Augmented Reality: Merging Our Real World WIth The Virtual
 
VR in manufacturing
VR in manufacturingVR in manufacturing
VR in manufacturing
 
VR
VR VR
VR
 
Tata consultancy services
Tata consultancy servicesTata consultancy services
Tata consultancy services
 
Sixth Sense Seminar ppt
Sixth Sense Seminar pptSixth Sense Seminar ppt
Sixth Sense Seminar ppt
 
Vision Pro and visionOS.pptx with GIPHY
Vision Pro and visionOS.pptx with GIPHYVision Pro and visionOS.pptx with GIPHY
Vision Pro and visionOS.pptx with GIPHY
 
Top 5 mnc profile
Top 5 mnc profileTop 5 mnc profile
Top 5 mnc profile
 
Screenless display
Screenless displayScreenless display
Screenless display
 
Virtual reality Presentation
Virtual reality PresentationVirtual reality Presentation
Virtual reality Presentation
 

Similar to Building Java and Android apps on the blockchain

web3j Overview
web3j Overviewweb3j Overview
web3j Overview
Conor Svensson
 
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereumDappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Tomoaki Sato
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso
 
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
 
Concept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized ApplicationConcept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized Application
Seiji Takahashi
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
Yakov Fain
 
sbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computersbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computer
Steve Waldman
 
Blockchain Workshop - Software Freedom Day 2017
Blockchain Workshop - Software Freedom Day 2017Blockchain Workshop - Software Freedom Day 2017
Blockchain Workshop - Software Freedom Day 2017
Zied GUESMI
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
Emanuel Mota
 
NET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxNET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptx
petabridge
 
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
병완 임
 
Go 1.8 'new' networking features
Go 1.8 'new' networking featuresGo 1.8 'new' networking features
Go 1.8 'new' networking features
strikr .
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
Arnout Kazemier
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwrdeimos
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
How to Create AltCoin(Alternative Cryptocurrency)?
How to Create AltCoin(Alternative Cryptocurrency)?How to Create AltCoin(Alternative Cryptocurrency)?
How to Create AltCoin(Alternative Cryptocurrency)?
Abdullah Khan Zehady
 
Build your own private blockchain based on ethereum
Build your own private blockchain based on ethereumBuild your own private blockchain based on ethereum
Build your own private blockchain based on ethereum
Mehran Pourvahab
 
Geth important commands
Geth important commandsGeth important commands
Geth important commands
NexThoughts Technologies
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
Ohad Kravchick
 

Similar to Building Java and Android apps on the blockchain (20)

web3j Overview
web3j Overviewweb3j Overview
web3j Overview
 
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereumDappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Java and the blockchain - introducing web3j
Java and the blockchain - introducing web3jJava and the blockchain - introducing web3j
Java and the blockchain - introducing web3j
 
Concept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized ApplicationConcept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized Application
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
sbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computersbt-ethereum: a terminal for the world computer
sbt-ethereum: a terminal for the world computer
 
Blockchain Workshop - Software Freedom Day 2017
Blockchain Workshop - Software Freedom Day 2017Blockchain Workshop - Software Freedom Day 2017
Blockchain Workshop - Software Freedom Day 2017
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
 
NET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxNET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptx
 
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
 
Go 1.8 'new' networking features
Go 1.8 'new' networking featuresGo 1.8 'new' networking features
Go 1.8 'new' networking features
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
How to Create AltCoin(Alternative Cryptocurrency)?
How to Create AltCoin(Alternative Cryptocurrency)?How to Create AltCoin(Alternative Cryptocurrency)?
How to Create AltCoin(Alternative Cryptocurrency)?
 
Build your own private blockchain based on ethereum
Build your own private blockchain based on ethereumBuild your own private blockchain based on ethereum
Build your own private blockchain based on ethereum
 
Geth important commands
Geth important commandsGeth important commands
Geth important commands
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 

More from Conor Svensson

Web3j 2.0 Update
Web3j 2.0 UpdateWeb3j 2.0 Update
Web3j 2.0 Update
Conor Svensson
 
Blockchain - Navigating this Game-Changing Technology
Blockchain - Navigating this Game-Changing TechnologyBlockchain - Navigating this Game-Changing Technology
Blockchain - Navigating this Game-Changing Technology
Conor Svensson
 
web3j 1.0 update
web3j 1.0 updateweb3j 1.0 update
web3j 1.0 update
Conor Svensson
 
Ether mining 101 v2
Ether mining 101 v2Ether mining 101 v2
Ether mining 101 v2
Conor Svensson
 
web3j overview
web3j overviewweb3j overview
web3j overview
Conor Svensson
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring Cloud
Conor Svensson
 
Ether Mining 101
Ether Mining 101Ether Mining 101
Ether Mining 101
Conor Svensson
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring Cloud
Conor Svensson
 
Java Microservices with Netflix OSS & Spring
Java Microservices with Netflix OSS & Spring Java Microservices with Netflix OSS & Spring
Java Microservices with Netflix OSS & Spring
Conor Svensson
 

More from Conor Svensson (9)

Web3j 2.0 Update
Web3j 2.0 UpdateWeb3j 2.0 Update
Web3j 2.0 Update
 
Blockchain - Navigating this Game-Changing Technology
Blockchain - Navigating this Game-Changing TechnologyBlockchain - Navigating this Game-Changing Technology
Blockchain - Navigating this Game-Changing Technology
 
web3j 1.0 update
web3j 1.0 updateweb3j 1.0 update
web3j 1.0 update
 
Ether mining 101 v2
Ether mining 101 v2Ether mining 101 v2
Ether mining 101 v2
 
web3j overview
web3j overviewweb3j overview
web3j overview
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring Cloud
 
Ether Mining 101
Ether Mining 101Ether Mining 101
Ether Mining 101
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring Cloud
 
Java Microservices with Netflix OSS & Spring
Java Microservices with Netflix OSS & Spring Java Microservices with Netflix OSS & Spring
Java Microservices with Netflix OSS & Spring
 

Recently uploaded

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 

Building Java and Android apps on the blockchain

  • 1. Java and the Blockchain Blockchain apps with web3j @conors10
  • 5.
  • 6. Ethereum • The world computer • Turing-complete virtual machine • Public blockchain (mainnet & testnet)
  • 7. Ether • The fuel of the Ethereum blockchain • Pay miners to process transactions • Market capitalisation ~$4.5bn USD (Bitcoin ~$20bn) • Associated with an address + wallet file 0x19e03255f667bdfd50a32722df860b1eeaf4d635
  • 8. 1 Ether = $42.80 USD
  • 9. Obtaining Ether • Buy it • Find someone • Coinbase • BTC Markets • Mine it • mainnet => requires dedicated GPUs • testnet => quick using your CPU • Refer to Geth/Parity mining docs
  • 10. Smart Contracts • Computerised contract • Code + data that lives on the blockchain at an address • Transactions call functions => state transition
  • 11. Transactions • Transfer Ether • Deploy a smart contract • Call a smart contract
  • 14. web3j • Complete Ethereum JSON-RPC implementation • Sync/async & RX Observable API • Ethereum wallet support • Smart contract wrappers • Command line tools • Android compatible
  • 15. web3j artefacts • Maven’s Nexus & Bintray's JFrog repositories • Java 8: org.web3j:core • Android: org.web3j:core-android • web3j releases page: • Command line tools: web3j-<version>.zip • Homebrew: • brew tap web3j/web3j && brew install web3j
  • 17. Getting started with Ethereum Free cloud clients @ https://infura.io/ Run a local client (to generate Ether): $ geth --rpcapi personal,db,eth,net,web3 --rpc --testnet $ parity --chain testnet
  • 18. Create a wallet $ web3j wallet create _ _____ _ _ | | |____ (_) (_) __ _____| |__ / /_ _ ___ / / / _ '_ | | | / _ V V / __/ |_) |.___/ / | _ | || (_) | _/_/ ___|_.__/ ____/| |(_)|_| ___/ _/ | |__/ Please enter a wallet file password: Please re-enter the password: Please enter a destination directory location [/Users/Conor/ Library/Ethereum/testnet/keystore]: ~/testnet-keystore Wallet file UTC--2016-11-10T22-52-35.722000000Z-- a929d0fe936c719c4e4d1194ae64e415c7e9e8fe.json successfully created in: /Users/Conor/testnet-keystore
  • 21. Using web3j • Create client Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/ • Call method web3.<method name>([param1, …, paramN). [send()|sendAsync()|observable()]
  • 22. Display client version Web3j web3 = Web3j.build(new HttpService()); Web3ClientVersion clientVersion = web3.web3ClientVersion() .sendAsync().get(); System.out.println(“Client version: “ + clientVersion.getWeb3ClientVersion()); Client version: Geth/v1.4.18-stable-c72f5459/ darwin/go1.7.3
  • 23. Sending Ether Web3j web3 = Web3j.build(new HttpService()); Credentials credentials = WalletUtils.loadCredentials( "password", "/path/to/walletfile"); TransactionReceipt transactionReceipt = Transfer.sendFundsAsync( web3, credentials, “0x<to address>", BigDecimal.valueOf(0.2), Convert.Unit.ETHER).get(); System.out.println(“Funds transfer completed…” + …); Funds transfer completed, transaction hash: 0x16e41aa9d97d1c3374a4cb9599febdb24d4d5648b607c99e01a8 e79e3eab2c34, block number: 1840479
  • 24.
  • 26. web3j + RxJava • Reactive-functional API • Observables for all Ethereum client methods Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/ web3j.web3ClientVersion().observable().subscribe( x -> { System.out.println(x.getWeb3ClientVersion()); });
  • 27. Processing all new blocks Web3j web3 = Web3j.build(new HttpService()); Subscription subscription = web3j.blockObservable(false) .subscribe(block -> { System.out.println( "Sweet, block number " + block.getBlock().getNumber() + " has just been created"); }, Throwable::printStackTrace); TimeUnit.MINUTES.sleep(2); subscription.unsubscribe();
  • 28. Ethereum Smart Contracts • Usually written in Solidity • Statically typed high level language • Compiled to Ethereum Virtual Machine (EVM) byte code • Create Java wrappers with web3j
  • 29. Greeter.sol contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; // constructor function greeter(string _greeting) public { greeting = _greeting; } // getter function greet() constant returns (string) { return greeting; } }
  • 30. Smart Contract Wrappers • Compile $ solc Greeter.sol --bin --abi -- optimize -o build/ • Generate wrappers $ web3j solidity generate build/ greeter.bin build/greeter.abi -p org.web3j.example.generated -o src/main/ java/
  • 31. Greeter.java public final class Greeter extends Contract {
 private static final String BINARY = “6060604052604....";
 ...
 
 public Future<Utf8String> greet() {
 Function function = new Function<Utf8String>("greet", 
 Arrays.<Type>asList(), 
 Arrays.<TypeReference<Utf8String>>asList(new TypeReference<Utf8String>() {}));
 return executeCallSingleValueReturnAsync(function);
 }
 
 public static Future<Greeter> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialValue, Utf8String _greeting) {
 String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(_greeting));
 return deployAsync(Greeter.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor, initialValue);
 } ...
  • 32. Hello Blockchain World! Web3j web3 = Web3j.build(new HttpService()); Credentials credentials = WalletUtils.loadCredentials( "my password", "/path/to/walletfile"); Greeter contract = Greeter.deploy( web3, credentials, BigInteger.ZERO, new Utf8String("Hello blockchain world!")) .get(); Utf8String greeting = contract.greet().get(); System.out.println(greeting.getTypeAsString()); Hello blockchain world!
  • 34. Smarter Contracts • Asset tokenisation • Hold Ether • EIP-20 smart contract token standard • See web3j examples
  • 35.
  • 36. Projects • web3j-core • web3j-android • web3j Spring Boot Starter • web3j-quorum • JP Morgan’s private blockchain technology
  • 37. web3j + Ethereum • web3j simplifies working with Ethereum • Plenty of documentation • Smart contract integration tests
  • 38. Further Information • Project home https://web3j.io • Mining http://docs.web3j.io/ transactions.html#obtaining-ether • Useful resources http://docs.web3j.io/links.html • Chat https://gitter.im/web3j/web3j • Blog http://conorsvensson.com/