Create a private node with Hyperledger Besu

Nasri Adzlani
4 min readDec 24, 2021

Hyperledger Besu is an Ethereum client designed to be enterprise-friendly for both public and private permissioned network use cases. It can also be ran on test networks such as` Rinkeby, Ropsten, and Görli. Hyperledger Besu includes several consensus algorithms including PoW, and PoA (IBFT, IBFT 2.0, Etherhash, and Clique). Its comprehensive permissioning schemes are designed specifically for use in a consortium environment.

Requirements

Server ( or you can using laptop/pc )
OS ( recomendation using linux ) but u can use a windows or mac
JDK 11 or lastest
Source besu

Installation

Download and Extract a besu binary package here,

[nasri@nasri-80t2 besu]$ tree
.
| — LICENSE
| — besu.autocomplete.sh
| — bin
| | — besu
| ` — besu.bat
| — lib

create folder for node and configuration folder in bin folder like this

.
|-- LICENSE
|-- besu.autocomplete.sh
|-- bin
| |-- besu
| |-- besu.bat
| `-- node
| |-- config
| |-- node1
| | `-- data
| |-- node2
| | `-- data
| `-- node3
| `-- data
|-- lib

open terminal in “node” folder and create ibftConfigFile for configuration consensus

ibftConfigFiles.json
{
"genesis": {
"config": {
"chainId": 2018,
"constantinoplefixblock": 0,
"ibft2": {
"blockperiodseconds": 2,
"epochlength": 30000,
"requesttimeoutseconds": 10
}
},
"nonce": "0x0",
"timestamp": "0x58ee40ba",
"gasLimit": "0x47b760",
"difficulty": "0x1",
"mixHash": "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"fe3b557e8fb62b89f4916b721be55ceb828dbd73": {
"privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "0xad78ebc5ac6200000"
},
"627306090abaB3A6e1400e9345bC60c78a8BEf57": {
"privateKey":
"c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "90000000000000000000000"
},
"f17f52151EbEF6C7334FAD080c5704D77216b732": {
"privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "90000000000000000000000"
}
}
},
"blockchain": {
"nodes": {
"generate": true,
"count": 3
}
}
}

save this json into config folder and run operator command like this

../besu operator generate-blockchain-config --config-file config/ibftConfigFile.json --to networkFiles --private-key-file-name key

after execute that command will be automatic created networkFiles with address and genesis file

networkFiles/
|-- genesis.json
`-- keys
|-- 0x000<Address>
| |-- key
| `-- key.pub
|-- 0x000<Address>
| |-- key
| `-- key.pub
`-- 0x000<Address>
|-- key
`-- key.pub

Copy genesis from networkFiles folder into config folder

mv networkFiles/genesis.json config/

Copy the node private keys to the node directories

.
|-- node1
| `-- data
| |-- key
| `-- key.pub
|-- node2
| `-- data
| |-- key
| `-- key.pub
`-- node3
`-- data
|-- key
`-- key.pub

create “toEncode.json” files for rlp (for extradata in genesis) and save into config folder

["address","address","address"]

execute source bellow to generate extraData

../besu rlp encode --from your_rlp_file --to dest_files  

after generate extraData, copy into genesis files and change address and private key on genesis files.

create toml configuration like a environment and save into all nodes folder with name “config.toml”

data-path="node1/data"
genesis-file="config/genesis.json"
#static-nodes-file="config/static_nodes.json"rpc-http-enabled=true
rpc-http-api=["ETH","NET","IBFT","WEB3","ADMIN"]
rpc-http-host="127.0.0.1"
rpc-http-port="8545"
rpc-http-cors-origins=["all"]
p2p-host="127.0.0.1"
p2p-port="30303"

change port between nodes and save, and folder tree like that

.
|-- config
| |-- genesis.json
| |-- ibftConfigFile.json
| |-- static-nodes.json
| `-- toEncode.json
|-- networkFiles
| `-- keys
| |-- 0x5f86cab243c3856702dda8a73eaf9a1aca64007d
| |-- 0x73037201d81e3a21fa670cde83f1ca9d4ca86aff
| `-- 0x9b4d32c4d263c61910d3c08233de60e2f1e82f27
|-- node1
| |-- config.toml
| `-- data
| |-- key
| `-- key.pub
|-- node2
| |-- config.toml
| `-- data
| |-- key
| `-- key.pub
|-- node3
| |-- config.toml
| `-- data
| |-- key
| `-- key.pub
`-- rlp.json
12 directories, 14 files

run config file for get a enode for creating static-nodes

copy enode into “static-nodes.json” and save into config folder and running other nodes

["enode-1","enode-2","enode-n"]

after created, u can remove # from toml config for using static nodes

../besu --config-file node1/config.toml

run all node, im recomended for using tmux and split screen

check peer count in terminal using

curl -X POST --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":1}' http://127.0.0.1:8545/

example result

{
"jsonrpc" : "2.0",
"id" : 1,
"result" : "0x2"
}
0x2 is total node pairing in your rpc

if your result like that, congrats your private node has been success

--

--