[TIP] How to build my own network?

Nine Chronicles is a fully decentralized multiplayer game. it means, there is no central server and you can build your own network without confirmation or authorization.

In this article, we’ll introduce how to build your own network using only the Nine Chronicles you already installed.

Requirement

  • Nine Chronicles (v10012+)
  • planet CLI
  • Public IP that can be accessed from outside

Launching the node as “seed”

Nine Chronicles is communicating based on P2P (Peer-to-Peer) and it doesn’t need any central server. but how does it find other peers for the first time?

When you launch Nine Chronicles.exe, it will try to connect peers that configured in the config file. these peers are called “seed” nodes, and they will distribute other peers in the network to connected nodes.

Therefore, if you want to build the network, you need to launch the “seed” nodes. Fortunately, the “seed” node is also a Nine Chronicle client and you can launch without any other executable or data.

  1. Run cmd.exe
  2. Move to the installation directory
    > cd "%localappdata%\Programs\Nine Chronicles" # it's default path
    
  3. Run NineChronicles.Headless as headless mode
    • Versions released before September 2, 2020 (v10012)
      > resources\app\publish\NineChronicles.Headless.Executable.exe ^
      --app-protocol-version "10012/019101FEec7ed4f918D396827E1277DEda1e20D4/MEUCIQDxz2NGPjE+j1g4gSzxWb6T5BGSvXkF8XRitNQ+aWnR2gIgDuOA4vamURG5IzbHCa4.Sx26pLFGruHkBM54vdmDIi0=/ZHUxNjpXaW5kb3dzQmluYXJ5VXJsdTU1Omh0dHBzOi8vZG93bmxvYWQubmluZS1jaHJvbmljbGVzLmNvbS92MTAwMTIvV2luZG93cy56aXB1MTQ6bWFjT1NCaW5hcnlVcmx1NTY6aHR0cHM6Ly9kb3dubG9hZC5uaW5lLWNocm9uaWNsZXMuY29tL3YxMDAxMi9tYWNPUy50YXIuZ3p1OTp0aW1lc3RhbXB1MjU6MjAyMC0wOC0xNFQwNToxNTozNyswMDowMGU=" ^
      --genesis-block-path "https://download.nine-chronicles.com/genesis-block-9c-beta-5" ^
      --store-type "rocksdb" ^
      --store-path "%localappdata%\planetarium\9c" ^
      --minimum-difficulty 5000000 ^
      --host <Your Public IP> ^
      --port <Your TCP Port> ^
      --private-key <Your Private Key>
      
    • Versions released at September 2, 2020 (v20000)
      > resources\app\publish\NineChronicles.Headless.Executable.exe ^
      --libplanet-node ^
      --mpt ^
      --app-protocol-version "20000/019101FEec7ed4f918D396827E1277DEda1e20D4/MEUCIQDLgm5r3B5g2DTMFFa2+o7cEr6HowLXeJ8OpugzsWhdCAIgKfF9foU5kDdz81OVJ4DmSgMntipvyYGM41CR+jHD3Lw=/ZHUxNjpXaW5kb3dzQmluYXJ5VXJsdTU1Omh0dHBzOi8vZG93bmxvYWQubmluZS1jaHJvbmljbGVzLmNvbS92MjAwMDAvV2luZG93cy56aXB1MTQ6bWFjT1NCaW5hcnlVcmx1NTY6aHR0cHM6Ly9kb3dubG9hZC5uaW5lLWNocm9uaWNsZXMuY29tL3YyMDAwMC9tYWNPUy50YXIuZ3p1OTp0aW1lc3RhbXB1MjU6MjAyMC0wOS0wMlQwMzoxNjo0NSswMDowMGU=" ^
      --genesis-block-path "https://download.nine-chronicles.com/genesis-block-9c-beta-6" ^
      --store-type "rocksdb" ^
      --store-path "%localappdata%\planetarium\9c-beta-6" ^
      --minimum-difficulty 5000000 ^
      --host <Your Public IP> ^
      --port <Your TCP Port> ^
      --private-key <Your Private Key>
      

