Bitcoin Core – Error: Unable to start HTTP server. See the debug log for more details. – Bitcoin Stack Exchange
Unable to bind (to port).
The endpoint of the RPC server could not be bound.
This is a very common error in all kinds of network services. The most common cause is that there is already another service bound to the port (8332 in this case) or the user lacks permissions.
You can check which service is bound to port 8332 using something like: netstat -anp
Command.
binding error
The following examples are for Windows, but the Linux commands have only minor differences (for example, using grep instead of findstr).
One way to check if an existing process is using a port is:
C> netstat -anb | findstr /N "bitcoin 8332"
63: (bitcoind.exe)
65: (bitcoind.exe)
67: (bitcoind.exe)
69: (bitcoind.exe)
70: TCP 127.0.0.1:8332 0.0.0.0:0 LISTENING
71: (bitcoind.exe)
132: TCP (::1):8332 (::):0 LISTENING
133: (bitcoind.exe)
The above indicates that bitcoind is already running, listening to the network on port 8332 and waiting for requests.
RPC testing
You can test basic connectivity as follows:
C> curl http://localhost:8332/
JSONRPC server handles only POST requests
I intentionally do not send credentials or valid requests. But bitcoind takes the request and tells you what it doesn’t like. This proves that the bitcoind HTTP service is working. is it so ~ no I get a connection refused message from curl.
Here’s an example that shows passing credentials and getting an error message:
C> curl -v -u user:pass -d '"method":"getblockhash","params":(0),"id":1' http://localhost:8332/
* Trying 127.0.0.1:8332...
* Connected to localhost (127.0.0.1) port 8332 (#0)
* Server auth using Basic with user 'user'
> POST / HTTP/1.1
> Host: localhost:8332
> Authorization: Basic dG9kYXk6dGVtcG9yYXJ5
> User-Agent: curl/8.0.1
> Accept: */*
> Content-Length: 39
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 500 Internal Server Error
< Content-Type: application/json
< Date: Sun, 16 Jul 2023 14:27:47 GMT
< Content-Length: 74
<
"result":null,"error":"code":-32700,"message":"Parse error","id":null
* Connection #0 to host localhost left intact
In this case, an HTTP 500 error occurs because bitcoind cannot parse the data.
Must be specified. -v
You’ll need to check the HTTP error message, but if the JSON response works, you don’t need to. You can remove the -v option to reduce confusion.
Changed the quotation from single quotes to double quotes. You don’t need to do this on Linux. This is a Windows feature.
C> curl -u user:pass -d "\"method\":\"getblockhash\",\"params\":(0),\"id\":1" http://localhost:8332/
"result":null,"error":"code":-28,"message":"Starting network threads…","id":1
Now bitcoind has no problem parsing the data, but it still says it’s initializing.
You can ask questions that don’t depend on blockchain state, etc.
C> curl -u user:pass -d "\"method\": \"uptime\", \"params\": ()" http://localhost:8332/
"result":2063,"error":null,"id":null
bitcoind reports that it ran for 2063 seconds.
C> curl -u user:pass -d "\"method\": \"uptime\", \"params\": ()" http://localhost:8332/
"result":2427,"error":null,"id":null
It has now been 2427 seconds since Bitcoin was launched.
Switching to WSL for no particular reason other than trying to make RPC calls using Linux will allow bitcoind to complete initialization and answer questions about blockchain data.
$ curl -u today:temporary -d '"method":"getblockhash","params":(0),"id":1' http://localhost:8332/
"result":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f","error":null,"id":1
This query can take several minutes on my PC with many other processes running, so you may need to adjust the client timeout.