How to Create Your Own Private Blockchain (PoA, Clique) in Linux Using Geth 1.11.5, 2023 Version


As mention in the previous on creating a private blockchain on PoW, this post will be on how to create a PoA (combination of PoW and PoS) blockchain effortlessly.

Create 2 folders.
You will need at least 2 signers to make PoA algorithm work.

mkdir node1 node2

Create 2 accounts.
If you want to access the private key of your newly created account, you can get the json file from the keystore folder and import into Metamask.

geth --datadir node1 account new
geth --datadir node2 account new

Copy down the address and paste it into your genesis.json. Maintain only 1 copy of the genesis.json as both nodes need to run from the same initial genesis configuration or they will not be able to sync. Create your own password.txt with the password inside for account unlocking.

Assuming your address is 0x9B02C47e6eecF989598c33F82686925Ed4EE6d85 and 0x98aB1d0ee9CaBF5d55a3a2804F083187c42c508c, your genesis file should look like this:

{"config":{"chainId":141319,"homesteadBlock":0,"eip150Block":0,"eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0,"istanbulBlock":0,"muirGlacierBlock":0,"berlinBlock":0,"londonBlock":0,"arrowGlacierBlock":0,"grayGlacierBlock":0,"clique":{"period":1,"epoch":10000}},"difficulty":"1","gasLimit":"800000000","extradata":"0x00000000000000000000000000000000000000000000000000000000000000009B02C47e6eecF989598c33F82686925Ed4EE6d8598aB1d0ee9CaBF5d55a3a2804F083187c42c508c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","alloc":{"9B02C47e6eecF989598c33F82686925Ed4EE6d85":{"balance":"500000"},"9B02C47e6eecF989598c33F82686925Ed4EE6d85":{"balance":"500000"}}}

Init for both nodes

geth init --datadir node1 genesis.json
geth init --datadir node2 genesis.json

Set up a bootnode to allow the 2 nodes to be able to search for one another. It is required for the first connection and subsequently can be omitted. Copy the enode address.

bootnode -genkey boot.key
bootnode -nodekey boot.key -addr 0.0.0.0:30305

Run the node with different port and authrpc.port. I allow node1 to be a public RPC server with console to do manual transaction while node2 will not be a RPC. You can set both to be a RPC too with different port. The enode is provided by the bootnode return message. The miner.etherbase have to be the same address as the signer.

geth --datadir node1 --port 30306 --bootnodes enode://40dbee2f4161a9a1b26670107b9b6efb2205477bedb76242317ed1a329002d44e59132d0bc6398a58849cfe8385b3c1eb067d50668de4afee8a7a933bc13f805@127.0.0.1:0?discport=30305  --networkid 141319 --unlock 0x9B02C47e6eecF989598c33F82686925Ed4EE6d85 --password password.txt console --mine --miner.threads 1 --miner.etherbase 0x9B02C47e6eecF989598c33F82686925Ed4EE6d85 --http --http.addr '0.0.0.0' --allow-insecure-unlock --syncmode full

geth --datadir node2 --port 30316 --bootnodes enode://4aafaa8904d3e37d1f4758b235910fa21d37bd5dee34ac729cc954433d69494788c292cf9468f3c32701f0bf979b817685ad4bc81639b9209317f0d521e6bff5@127.0.0.1:0?discport=30305  --networkid 141319 --unlock 0x98aB1d0ee9CaBF5d55a3a2804F083187c42c508c --password password.txt --authrpc.port 8561 --mine --miner.threads 1 --miner.etherbase 0x98aB1d0ee9CaBF5d55a3a2804F083187c42c508c --syncmode full

Comments

Popular posts from this blog

Kokology Questions & Answers

Neuro-Linguistic Programming Models Summary (02 of 14)

Neuro-Linguistic Programming Models Summary (11 of 14)