Changing the ports

To operate, Bitcoin uses two ports on which the client will listen to establish connections, namely:

  • p2p port (by default, 8333 in mainnet and 18333 in testnet)
  • RPC port (by default, 8332 in mainnet and 18332 in testnet)

We will define different ports for both mainnet and testnet, in order to be able to run your altcoin alongside a Bitcoin client without port overlap. Remember, mainnet and testnet are abbreviations for the main and test public networks.

Get your favourite text editor and open up chainparams.cpp and chainparamsbase.cpp located in the src/ folder. Find the network parameters, including the ports, and then change the following variables:

  • For mainnet (CMainParams and CBaseMainParams classes):
chainparams.cpp: ...

Get Blockchain By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.