0

web3 = Web3j.build(new HttpService());

         EthGetBalance ethGetBalance = web3.ethGetBalance("0xb34a5b6a39bceafeb8e23c2cc526889d85bf664e", DefaultBlockParameterName.LATEST).send();
         BigInteger balance = ethGetBalance.getBalance();
         System.out.println("balance - "+balance);

java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:8545 at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:225) at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:149) at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:195) at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121) at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:211) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) at okhttp3.RealCall.execute(RealCall.java:69) at org.web3j.protocol.http.HttpService.performIO(HttpService.java:106) at org.web3j.protocol.Service.send(Service.java:30) at org.web3j.protocol.core.Request.send(Request.java:68) at com.mobiloitte.coinbase.TestEthreum.createConnection(TestEthreum.java:56) at com.mobiloitte.coinbase.TestEthreum.main(TestEthreum.java:74) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at okhttp3.internal.platform.Platform.connectSocket(Platform.java:124) at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:223) ... 25 more

1 Answer 1

2

You should run node (geth for example) on your localhost and tell it to open rpc port

geth --rpc --rpcaddr 127.0.0.1 --rpcport 8545 --rpcapi="db,eth,net,web3,personal,debug" --rpccorsdomain "*"

Be carefull, using --rpccorsdomain "*" is a security issue

4
  • I am running the node i.e GETH @alexey
    – Aman Vyas
    Nov 16, 2017 at 11:42
  • @aman-vyas answer was edited Nov 16, 2017 at 11:54
  • Thank you @Alexey It worked for me and It will be great help what actually you mean by security issue can you provide any reference for it.. Thanks in advance
    – Aman Vyas
    Nov 17, 2017 at 5:17
  • @aman-vyas --rpccorsdomain "*" tells geth to accept connections from anywhere. Here is described this flag ethereum.stackexchange.com/a/8854/6041. Here is described what can happen ethereum.stackexchange.com/a/648/6041 Nov 17, 2017 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.