How to check if node is on TestNet or MainNet via `bitcoin-cli`?

6

Is there a way, by using bitcoin-cli using RPC querying, if the node I'm querying is running on MainNet or TestNet?

Thanks

knocte

Posted 2016-06-28T04:28:01.313

Reputation: 1 531

Answers

8

Simplest API, doh!:

$ bitcoin-cli getinfo
{
  "version": 120100,
  "protocolversion": 70012,
  "walletversion": 60000,
  "balance": 0.00000000,
  "blocks": 414105,
  "timeoffset": -165,
  "connections": 9,
  "proxy": "",
  "difficulty": 199312067531.243,
  "testnet": false,
  "keypoololdest": 1466689642,
  "keypoolsize": 101,
  "paytxfee": 0.00000000,
  "relayfee": 0.00001000,
  "errors": ""
}

knocte

Posted 2016-06-28T04:28:01.313

Reputation: 1 531

the getinfo command deprecated in Bitcoin Core 0.16 onwards. you'll get the message the method not found on later versions.inherithandle 2019-11-11T06:37:09.143

good to know, any replacement?knocte 2019-11-11T08:16:30.927

as @Kerem atam said, you can use getblockchaininfo as well as getnetworkinfo and getwalletinfo for some more information.inherithandle 2019-11-12T11:29:33.047

4

Since version 0.16.0

$ bitcoind-cli getblockchaininfo

{
  "chain": "main",
  "blocks": 525663,
  "headers": 525663, 
  .
  .
  .

}

Kerem atam

Posted 2016-06-28T04:28:01.313

Reputation: 93