<p>The issue is that you are trying to connect BitcoinJ to Bitcoin Core's RPC interface. However BitcoinJ is not a RPC client, it's a separate node(ish) implementation that connects to other nodes using the P2P protocol. The P2P interface and the RPC interface are separate and use different protocols, you cannot connect one to the other and expect them to work.</p>
<p>This issue can be solved by having BitcoinJ connect to port 10000 as that is the port that you have configured Bitcoin Core to listen on for P2P connections.</p>

CC BY-SA 4.0
2022-11-06T15:14:56.773Z
2022-11-06T15:14:56.773Z
Ava Chow
<p>I am running Bitcoin Network on local Ubuntu machine. The network consists of multiple nodes. I want to connect to the network from a java application running on the same machine via JSON RPC. I can connect to the Bitcoind server from command line using bitcoin-cli. However, i cannot connect to the Bitcoind server from the Java application using Bitcoinj Libraray. I suspect that the problem is related to RPC authentication. I specified rpc username and password in the bitcoin.conf file and I tried to use Java Authenticator in my Java code. However, it hasn't solved the problem.</p>
<pre><code>  Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication()
 { return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
                }});
</code></pre>
<p>My bitcoin.conf file is as follows:</p>
<pre><code>regtest=1
server=1
listen=1
rpcuser=user
rpcpassword=password
fallbackfee=0.0001
[regtest]
port=10000
rpcport=20000
bind=127.0.0.1
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
</code></pre>
<p>This is the log message I see when i start the Bitcoind server:
<a href="https://i.sstatic.net/ttEyH.png" rel="nofollow noreferrer">Server Log</a></p>
<ul>
<li>List item</li>
</ul>
<p><a href="https://i.sstatic.net/84WvF.png" rel="nofollow noreferrer">Server Log</a></p>
<p>And this is the error I am receiving on the application side:
<a href="https://i.sstatic.net/6jbUQ.png" rel="nofollow noreferrer">Application side error message</a></p>
<p>I am using Bitcoin core version 22 for the server and Bitcoinj library version 16.1 (<a href="https://bitcoinj.org/getting-started" rel="nofollow noreferrer">https://bitcoinj.org/getting-started</a>) to connect to the server</p>

CC BY-SA 4.0
2022-09-02T20:28:59.540Z
Are you trying to connect to regtest? If so, you've specified a custom `rpcport`, does your Java code try to connect to that port?
Ava Chow
CC BY-SA 4.0
2022-09-03T08:39:55.977Z
@AndrewChow yes, i am trying to connect to a regtest network using the new rpcport I specified in the bitcoin.conf file.
J.A
CC BY-SA 4.0
2022-11-06T10:22:07.273Z
Is there anyone who can help with this issue? @AndrewChow Any idea? Thanks
J.A
<bitcoind><json-rpc><bitcoinj>
Localhost peer not detected error when trying to connect to Bitcoind server via JSON RPC from Java Application
J.A
# Localhost peer not detected error when trying to connect to Bitcoind server via JSON RPC from Java Application

(Asked by: username_0 on 2022-08-20)

I am running Bitcoin Network on local Ubuntu machine. The network consists of multiple nodes. I want to connect to the network from a java application running on the same machine via JSON RPC. I can connect to the Bitcoind server from command line using bitcoin-cli. However, i cannot connect to the Bitcoind server from the Java application using Bitcoinj Libraray. I suspect that the problem is related to RPC authentication. I specified rpc username and password in the bitcoin.conf file and I tried to use Java Authenticator in my Java code. However, it hasn't solved the problem.

```
  Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication()
 { return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
                }});

```

My bitcoin.conf file is as follows:

```
regtest=1
server=1
listen=1
rpcuser=user
rpcpassword=password
fallbackfee=0.0001
[regtest]
port=10000
rpcport=20000
bind=127.0.0.1
rpcbind=127.0.0.1
rpcallowip=127.0.0.1

```

This is the log message I see when i start the Bitcoind server:
[Server Log](https://i.sstatic.net/ttEyH.png)

* List item

[Server Log](https://i.sstatic.net/84WvF.png)

And this is the error I am receiving on the application side:
[Application side error message](https://i.sstatic.net/6jbUQ.png)

I am using Bitcoin core version 22 for the server and Bitcoinj library version 16.1 (<https://bitcoinj.org/getting-started>) to connect to the server

**Tags:** bitcoind, json-rpc, bitcoinj

> **Comments:**
> **username_1**: Are you trying to connect to regtest? If so, you've specified a custom `rpcport`, does your Java code try to connect to that port?  
> **username_0**: @AndrewChow yes, i am trying to connect to a regtest network using the new rpcport I specified in the bitcoin.conf file.  
> **username_0**: Is there anyone who can help with this issue? @AndrewChow Any idea? Thanks  

---

## 1 answers

### Answer by username_1 on 2022-11-06. Score: 1

The issue is that you are trying to connect BitcoinJ to Bitcoin Core's RPC interface. However BitcoinJ is not a RPC client, it's a separate node(ish) implementation that connects to other nodes using the P2P protocol. The P2P interface and the RPC interface are separate and use different protocols, you cannot connect one to the other and expect them to work.

This issue can be solved by having BitcoinJ connect to port 10000 as that is the port that you have configured Bitcoin Core to listen on for P2P connections.


---

