<p>Both regtest and testnet use the same address prefixes for the legacy and p2sh-segwit address types. Addresses beginning with <code>2</code> are p2sh, and if retrieved via <code>getnewaddress</code>, are guaranteed to be p2sh-segwit.</p>
<p>For bech32 type addresses, the regtest prefix is <code>bcrt</code> and on testnet it is <code>tb</code>. You can try fetching a bech32 address to see what the prefix is and be more sure of which network you are using.</p>
<blockquote>
<p>shouldn't the address start with 1 if its really regtest mode</p>
</blockquote>
<p>No, and that would be dangerous.</p>
<p>Both regtest and testnet intentionally use different prefixes than mainnet. You will never see mainnet prefixes in those modes.</p>

CC BY-SA 4.0
2020-09-13T13:13:19.013Z
Thanks! I didn't realize regtest has diff prefixes too. I thought it just tweaked another parameter to differentiate itself from mainnet.
Ashfame
CC BY-SA 4.0
2020-09-13T05:55:25.127Z
2020-09-13T05:55:25.127Z
Ava Chow
<p>I am using <a href="https://github.com/freewil/bitcoin-testnet-box" rel="nofollow noreferrer">https://github.com/freewil/bitcoin-testnet-box</a> to run bitcoind in docker to test signing of transactions.</p>
<p><code>make start</code> tells me the bitcoind is started without <code>-regtest</code> flag. See <a href="https://github.com/freewil/bitcoin-testnet-box/blob/master/Makefile#L13" rel="nofollow noreferrer">https://github.com/freewil/bitcoin-testnet-box/blob/master/Makefile#L13</a></p>
<p>When I run <code>bitcoin-cli -datadir=1 getblockchaininfo</code>, I indeed see <code>&quot;chain&quot;: &quot;regtest&quot;</code> in output, so both the nodes are running in regression test mode, I believe.</p>
<p>If I generate an address for either of these 2 nodes, I get an address starting with 2:</p>
<pre><code>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
</code></pre>
<p><code>make getinfo</code> tells me its not testnet either:</p>
<pre><code>tester@4df64413049e ~/bitcoin-testnet-box$ make getinfo
bitcoin-cli -datadir=1  -getinfo
{
  &quot;version&quot;: 170100,
  &quot;protocolversion&quot;: 70015,
  &quot;walletversion&quot;: 169900,
  &quot;balance&quot;: 0.00000000,
  &quot;blocks&quot;: 0,
  &quot;timeoffset&quot;: 0,
  &quot;connections&quot;: 1,
  &quot;proxy&quot;: &quot;&quot;,
  &quot;difficulty&quot;: 4.656542373906925e-10,
  &quot;testnet&quot;: false,
  &quot;keypoololdest&quot;: 1599940906,
  &quot;keypoolsize&quot;: 1000,
  &quot;paytxfee&quot;: 0.00000000,
  &quot;relayfee&quot;: 0.00001000,
  &quot;warnings&quot;: &quot;&quot;
}
bitcoin-cli -datadir=2  -getinfo
{
  &quot;version&quot;: 170100,
  &quot;protocolversion&quot;: 70015,
  &quot;walletversion&quot;: 169900,
  &quot;balance&quot;: 0.00000000,
  &quot;blocks&quot;: 0,
  &quot;timeoffset&quot;: 0,
  &quot;connections&quot;: 1,
  &quot;proxy&quot;: &quot;&quot;,
  &quot;difficulty&quot;: 4.656542373906925e-10,
  &quot;testnet&quot;: false,
  &quot;keypoololdest&quot;: 1599940906,
  &quot;keypoolsize&quot;: 1000,
  &quot;paytxfee&quot;: 0.00000000,
  &quot;relayfee&quot;: 0.00001000,
  &quot;warnings&quot;: &quot;&quot;
}
</code></pre>
<p>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?</p>
<p>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?</p>

CC BY-SA 4.0
2020-09-12T23:27:45.220Z
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
CC BY-SA 4.0
2020-09-12T23:50:18.537Z
@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
CC BY-SA 4.0
2020-09-13T13:15:02.503Z
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
<bitcoind><regtest>
Address starting with 2, what mode I am in?
Ashfame
# Address starting with 2, what mode I am in?

(Asked by: username_0 on 2020-09-12)

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?

**Tags:** bitcoind, regtest

> **Comments:**
> **username_1**: Addresses that start with "2" are regtest or testnet P2SH (legacy pay to script hash) similar to addresses that start with "3" on mainnet.  
> **username_0**: @username_1 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.  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_2 on 2020-09-13. Score: 0 | Accepted answer

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.

> **Comments:**
> **username_0**: Thanks! I didn't realize regtest has diff prefixes too. I thought it just tweaked another parameter to differentiate itself from mainnet.  

---

