SlideShare a Scribd company logo
web3j
Web3 Java Ðapp API
@conors10
Ethereum integration
challenges
• Smart contract application binary interface
encoders/decoders
• 256 bit numeric types
• Multiple transaction types
• Wallet management
• …
web3j
• Complete Ethereum JSON-RPC implementation
• Sync/async & RX Observable API
• Ethereum wallet support
• Smart contract wrappers
• Command line tools
• Android compatible
web3j
JSON-RPC
• Full implementations:
• Ethereum client API
• Parity & Geth Personal (admin) APIs
Using web3j
• Create client
Web3j web3 = Web3j.build(new HttpService());
// defaults to http://localhost:8545/
• Call JSON-RPC method
web3.<method name>([param1, …, paramN).
[send()|sendAsync()|observable()]
web3j installation
• 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
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.6.1-stable-021c3c28/
darwin-amd64/go1.8.1
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
Command line tools
• Send Ether + manage wallet files
$ web3j wallet send ~/.ethereum/keystore/<walletfile> 0x<destination address>
_ _____ _ _
| | |____ (_) (_)
__ _____| |__ / /_ _ ___
  / / / _  '_    | | | / _ 
 V V / __/ |_) |.___/ / | _ | || (_) |
_/_/ ___|_.__/ ____/| |(_)|_| ___/
_/ |
|__/
Please enter your existing wallet file password:
Wallet for address 0x<source address> loaded
Please confirm address of running Ethereum client you wish to send the transfer request to [http://
localhost:8545/]: https://mainnet.infura.io/<infura token>
Connected successfully to client: Parity//v1.4.4-beta-a68d52c-20161118/x86_64-linux-gnu/rustc1.13.0
What amound would you like to transfer (please enter a numeric value): 10
Please specify the unit (ether, wei, ...) [ether]: ether
Please confim that you wish to transfer 10 ether (10000000000000000000 wei) to address 0x<destination
address>
Please type 'yes' to proceed: yes
Commencing transfer (this may take a few
minutes) ................................................................................................
............................$
Funds have been successfully transferred from 0x<source address> to 0x<destination address>
Transaction hash: 0x<tx hash>
Mined block number: 2673468
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
Smart contract wrappers
• Generate from Solidity ABI + binary files
• Java code to:
• Deploy
• Call
• Transact
Transactions
web3j transactions
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;
}
}
Greeter.abi[
{
"constant": true,
"inputs": [
],
"name": "greet",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"type": "function"
},
{
"inputs": [
{
"name": "_greeting",
"type": "string"
}
],
"type": "constructor"
},
...
]
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!
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());
});
Event callbacks
• Process events in smart contracts
HumanStandardToken contract = deploy(web3j, ALICE,
GAS_PRICE, GAS_LIMIT,
BigInteger.ZERO,
new Uint256(aliceQty), new Utf8String("web3j tokens"),
new Uint8(BigInteger.TEN), new Utf8String(“w3j$")).get();
contract.transferEventObservable(
<startBlock>, <endBlock>)
.subscribe(event -> {
…
});
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();
Replay transactions
Subscription subscription =
web3j.replayTransactionsObservable(
<startBlockNo>, <endBlockNo>)
.subscribe(tx -> {
...
});
Replay all + future
Subscription subscription =
web3j.catchUpToLatestAndSubscribeToNewBlocks
Observable(
<startBlockNo>, <fullTxObjects>)
.subscribe(blk -> {
...
});
Replay Performance
941667 blocks on Ropsten (14th June 2017):
• Blocks excluding transactions in 7m22s.
• Blocks including transactions in 41m16s
(2013 Macbook Pro)
web3j Overview
Further Information
• Project home https://web3j.io
• Useful resources http://docs.web3j.io/links.html
• Chat https://gitter.im/web3j/web3j
• Blog http://conorsvensson.com/
• https://blk.io

More Related Content

PDF
Web3j 2.0 Update
Conor Svensson
 
PDF
Building Java and Android apps on the blockchain
Conor Svensson
 
PDF
Java and the blockchain - introducing web3j
Conor Svensson
 
PDF
web3j overview
Conor Svensson
 
PDF
web3j 1.0 update
Conor Svensson
 
KEY
Socket.io
Antonio Terreno
 
PDF
Socket.IO
Davide Pedranz
 
KEY
Socket.io
Timothy Fitz
 
Web3j 2.0 Update
Conor Svensson
 
Building Java and Android apps on the blockchain
Conor Svensson
 
Java and the blockchain - introducing web3j
Conor Svensson
 
web3j overview
Conor Svensson
 
web3j 1.0 update
Conor Svensson
 
Socket.io
Antonio Terreno
 
Socket.IO
Davide Pedranz
 
Socket.io
Timothy Fitz
 

What's hot (20)

PPTX
The Ethereum Geth Client
Arnold Pham
 
PDF
Socket.io under the hood
Haokang Den
 
KEY
Jugando con websockets en nodeJS
Israel Gutiérrez
 
PPTX
Learning Solidity
Arnold Pham
 
PDF
Building interactivity with websockets
Wim Godden
 
PPTX
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
Stéphane ESCANDELL
 
PPTX
Cryptography In Silverlight
Barry Dorrans
 
KEY
Node worshop Realtime - Socket.io
Caesar Chi
 
DOCX
Chatting dengan beberapa pc laptop
yayaria
 
PDF
XoxzoテレフォニーAPI入門2017
Xoxzo Inc.
 
PDF
Ingredients for creating dapps
Stefaan Ponnet
 
PDF
WebSockets Jump Start
Haim Michael
 
PPTX
Web sockets Introduction
Sudhir Bastakoti
 
PDF
Realtime web applications with ExpressJS and SocketIO
Hüseyin BABAL
 
PDF
Concept of BlockChain & Decentralized Application
Seiji Takahashi
 
PDF
WebSockets, Unity3D, and Clojure
Josh Glover
 
PDF
JugTAAS ReSTful
Tiziano Lattisi
 
PDF
Build dapps 1:3 dev tools
Martin Köppelmann
 
PDF
Socket.io tech talk 06022014
rifqi alfian
 
PDF
Node.js introduction
Parth Joshi
 
The Ethereum Geth Client
Arnold Pham
 
Socket.io under the hood
Haokang Den
 
Jugando con websockets en nodeJS
Israel Gutiérrez
 
Learning Solidity
Arnold Pham
 
Building interactivity with websockets
Wim Godden
 
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
Stéphane ESCANDELL
 
Cryptography In Silverlight
Barry Dorrans
 
Node worshop Realtime - Socket.io
Caesar Chi
 
Chatting dengan beberapa pc laptop
yayaria
 
XoxzoテレフォニーAPI入門2017
Xoxzo Inc.
 
Ingredients for creating dapps
Stefaan Ponnet
 
WebSockets Jump Start
Haim Michael
 
Web sockets Introduction
Sudhir Bastakoti
 
Realtime web applications with ExpressJS and SocketIO
Hüseyin BABAL
 
Concept of BlockChain & Decentralized Application
Seiji Takahashi
 
WebSockets, Unity3D, and Clojure
Josh Glover
 
JugTAAS ReSTful
Tiziano Lattisi
 
Build dapps 1:3 dev tools
Martin Köppelmann
 
Socket.io tech talk 06022014
rifqi alfian
 
Node.js introduction
Parth Joshi
 
Ad

Similar to web3j Overview (20)

PDF
Smart contracts using web3.js
Felix Crisan
 
PDF
Blockchain Coding Dojo - BlockchainHub Graz
BlockchainHub Graz
 
PPTX
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Tomoaki Sato
 
PPTX
Introduction to Ethereum
Arnold Pham
 
PDF
DevEx in Ethereum - a look at the developer stack
All Things Open
 
PDF
Javascript toolset for Ethereum Smart Contract development
BugSense
 
PDF
The JavaScript toolset for development on Ethereum
GreeceJS
 
PPTX
The Foundation of Smart Contract Development on Ethereum
NAtional Institute of TEchnology Rourkela , Galgotias University
 
DOCX
BlockChain Online Training
Glory IT Technologies
 
DOCX
BlockChain Online Course
Prasanthi K
 
PDF
Introduction to Ethereum Smart Contracts
ArcBlock
 
PDF
Smart contracts in Solidity
Felix Crisan
 
PPTX
Ethereum
Brian Yap
 
PDF
20221110 MetaCoin
Hu Kenneth
 
DOCX
Web 3.docx
Anbhazhagan Deyennae
 
PDF
Ivy Block - technicals.pdf
TheBlockchainTeam
 
PDF
Developing Blockchain Applications
malikmayank
 
PPTX
Dapps 101
Katarzyna Jagieła
 
PPTX
Ethereum Block Chain
SanatPandoh
 
PPTX
CCS339 Unit IV is explained in detail for easy understanding
santhikala3
 
Smart contracts using web3.js
Felix Crisan
 
Blockchain Coding Dojo - BlockchainHub Graz
BlockchainHub Graz
 
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Tomoaki Sato
 
Introduction to Ethereum
Arnold Pham
 
DevEx in Ethereum - a look at the developer stack
All Things Open
 
Javascript toolset for Ethereum Smart Contract development
BugSense
 
The JavaScript toolset for development on Ethereum
GreeceJS
 
The Foundation of Smart Contract Development on Ethereum
NAtional Institute of TEchnology Rourkela , Galgotias University
 
BlockChain Online Training
Glory IT Technologies
 
BlockChain Online Course
Prasanthi K
 
Introduction to Ethereum Smart Contracts
ArcBlock
 
Smart contracts in Solidity
Felix Crisan
 
Ethereum
Brian Yap
 
20221110 MetaCoin
Hu Kenneth
 
Ivy Block - technicals.pdf
TheBlockchainTeam
 
Developing Blockchain Applications
malikmayank
 
Ethereum Block Chain
SanatPandoh
 
CCS339 Unit IV is explained in detail for easy understanding
santhikala3
 
Ad

More from Conor Svensson (6)

PDF
Blockchain - Navigating this Game-Changing Technology
Conor Svensson
 
PDF
Ether mining 101 v2
Conor Svensson
 
PDF
Cloud Native Microservices with Spring Cloud
Conor Svensson
 
PDF
Ether Mining 101
Conor Svensson
 
PDF
Cloud Native Microservices with Spring Cloud
Conor Svensson
 
PDF
Java Microservices with Netflix OSS & Spring
Conor Svensson
 
Blockchain - Navigating this Game-Changing Technology
Conor Svensson
 
Ether mining 101 v2
Conor Svensson
 
Cloud Native Microservices with Spring Cloud
Conor Svensson
 
Ether Mining 101
Conor Svensson
 
Cloud Native Microservices with Spring Cloud
Conor Svensson
 
Java Microservices with Netflix OSS & Spring
Conor Svensson
 

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
The Future of Artificial Intelligence (AI)
Mukul
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Software Development Methodologies in 2025
KodekX
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 

web3j Overview

  • 1. web3j Web3 Java Ðapp API @conors10
  • 2. Ethereum integration challenges • Smart contract application binary interface encoders/decoders • 256 bit numeric types • Multiple transaction types • Wallet management • …
  • 3. web3j • Complete Ethereum JSON-RPC implementation • Sync/async & RX Observable API • Ethereum wallet support • Smart contract wrappers • Command line tools • Android compatible
  • 5. JSON-RPC • Full implementations: • Ethereum client API • Parity & Geth Personal (admin) APIs
  • 6. Using web3j • Create client Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/ • Call JSON-RPC method web3.<method name>([param1, …, paramN). [send()|sendAsync()|observable()]
  • 7. web3j installation • 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
  • 8. 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.6.1-stable-021c3c28/ darwin-amd64/go1.8.1
  • 9. 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
  • 10. Command line tools • Send Ether + manage wallet files $ web3j wallet send ~/.ethereum/keystore/<walletfile> 0x<destination address> _ _____ _ _ | | |____ (_) (_) __ _____| |__ / /_ _ ___ / / / _ '_ | | | / _ V V / __/ |_) |.___/ / | _ | || (_) | _/_/ ___|_.__/ ____/| |(_)|_| ___/ _/ | |__/ Please enter your existing wallet file password: Wallet for address 0x<source address> loaded Please confirm address of running Ethereum client you wish to send the transfer request to [http:// localhost:8545/]: https://mainnet.infura.io/<infura token> Connected successfully to client: Parity//v1.4.4-beta-a68d52c-20161118/x86_64-linux-gnu/rustc1.13.0 What amound would you like to transfer (please enter a numeric value): 10 Please specify the unit (ether, wei, ...) [ether]: ether Please confim that you wish to transfer 10 ether (10000000000000000000 wei) to address 0x<destination address> Please type 'yes' to proceed: yes Commencing transfer (this may take a few minutes) ................................................................................................ ............................$ Funds have been successfully transferred from 0x<source address> to 0x<destination address> Transaction hash: 0x<tx hash> Mined block number: 2673468
  • 11. 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
  • 12. Smart contract wrappers • Generate from Solidity ABI + binary files • Java code to: • Deploy • Call • Transact
  • 15. 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; } }
  • 16. Greeter.abi[ { "constant": true, "inputs": [ ], "name": "greet", "outputs": [ { "name": "", "type": "string" } ], "payable": false, "type": "function" }, { "inputs": [ { "name": "_greeting", "type": "string" } ], "type": "constructor" }, ... ]
  • 17. 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/
  • 18. 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);
 } ...
  • 19. 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!
  • 20. 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()); });
  • 21. Event callbacks • Process events in smart contracts HumanStandardToken contract = deploy(web3j, ALICE, GAS_PRICE, GAS_LIMIT, BigInteger.ZERO, new Uint256(aliceQty), new Utf8String("web3j tokens"), new Uint8(BigInteger.TEN), new Utf8String(“w3j$")).get(); contract.transferEventObservable( <startBlock>, <endBlock>) .subscribe(event -> { … });
  • 22. 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();
  • 23. Replay transactions Subscription subscription = web3j.replayTransactionsObservable( <startBlockNo>, <endBlockNo>) .subscribe(tx -> { ... });
  • 24. Replay all + future Subscription subscription = web3j.catchUpToLatestAndSubscribeToNewBlocks Observable( <startBlockNo>, <fullTxObjects>) .subscribe(blk -> { ... });
  • 25. Replay Performance 941667 blocks on Ropsten (14th June 2017): • Blocks excluding transactions in 7m22s. • Blocks including transactions in 41m16s (2013 Macbook Pro)
  • 27. Further Information • Project home https://web3j.io • Useful resources http://docs.web3j.io/links.html • Chat https://gitter.im/web3j/web3j • Blog http://conorsvensson.com/ • https://blk.io