<p><code>getblockchaininfo</code> should tell you which chain you're on. For instance, on the main chain, you should get something like: </p>

<pre><code>{
    "result": {
        "chain": "main",   &lt;======= This is what you want
        "blocks": 519338,
        "headers": 519338,
        "bestblockhash": "0000000000000000001822f09f1821deb6b3b74e36ea1de4e232e5c60fa30ed9",
        "difficulty": 3839316899029.672,
        "mediantime": 1524358671,
        "verificationprogress": 0.9999957624003699,
        "chainwork": "0000000000000000000000000000000000000000018fa8011b05ef506160c4ff",
        "pruned": false,
        "softforks": [
            {
                "id": "bip34",
                "version": 2,
                "reject": {
                    "status": true
                }
            },
            {
                "id": "bip66",
                "version": 3,
                "reject": {
                    "status": true
                }
            },
            {
                "id": "bip65",
                "version": 4,
                "reject": {
                    "status": true
                }
            }
        ],
        "bip9_softforks": {
            "csv": {
                "status": "active",
                "startTime": 1462060800,
                "timeout": 1493596800,
                "since": 419328
            },
            "segwit": {
                "status": "active",
                "startTime": 1479168000,
                "timeout": 1510704000,
                "since": 481824
            }
        }
    },
    "error": null,
    "id": null
}
</code></pre>

CC BY-SA 3.0
2018-04-22T08:37:26.737Z
Seems to be that OP is asking about bitwasp-php library,
Tailer
CC BY-SA 3.0
2018-04-22T08:48:20.627Z
`getblockchaininfo` is part of the standard rpc interface, so I suspect any library will support it by default. bitwasp-php seems to include it in its tests too.
Raghav Sood
CC BY-SA 3.0
2018-04-22T19:29:45.980Z
@Adam, I tagged it `json-rpc`. (anyway, bitwasp never had `ValidateAddress` in the `Bitcoin` class). The `Bitcoin` class name is used all over the place, in EasyBitcoin, etc. But you can keep it closed if you wish, since I have my answer.
toddmo
CC BY-SA 3.0
2018-04-23T07:10:29.503Z
Sorry, but it was not clear at all. because Bitcoind chain is not something that you change regularly through an RPC command, so you would know which chain you're connected to by the way you've started it. `bitcoind -testnet or bitcoind -regtest` etc..
Tailer
CC BY-SA 3.0
2018-04-22T01:33:23.533Z
2018-04-22T01:33:23.533Z
Raghav Sood
<p>I'm in a unit test and I would like to use different test addresses depending on which network I'm connected to, to keep test output limited to the network I'm actually connected to.</p>

<p>I know I can run <code>validateaddress</code> to figure it out, but how can I detect this directly? </p>

CC BY-SA 3.0
2018-04-22T08:38:02.180Z
are you Asking about bitwasp-php library or Bitcoin-core JSONRPC?
Tailer
CC BY-SA 3.0
2018-04-22T14:56:20.487Z
Hey toddmo, could you please add some more details what software you're working with and then flag your question for reopening?
Murch
CC BY-SA 3.0
2018-04-22T20:01:32.000Z
Do you mean "which network" as in "testnet or mainnet"?
Murch
CC BY-SA 3.0
2018-04-22T20:11:53.880Z
@Murch, yes sir. I guess a chain is a network and that's why they call it that? Should I put chain?
toddmo
<json-rpc>
How can I detect which network I'm connected to?
toddmo
# How can I detect which network I'm connected to?

(Asked by: username_0 on 2018-04-22)

I'm in a unit test and I would like to use different test addresses depending on which network I'm connected to, to keep test output limited to the network I'm actually connected to.

I know I can run `validateaddress` to figure it out, but how can I detect this directly?

**Tags:** json-rpc

> **Comments:**
> **username_1**: are you Asking about bitwasp-php library or Bitcoin-core JSONRPC?  
> **username_2**: Hey username_0, could you please add some more details what software you're working with and then flag your question for reopening?  
> **username_2**: Do you mean "which network" as in "testnet or mainnet"?  
> **username_0**: @username_2, yes sir. I guess a chain is a network and that's why they call it that? Should I put chain?  

---

## 1 answers

### Answer by username_3 on 2018-04-22. Score: 3 | Accepted answer

`getblockchaininfo` should tell you which chain you're on. For instance, on the main chain, you should get something like:

```
{
    "result": {
        "chain": "main",   <======= This is what you want
        "blocks": 519338,
        "headers": 519338,
        "bestblockhash": "0000000000000000001822f09f1821deb6b3b74e36ea1de4e232e5c60fa30ed9",
        "difficulty": 3839316899029.672,
        "mediantime": 1524358671,
        "verificationprogress": 0.9999957624003699,
        "chainwork": "0000000000000000000000000000000000000000018fa8011b05ef506160c4ff",
        "pruned": false,
        "softforks": [
            {
                "id": "bip34",
                "version": 2,
                "reject": {
                    "status": true
                }
            },
            {
                "id": "bip66",
                "version": 3,
                "reject": {
                    "status": true
                }
            },
            {
                "id": "bip65",
                "version": 4,
                "reject": {
                    "status": true
                }
            }
        ],
        "bip9_softforks": {
            "csv": {
                "status": "active",
                "startTime": 1462060800,
                "timeout": 1493596800,
                "since": 419328
            },
            "segwit": {
                "status": "active",
                "startTime": 1479168000,
                "timeout": 1510704000,
                "since": 481824
            }
        }
    },
    "error": null,
    "id": null
}

```

> **Comments:**
> **username_1**: Seems to be that OP is asking about bitwasp-php library,  
> **username_3**: `getblockchaininfo` is part of the standard rpc interface, so I suspect any library will support it by default. bitwasp-php seems to include it in its tests too.  
> **username_0**: @Adam, I tagged it `json-rpc`. (anyway, bitwasp never had `ValidateAddress` in the `Bitcoin` class). The `Bitcoin` class name is used all over the place, in EasyBitcoin, etc. But you can keep it closed if you wish, since I have my answer.  
> **username_1**: Sorry, but it was not clear at all. because Bitcoind chain is not something that you change regularly through an RPC command, so you would know which chain you're connected to by the way you've started it. `bitcoind -testnet or bitcoind -regtest` etc..  

---

