Bitcoin Forum
April 15, 2026, 03:58:05 AM *
News: Latest Bitcoin Core release: 30.2 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: bitcoin-cli does not work with testnet  (Read 107 times)
takuma sato (OP)
Hero Member
*****
Offline Offline

Activity: 831
Merit: 739


View Profile
September 11, 2025, 06:22:24 PM
 #1

Im trying to make bitcoin-cli work with testnet3, im using bitcoin-qt (knots 29)

I have testnet3 fully synced. In the linux terminal I use

Code:
./bitcoin-cli -testnet=1 -datadir=/home/takuma/software/.bitcoin/testnet3 getblockchaininfo

Result:

Code:
error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set. See -rpcpassword and -stdinrpcpass. Configuration file: (./bitcoin-cli -testnet=1 -datadir=/home/takuma/software/.bitcoin/testnet3/bitcoin.conf)

On my ./bitcoin/bitcoin.conf file there is this:

Code:
listen=0
server=1
rcpbind=127.0.0.1

When I try bitcoin-cli on the main blockchain:

Code:
./bitcoin-cli -datadir=/home/takuma/software/.bitcoin getblockchaininfo

it works fine. So something to do with the testnet3 for some reason. The .cookie is there on the /testnet3 folder, but it seems it's not reading it or something. The error points to testnet3/bitcoin.conf file, which didn't exist. So I tried creating a bitcoin.conf file there, which contains the same:

Code:
listen=0
server=1
rcpbind=127.0.0.1

Still same error. I have also noticed that it isn't even loading that file on testnet3, because I tried adding par1 on the /.bitcoin/ one and par=4 on the /.bitcoin/testnet3 one and when I open bitcoin-qt -testnet=1 it is using par=1 so it looks like it's reading that config file and on the debug.log file it says:

Code:
Script verification uses 0 additional threads

So it seems it's using par=1, it also shows 1 in the GUI. And I actually found the line that says it's just using the regular /.bitcoin/bitcoin.conf file:

Code:
Config file: /home/takuma/software/.bitcoin/bitcoin.conf

I thought there was only one global bitcoin.conf file in /.bitcoin/ that was used for all datadirs, but now due that error im not sure if you can set different bitcoin.conf files for each datadir. In any case, I don't understand why this isn't working. It clearly creates the cookie in testnet3, it works when launching mainnet, so unless testnet needs to use different values on bitcoin.conf then I don't get it.

achow101
Moderator
Legendary
*
Offline Offline

Activity: 3920
Merit: 7677


Just writing some code


View Profile WWW
September 11, 2025, 07:18:35 PM
Merited by LoyceV (4), hugeblack (2), takuma sato (2), BayAreaCoins (1), ABCbits (1)
 #2

-datadir should be the mainnet datadir, not the testnet one. When you're in testnet mode, it always uses the testnet3 subdirectory of whatever is specified in -datadir.

takuma sato (OP)
Hero Member
*****
Offline Offline

Activity: 831
Merit: 739


View Profile
September 11, 2025, 07:46:54 PM
Last edit: September 11, 2025, 07:57:25 PM by takuma sato
Merited by hugeblack (2)
 #3

-datadir should be the mainnet datadir, not the testnet one. When you're in testnet mode, it always uses the testnet3 subdirectory of whatever is specified in -datadir.

Would have never guessed that. It works:

Code:
./bitcoin-cli -testnet=1 -datadir=/home/takuma/software/.bitcoin getblockchaininfo

So as far as bitcoin.conf files, you are supposed to only have one file on /.bitcoin/ and not have separate in /testnet3/ or /testnet4/ etc?

Thing is, on the GUI in datadir it says:

/home/takuma/software/.bitcoin/testnet3

So assumed it would have it's own bitcoin.conf file too, and require that path when you use -datadir, but I don't remember reading it automatically adds /testnet3/ when running testnet.

Btw, if you wanted to not have to type the path each time you use bitcoin-cli, what would be a solution?

Should I add "datadir=/home/takuma/software/.bitcoin" in the bitcoin.conf file? I have .desktop files with different arguments for the executables. So one file runs bitcoin-qt normally and another adds -testnet=1. Considering that you said if you run in testnet mode it automatically adds the subdirectory of whatever chain you are adding, then adding that in bitcoin.conf should be safe? I just don't want my blockchain files overwritten, I mean I don't want the testnet blockchain overwritting the normal blockchain files if it reads that it literally should be using "datadir=/home/takuma/software/.bitcoin/" from the bitcoin.conf file, but I assume it always adds the subdirectory. Well the idea is to not need to type the path eachtime you use ./bitcoin-cli so im looking to tell bitcoin-cli to always use the datadir I want by default. I assume this can be done like this or either add -datadir=path to the .desktop entries.
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3920
Merit: 7677


Just writing some code


View Profile WWW
September 11, 2025, 08:53:56 PM
 #4

Should I add "datadir=/home/takuma/software/.bitcoin" in the bitcoin.conf file?
yes

takuma sato (OP)
Hero Member
*****
Offline Offline

Activity: 831
Merit: 739


View Profile
September 12, 2025, 09:16:25 PM
 #5

Should I add "datadir=/home/takuma/software/.bitcoin" in the bitcoin.conf file?
yes
Added but to run ./bitcoin-cli it still requires that I add the -datadir=path arg everytime I run the command.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!