0

I am using https://github.com/freewil/bitcoin-testnet-box to run bitcoind in docker to test signing of transactions.

make start tells me the bitcoind is started without -regtest flag. See https://github.com/freewil/bitcoin-testnet-box/blob/master/Makefile#L13

When I run bitcoin-cli -datadir=1 getblockchaininfo, I indeed see "chain": "regtest" in output, so both the nodes are running in regression test mode, I believe.

If I generate an address for either of these 2 nodes, I get an address starting with 2:

tester@4df64413049e ~/bitcoin-testnet-box$ make address1
bitcoin-cli -datadir=1  getnewaddress
2N4DTeBWDF9yaF9TJVGcgcZDM7EQtsGwFjX
tester@4df64413049e ~/bitcoin-testnet-box$ make address2
bitcoin-cli -datadir=2  getnewaddress
2MwxP8fyh9MFqKnZXZuqt3ZYByhLpNVoiX3

make getinfo tells me its not testnet either:

tester@4df64413049e ~/bitcoin-testnet-box$ make getinfo
bitcoin-cli -datadir=1  -getinfo
{
  "version": 170100,
  "protocolversion": 70015,
  "walletversion": 169900,
  "balance": 0.00000000,
  "blocks": 0,
  "timeoffset": 0,
  "connections": 1,
  "proxy": "",
  "difficulty": 4.656542373906925e-10,
  "testnet": false,
  "keypoololdest": 1599940906,
  "keypoolsize": 1000,
  "paytxfee": 0.00000000,
  "relayfee": 0.00001000,
  "warnings": ""
}
bitcoin-cli -datadir=2  -getinfo
{
  "version": 170100,
  "protocolversion": 70015,
  "walletversion": 169900,
  "balance": 0.00000000,
  "blocks": 0,
  "timeoffset": 0,
  "connections": 1,
  "proxy": "",
  "difficulty": 4.656542373906925e-10,
  "testnet": false,
  "keypoololdest": 1599940906,
  "keypoolsize": 1000,
  "paytxfee": 0.00000000,
  "relayfee": 0.00001000,
  "warnings": ""
}

So what mode I am running these bitcoin nodes as? If I was to trust the output that its not testmode but somehow regression test mode, shouldn't the address start with 1 if its really regtest mode or with m/n if its testnet mode?

Also, when I dump the private key for any of such address and try to derive the P2PKH address from it, it doesn't match. Same code works fine with address and key taken from mainnet. What's going on?

  • Addresses that start with "2" are regtest or testnet P2SH (legacy pay to script hash) similar to addresses that start with "3" on mainnet. – pinhead Sep 12 at 23:27
  • @pinhead I looked hard at specifying addresstype in getnewaddress call and was able to get an address starting from m/n for legacy value. I was passing the argument incorrectly earlier, so it was defaulting to p2sh-segwit like you said. The code to derive the address from public key still fails though. – Ashfame Sep 12 at 23:50
  • I figured out the issue with mismatching address too. Turns out code sample I had wasn't serializing according to the pub key being compressed or not. Using the right condition/abstraction fixed it. – Ashfame Sep 13 at 13:15
0

Both regtest and testnet use the same address prefixes for the legacy and p2sh-segwit address types. Addresses beginning with 2 are p2sh, and if retrieved via getnewaddress, are guaranteed to be p2sh-segwit.

For bech32 type addresses, the regtest prefix is bcrt and on testnet it is tb. You can try fetching a bech32 address to see what the prefix is and be more sure of which network you are using.

shouldn't the address start with 1 if its really regtest mode

No, and that would be dangerous.

Both regtest and testnet intentionally use different prefixes than mainnet. You will never see mainnet prefixes in those modes.

| improve this answer | |
  • Thanks! I didn't realize regtest has diff prefixes too. I thought it just tweaked another parameter to differentiate itself from mainnet. – Ashfame Sep 13 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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