It’s a bit complicated. :sweat_smile: Let’s take a look one by one. :mag_right:

Host and Port

In order to process a connection from another node as a seed, you need to provide the necessary information for the connection. NineChronicles.Headless.Executable can set the corresponding information through the execution arguments --host and --port.

One thing note, For --host, the address used for binding in BSD sockets (e.g. 0.0.0.0) cannot be used. The --host argument must be set to a public IP address that other nodes can access because it provides the necessary access information when connecting to the seed node.

Private Key

The private key is a hex-encoded string(not the password you typed) and, it is generated by Nine Chronicles automatically when you create your account. if you’ve backed up your private key from the account creation page, you can use it directly.

But if you don’t have your private key, you need planet CLI. planet is a command-line interface for manage key files used in Nine Chronicles.

As below, you can get your private key via planet key export command.

> planet key
Key ID                               Address
------------------------------------ ------------------------------------------
2d3f5e09-6e99-48b0-af14-eb1fb6a3b899 0x6eb2205f75F32991B8cf43a1022e5BCF7B29f9c2
# It's an example, yours will be different.

> planet key export 2d3f5e09-6e99-48b0-af14-eb1fb6a3b899
Passphrase: ****
c42b19f8c129b3d3cb551bec5304343e0c812fdf3462a49447cab8973b0785a7

Connecting with other clients

If set it up correctly, you should get the following output.

[20:50:47 DBG] Secp256K1CryptoBackend initialized.
[20:50:48 DBG] RocksDB is initialized.
[20:50:48 DBG] Number of chain ids: 1
[20:50:48 DBG] chainId: b9becc92-3768-4a36-aec1-7fd34b468d02
[20:50:48 DBG] Miner called.
[20:50:48 INF] Listen on 51186
[20:50:48 DBG] Starting swarm...
[20:50:48 DBG] Peer information : 0xF3e36873E6BA155DFe05A16616A173b670faEFF2.Unspecified/127.0.0.1:51186.
[20:50:48 DBG] Rebuilding connection...
[20:50:48 DBG] FindPeerAsync() with 0x008bf16053CB8b78bb1345798efe56536E8D828c to null. (depth: -1)
[20:50:48 DBG] No any neighbor received.
[20:50:48 DBG] FindPeerAsync() with 0x23DaF80d09e422cfEa73791c4c1f35626c3E0672 to null. (depth: -1)
[20:50:48 DBG] No any neighbor received.
[20:50:48 DBG] FindPeerAsync() with 0x3EBb95d7Ed49e4D93738379208078c2692e4576f to null. (depth: -1)
[20:50:48 DBG] No any neighbor received.
[20:50:48 DBG] FindPeerAsync() with 0xF3e36873E6BA155DFe05A16616A173b670faEFF2 to null. (depth: -1)
[20:50:48 DBG] No any neighbor received.
[20:50:48 DBG] Swarm started.
[20:50:49 DBG] Start mining.
[20:50:58 DBG] Refreshing table... total peers: 0

Next, open the configuration file(%localappdata%\Programs\Nine Chronicles\resources\app\config.json) using your favorite text editor(e.g. Visual Studio Code, Notepad) and modify the PeerStrings item as follows.

	"PeerStrings": [
		"<hex-encoded Public Key>,<Public IP of seed>,<Port of seed>"
	],

Public Key

Nine Chronicles’ private key is an asymmetric secret key using ECDSA. Therefore, this private key has a pair of public keys to be disclosed to the outside, and this public key is used for P2P communication of Nine Chronicles.

To get the public key corresponding to the private key of the seed node, you can use planet export -P.

> planet key
Key ID                               Address
------------------------------------ ------------------------------------------
2d3f5e09-6e99-48b0-af14-eb1fb6a3b899 0x6eb2205f75F32991B8cf43a1022e5BCF7B29f9c2
> planet key export -P 2d3f5e09-6e99-48b0-af14-eb1fb6a3b899
Passphrase: *
0290fd6edcc435270313e9bca88ed012c0af0ece67f39ec793581c8a93b06a21f1