Sunday, February 4, 2018

Connect to Ethereum geth client using web3j

Introduction video to web3j
https://www.youtube.com/watch?v=ea3miXs_P6Y

Blockchain - Using cryptocurrency with Java

http://www.javamagazine.mozaicreader.com/JanFeb2017/Default/36/0#&pageSet=36&page=0&contentItem=0

 

Reactive-Functional Fun on the Blockchain with web3j

https://community.oracle.com/docs/DOC-1011373


Ethereum Geth client

 
 
https://geth.ethereum.org/docs/install-and-build/installing-geth#most-linux-systems-and-macos


Web3j
https://web3j.io/
https://github.com/web3j/web3j 

Install Ethereum client

Get Golang and geth code
dnf install golang

git clone https://github.com/ethereum/go-ethereum.git

Compile geth client
[dave@localhost go-ethereum]$ make
build/env.sh go run build/ci.go install ./cmd/geth
>>> /usr/lib/golang/bin/go install -ldflags -X main.gitCommit=0662384d294eaa44390799747db030e8d401111d -v ./cmd/geth
github.com/ethereum/go-ethereum/common/hexutil
github.com/ethereum/go-ethereum/crypto/sha3
github.com/ethereum/go-ethereum/common/math
github.com/ethereum/go-ethereum/rlp
github.com/ethereum/go-ethereum/crypto/secp256k1
github.com/ethereum/go-ethereum/vendor/github.com/go-stack/stack
github.com/ethereum/go-ethereum/log
github.com/ethereum/go-ethereum/vendor/github.com/rcrowley/go-metrics
github.com/ethereum/go-ethereum/vendor/gopkg.in/karalabe/cookiejar.v2/collections/prque
github.com/ethereum/go-ethereum/common
github.com/ethereum/go-ethereum/vendor/github.com/aristanetworks/goarista/monotime
github.com/ethereum/go-ethereum/common/mclock
github.com/ethereum/go-ethereum/event
github.com/ethereum/go-ethereum/params
github.com/ethereum/go-ethereum/crypto/randentropy
github.com/ethereum/go-ethereum/vendor/github.com/pborman/uuid
github.com/ethereum/go-ethereum/vendor/golang.org/x/sys/unix
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/pbkdf2
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/scrypt
github.com/ethereum/go-ethereum/vendor/gopkg.in/fatih/set.v0
github.com/ethereum/go-ethereum/cmd/internal/browser
github.com/ethereum/go-ethereum/common/fdlimit
github.com/ethereum/go-ethereum/vendor/github.com/rcrowley/go-metrics/exp
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/util
github.com/ethereum/go-ethereum/metrics
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/cache
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/comparer
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/storage
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/filter
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/opt
github.com/ethereum/go-ethereum/vendor/github.com/golang/snappy
github.com/ethereum/go-ethereum/vendor/github.com/rjeczalik/notify
github.com/ethereum/go-ethereum/vendor/github.com/hashicorp/golang-lru/simplelru
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/errors
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/iterator
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/journal
github.com/ethereum/go-ethereum/vendor/github.com/hashicorp/golang-lru
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/memdb
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/table
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/context
github.com/ethereum/go-ethereum/vendor/github.com/rs/xhandler
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/websocket
github.com/ethereum/go-ethereum/vendor/github.com/rs/cors
github.com/ethereum/go-ethereum/vendor/github.com/edsrzf/mmap-go
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb
github.com/ethereum/go-ethereum/common/bitutil
github.com/ethereum/go-ethereum/crypto/bn256
github.com/ethereum/go-ethereum/rpc
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/ripemd160
github.com/ethereum/go-ethereum/vendor/github.com/elastic/gosigar
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/httpu
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/scpd
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/soap
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/ssdp
github.com/ethereum/go-ethereum/ethdb
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html/atom
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/internal/identifier
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/transform
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/internal/utf8internal
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/internal/tag
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/runes
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/internal
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/language
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/charmap
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/japanese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/korean
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/simplifiedchinese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/traditionalchinese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/unicode
github.com/ethereum/go-ethereum/vendor/github.com/jackpal/go-nat-pmp
github.com/ethereum/go-ethereum/p2p/netutil
github.com/ethereum/go-ethereum/eth/tracers/internal/tracers
github.com/ethereum/go-ethereum/vendor/gopkg.in/olebedev/go-duktape.v3
github.com/ethereum/go-ethereum/vendor/github.com/golang/protobuf/proto
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/htmlindex
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html/charset
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/dcps/internetgateway1
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/dcps/internetgateway2
github.com/ethereum/go-ethereum/vendor/github.com/golang/protobuf/protoc-gen-go/descriptor
github.com/ethereum/go-ethereum/p2p/nat
github.com/ethereum/go-ethereum/accounts/usbwallet/internal/trezor
github.com/ethereum/go-ethereum/vendor/github.com/karalabe/hid
github.com/ethereum/go-ethereum/log/term
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-colorable
github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1
github.com/ethereum/go-ethereum/internal/debug
github.com/ethereum/go-ethereum/vendor/github.com/prometheus/prometheus/util/flock
github.com/ethereum/go-ethereum/les/flowcontrol
github.com/ethereum/go-ethereum/vendor/golang.org/x/sync/syncmap
github.com/ethereum/go-ethereum/internal/jsre/deps
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-isatty
github.com/ethereum/go-ethereum/vendor/github.com/fatih/color
# github.com/ethereum/go-ethereum/vendor/gopkg.in/olebedev/go-duktape.v3
In file included from vendor/gopkg.in/olebedev/go-duktape.v3/api.go:7:0:
vendor/gopkg.in/olebedev/go-duktape.v3/api.go: In function ‘_duk_error’:
vendor/gopkg.in/olebedev/go-duktape.v3/duktape.h:510:127: warning: right-hand operand of comma expression has no effect [-Wunused-value]
  (duk_error_raw((ctx), (duk_errcode_t) (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__), (duk_ret_t) 0)
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
vendor/gopkg.in/olebedev/go-duktape.v3/api.go:153:2: note: in expansion of macro ‘duk_error’
  duk_error(ctx, err_code, "%s", str);
  ^~~~~~~~~
github.com/ethereum/go-ethereum/vendor/gopkg.in/sourcemap.v1/base64vlq
github.com/ethereum/go-ethereum/vendor/gopkg.in/sourcemap.v1
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/file
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/token
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/ast
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/dbg
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/parser
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/registry
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto
github.com/ethereum/go-ethereum/crypto
github.com/ethereum/go-ethereum/trie
github.com/ethereum/go-ethereum/core/types
github.com/ethereum/go-ethereum/crypto/ecies
github.com/ethereum/go-ethereum/p2p/discover
github.com/ethereum/go-ethereum
github.com/ethereum/go-ethereum/accounts
github.com/ethereum/go-ethereum/accounts/keystore
github.com/ethereum/go-ethereum/core/state
github.com/ethereum/go-ethereum/core/vm
github.com/ethereum/go-ethereum/p2p/discv5
github.com/ethereum/go-ethereum/consensus
github.com/ethereum/go-ethereum/consensus/misc
github.com/ethereum/go-ethereum/consensus/clique
github.com/ethereum/go-ethereum/consensus/ethash
github.com/ethereum/go-ethereum/core
github.com/ethereum/go-ethereum/p2p
github.com/ethereum/go-ethereum/core/bloombits
github.com/ethereum/go-ethereum/eth/fetcher
github.com/ethereum/go-ethereum/accounts/usbwallet
github.com/ethereum/go-ethereum/dashboard
github.com/ethereum/go-ethereum/node
github.com/ethereum/go-ethereum/whisper/whisperv5
github.com/ethereum/go-ethereum/eth/downloader
github.com/ethereum/go-ethereum/eth/filters
github.com/ethereum/go-ethereum/light
github.com/ethereum/go-ethereum/internal/jsre
github.com/ethereum/go-ethereum/internal/ethapi
github.com/ethereum/go-ethereum/miner
github.com/ethereum/go-ethereum/internal/web3ext
github.com/ethereum/go-ethereum/vendor/github.com/peterh/liner
github.com/ethereum/go-ethereum/eth/gasprice
github.com/ethereum/go-ethereum/ethclient
github.com/ethereum/go-ethereum/vendor/github.com/maruel/panicparse/stack
github.com/ethereum/go-ethereum/console
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-runewidth
github.com/ethereum/go-ethereum/vendor/github.com/mitchellh/go-wordwrap
github.com/ethereum/go-ethereum/vendor/github.com/nsf/termbox-go
github.com/ethereum/go-ethereum/vendor/github.com/naoina/go-stringutil
github.com/ethereum/go-ethereum/vendor/github.com/naoina/toml/ast
github.com/ethereum/go-ethereum/vendor/github.com/gizak/termui
github.com/ethereum/go-ethereum/vendor/github.com/naoina/toml
github.com/ethereum/go-ethereum/eth/tracers
github.com/ethereum/go-ethereum/eth
github.com/ethereum/go-ethereum/les
github.com/ethereum/go-ethereum/ethstats
github.com/ethereum/go-ethereum/cmd/utils
github.com/ethereum/go-ethereum/cmd/geth
Done building.
Run "/home/dave/github/go-ethereum/build/bin/geth" to launch geth.



Start geth client
[dave@localhost go-ethereum]$ /home/dave/github/go-ethereum/build/bin/geth --fast --cache=512 --rpcapi personal,db,eth,net,web3 --rpc --testnet
INFO [02-04|06:34:54] Starting peer-to-peer node               instance=Geth/v1.8.0-unstable-0662384d/linux-amd64/go1.8.5
INFO [02-04|06:34:54] Allocated cache and file handles         database=/home/dave/.ethereum/testnet/geth/chaindata cache=512 handles=512
INFO [02-04|06:34:55] Writing custom genesis block 
INFO [02-04|06:34:55] Initialised chain configuration          config="{ChainID: 3 Homestead: 0 DAO: <nil> DAOSupport: true EIP150: 0 EIP155: 10 EIP158: 10 Byzantium: 1700000 Engine: ethash}"
INFO [02-04|06:34:55] Disk storage enabled for ethash caches   dir=/home/dave/.ethereum/testnet/geth/ethash count=3
INFO [02-04|06:34:55] Disk storage enabled for ethash DAGs     dir=/home/dave/.ethash                       count=2
INFO [02-04|06:34:55] Initialising Ethereum protocol           versions="[63 62]" network=3
INFO [02-04|06:34:55] Loaded most recent local header          number=0 hash=419410…ca4a2d td=1048576
INFO [02-04|06:34:55] Loaded most recent local full block      number=0 hash=419410…ca4a2d td=1048576
INFO [02-04|06:34:55] Loaded most recent local fast block      number=0 hash=419410…ca4a2d td=1048576
INFO [02-04|06:34:55] Regenerated local transaction journal    transactions=0 accounts=0
INFO [02-04|06:34:55] Starting P2P networking 
INFO [02-04|06:34:57] UDP listener up                          self=enode://9bbc55ed1cca170be4cba9c3ea9e22322680d2f9cdd7e363591d2a6738e55707cb58fa64764c9b1ead28174dbec81ec5721cb2452e625de6292fe36881d672a2@89.233.189.164:30303
INFO [02-04|06:34:57] RLPx listener up                         self=enode://9bbc55ed1cca170be4cba9c3ea9e22322680d2f9cdd7e363591d2a6738e55707cb58fa64764c9b1ead28174dbec81ec5721cb2452e625de6292fe36881d672a2@89.233.189.164:30303
INFO [02-04|06:34:57] IPC endpoint opened: /home/dave/.ethereum/testnet/geth.ipc 
INFO [02-04|06:34:57] HTTP endpoint opened: http://127.0.0.1:8545 


Geth client running
INFO [02-04|07:06:39] Imported new state entries               count=273 elapsed=8.868µs processed=273 pending=4369 retry=0 duplicate=0 unexpected=0
INFO [02-04|07:06:39] Imported new block headers               count=0   elapsed=8.269ms number=83814 hash=94033d…457655 ignored=192
INFO [02-04|07:06:39] Imported new block receipts              count=4   elapsed=659.004µs bytes=3957 number=83626 hash=ba23b3…b7e218 ignored=0
INFO [02-04|07:06:40] Imported new block receipts              count=33  elapsed=4.361ms   bytes=33409 number=83659 hash=5eb979…3e5a58 ignored=0
INFO [02-04|07:06:40] Imported new block headers               count=0   elapsed=7.208ms   number=84006 hash=aee4cb…1bb757 ignored=192
INFO [02-04|07:06:40] Imported new block receipts              count=155 elapsed=35.627ms  bytes=89944 number=83814 hash=94033d…457655 ignored=0
INFO [02-04|07:06:40] Imported new block receipts              count=192 elapsed=9.058ms   bytes=130405 number=84006 hash=aee4cb…1bb757 ignored=0


Connect to client using https://web3j.io/

Web3j code samples
https://github.com/web3j/examples/blob/master/rx/src/main/java/org/web3j/examples/rx/Main.java

Maven sample project
https://github.com/JacqMT/web3j-maven-example/blob/master/pom.xml

Clone sample project
git clone https://github.com/JacqMT/web3j-maven-example


Compile test project using
[dave@localhost web3j-maven-example]$ mvn install
[INFO] Scanning for projects...
[WARNING] 
[[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building web3j-maven-example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ web3j-maven-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/dave/github/web3j-maven-example/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ web3j-maven-example ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 4 source files to /home/dave/github/web3j-maven-example/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ web3j-maven-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/dave/github/web3j-maven-example/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ web3j-maven-example ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ web3j-maven-example ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ web3j-maven-example ---
[INFO] Building jar: /home/dave/github/web3j-maven-example/target/web3j-maven-example-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ web3j-maven-example ---
[INFO] Installing /home/dave/github/web3j-maven-example/target/web3j-maven-example-1.0-SNAPSHOT.jar to /home/dave/.m2/repository/org/train/web3j-maven-example/1.0-SNAPSHOT/web3j-maven-example-1.0-SNAPSHOT.jar
[INFO] Installing /home/dave/github/web3j-maven-example/pom.xml to /home/dave/.m2/repository/org/train/web3j-maven-example/1.0-SNAPSHOT/web3j-maven-example-1.0-SNAPSHOT.pom



[dave@localhost web3j-maven-example]$ ls -R
.:
contracts  LICENSE  pom.xml  README.md  src  tutorial-images

./contracts:
build  solidity

./contracts/build:
greeter.abi  greeter.bin  mortal.abi  mortal.bin

./contracts/solidity:
Greeter.sol

./src:
main

./src/main:
java

./src/main/java:
org

./src/main/java/org:
train  web3j

./src/main/java/org/train:
FundsService.java  Greeting.java  VersionFinder.java

./src/main/java/org/web3j:
example

./src/main/java/org/web3j/example:
generated

./src/main/java/org/web3j/example/generated:
Greeter.java

./tutorial-images:
'Generate a Wallet.png'           'Rinkeby EtherScan.png'             'Setting Contract Value Output.png'
'Greetings Output.png'            'Rinkeby Faucet.png'                'Starting Local Ethereum Node.png'
'Local Node Sync Status.png'      'Sending Funds Local Node Log.png'  'VersionFinder Output.png'
'Rinkeby EtherScan Overview.png'  'Sending Funds Output.png'



Display version of Ethereum geth  client
[dave@localhost web3j-maven-example]$ mvn exec:java -Dexec.mainClass="org.train.VersionFinder"

Client version: Geth/v1.8.0-unstable-0662384d/linux-amd64/go1.8.5
Network version: 3


Download web3j CLI tools
https://github.com/web3j/web3j/releases/tag/v3.2.0

 Create  wallet
[dave@localhost bin]$ ./web3j wallet create

              _      _____ _     _        
             | |    |____ (_)   (_)       
__      _____| |__      / /_     _   ___  
\ \ /\ / / _ \ '_ \     \ \ |   | | / _ \ 
 \ V  V /  __/ |_) |.___/ / | _ | || (_) |
  \_/\_/ \___|_.__/ \____/| |(_)|_| \___/ 
                         _/ |             
                        |__/              

Please enter a wallet file password: 
Please re-enter the password: 
Please enter a destination directory location [/home/dave/.ethereum/testnet/keystore]: 
Wallet file UTC--2018-02-04T06-34-14.95000000Z--1234567890123456789012345678.json successfully created in: /home/dave/.ethereum/testnet/keystore


Check transactions on testnet
https://rinkeby.etherscan.io/address/

Getting ether from https://www.rinkeby.io/ "Crypto Faucet"
https://gist.github.com/cryptogoth/10a98e8078cfd69f7ca892ddbdcf26bc

Post wallet id on Google+ and then go to
https://www.rinkeby.io/#faucet

Check if Ether  transaction is properly finished on  https://rinkeby.etherscan.io/address/



Transaction Information
TxHash:
0xTX_HASH
TxReceipt Status: Success
Block Height: 1710713 (102 block confirmations)
TimeStamp: 25 mins ago (Feb-04-2018 07:48:00 AM +UTC)
From:  0xTO_WALLET_ADDRESS
To:0xFROM_WALLET_ADDRESS
Value: 3 Ether ($0.00)
Gas Limit: 21000
Gas Used By Txn: 21000
Gas Price: 0.000000004 Ether (4 Gwei)
Actual Tx Cost/Fee: 0.000084 Ether ($0.000000)
Cumulative Gas Used: 21000
Nonce: 5246


Block information


Block Information
  Height:     
   1710713  
  TimeStamp:     1 hr 4 mins ago (Feb-04-2018 07:48:00 AM +UTC)
  Transactions:     2 transactions and 0 contract internal transactions in this block
  Hash:     0xTX_HASH
  Parent Hash:     0xPARENT_TX_HASH
  Sha3Uncles:     0x1dcc4de8dec75d7aa45645645651b948a7413f0a142fd40d49347
  Mined By:     0xfc18cbc391de84dbd87466689f5dd91 in 15 secs
  Difficulty:     2
  Total Difficulty:     3,188,999
  Size:     864 bytes
  Gas Used:     5,033,664 (71.90%)
  Gas Limit:     7,001,200
  Nonce:     0x0000000000000000
  Block Reward:     0 Ether
  Uncles Reward:     


Fully synchronize geth client

dave@localhost go-ethereum]$ /home/dave/github/go-ethereum/build/bin/geth --fast --cache=512 --rpcapi personal,db,eth,net,web3 --rpc --testnet
INFO [02-04|09:33:58] Starting peer-to-peer node               instance=Geth/v1.8.0-unstable-0662384d/linux-amd64/go1.8.5
INFO [02-04|09:33:58] Allocated cache and file handles         database=/home/dave/.ethereum/testnet/geth/chaindata cache=512 handles=512
INFO [02-04|09:34:00] Initialised chain configuration          config="{ChainID: 3 Homestead: 0 DAO: <nil> DAOSupport: true EIP150: 0 EIP155: 10 EIP158: 10 Byzantium: 1700000 Engine: ethash}"
INFO [02-04|09:34:00] Disk storage enabled for ethash caches   dir=/home/dave/.ethereum/testnet/geth/ethash count=3
INFO [02-04|09:34:00] Disk storage enabled for ethash DAGs     dir=/home/dave/.ethash                       count=2
INFO [02-04|09:34:01] Initialising Ethereum protocol           versions="[63 62]" network=3
INFO [02-04|09:34:01] Loaded most recent local header          number=926234 hash=a2bb1a…990d6c td=642817207095421
INFO [02-04|09:34:01] Loaded most recent local full block      number=0      hash=419410…ca4a2d td=1048576
INFO [02-04|09:34:01] Loaded most recent local fast block      number=913040 hash=9c0570…0f970a td=627371749055334
INFO [02-04|09:34:01] Loaded local transaction journal         transactions=0 dropped=0
INFO [02-04|09:34:01] Upgrading chain index                    type=bloombits percentage=70
INFO [02-04|09:34:01] Regenerated local transaction journal    transactions=0 accounts=0
INFO [02-04|09:34:01] Starting P2P networking 
INFO [02-04|09:34:05] UDP listener up                          self=enode://9bbc55ed1cca170be4cba9c3ea76765cca170226dd7e363591d2a6738e55707cb58fa64764c9b1ead28174dbec81ec5721cb2452e625de6292fe36881d672a2@89.233.189.164:30303
INFO [02-04|09:34:05] RLPx listener up                         self=enode://9bbc55ed1cca170be4cba9c322680d2f956565635956565738e55707cb58fa64764c9b1ead28174dbec81ec5721cb2452e625de6292fe36881d672a2@89.233.189.164:30303
INFO [02-04|09:34:05] IPC endpoint opened: /home/dave/.ethereum/testnet/geth.ipc 
INFO [02-04|09:34:05] HTTP endpoint opened: http://127.0.0.1:8545 



[dave@localhost go-ethereum]$ du -h  /home/dave/.ethereum/
2.8M    /home/dave/.ethereum/geth/chaindata
20K    /home/dave/.ethereum/geth/nodes
2.9M    /home/dave/.ethereum/geth
60M    /home/dave/.ethereum/testnet/geth/ethash
2.0G    /home/dave/.ethereum/testnet/geth/chaindata
6.2M    /home/dave/.ethereum/testnet/geth/nodes
2.0G    /home/dave/.ethereum/testnet/geth
8.0K    /home/dave/.ethereum/testnet/keystore
2.0G    /home/dave/.ethereum/testnet
4.0K    /home/dave/.ethereum/keystore
2.0G    /home/dave/.ethereum/



Without properly finished transaction you will get following error

java.util.concurrent.ExecutionException: java.lang.RuntimeException: Error processing transaction request: insufficient funds for gas * price + value


Run the test code
mvn exec:java -Dexec.mainClass="org.train.FundsService"

 
Transfer funds using web3j test code

package org.train;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.concurrent.ExecutionException;

import org.web3j.crypto.CipherException;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.WalletUtils;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.exceptions.TransactionTimeoutException;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.Transfer;
import org.web3j.utils.Convert;

public class FundsService {
    public static void main(String[] args) throws IOException, CipherException, InterruptedException,
                                                    ExecutionException, TransactionTimeoutException {
        Web3j web3 = Web3j.build(new HttpService());
        String walletId = "<WALLET_ADDRESS>";
        String walletSource = "/home/dave/.ethereum/testnet/keystore/UTC--2018-02-04T06-34-14.95000000Z--" + walletId + "" +
                ".json";
        Credentials credentials = WalletUtils.loadCredentials("<WALLET_PASSWORD>", walletSource);
        String myWalletAddr = "0x" + walletId;
        TransactionReceipt transactionReceipt = Transfer.sendFundsAsync(web3, credentials, myWalletAddr,
                BigDecimal.valueOf(0.2), Convert.Unit.ETHER).get();
        System.out.println("Funds transfer completed...");
        System.out.println("Hash: " + transactionReceipt.getBlockHash());
        System.out.println("Block number: " + transactionReceipt.getBlockNumber());
    }
}

2 comments:

  1. It is very good blog and useful for students and developer,Thanks for sharing

    Java Online Training Bangalore

    ReplyDelete
  2. Right away this website will probably definitely usually become well known with regards to most of website customers, due to the fact careful accounts and in addition tests. pagar boleto com bitcoin

    ReplyDelete