sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
https://www.digitalocean.com/community/tutorials/how-to-install-go-on-ubuntu-20-04
cd go-ethereum
git checkout release/1.11
git pull
make geth
sudo cp build/bin/geth /usr/local/bin/
mkdir private-ethereum
cd private-ethereum
geth --datadir ./datadir account new
paste the following code and replace the address in alloc with the account you prev made
{
"config": {
"chainId": 4785,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"difficulty": "400",
"gasLimit": "2000000",
"alloc": {
"Daa9D9230fA7d30831dC2cfc624155120Bcf1793": {
"balance": "100000000000000000000"
},
"7fFFA35Ddd1Dcf33648F8F61C8a712bDBd8d52D2": {
"balance": "120000000000000000000000"
}
}
}
geth --datadir ./blockchainData init ./genesis.json
geth --datadir ./blockchainData --networkid 4785 console 2>> eth.log
eth.accounts
- create a new folder like blockchainData with another name
- initialize the genesis block for this folder
- run the following command to run a new node in a separate terminal
geth --datadir ./blockchainData2 --networkid 4785 --port 30305 --authrpc.port 8553 console
- the port and authrpc port must be changed for every node if running on the same machine
- In node 1 run
admin.nodeInfo
- copy the encode value and open the terminal of node 2, run the command and paste the value as a string in param
admin.addPeer()
- now open the terminal of node 1 or node 2 and run admin.peers to see if the node is added
admin.peers
- if it returns an array of objects it means nodes are peers. if an empty array its mean nodes are not peer
- now we will start mining
miner.setEtherbase(eth.accounts[0])
miner.start()
- to stop mining
miner.stop()
- to stop mining empty block add the following script
var mining_threads = 1
function checkWork() {
if (eth.getBlock("pending").transactions.length > 0) {
if (eth.mining) return;
console.log("== Pending transactions! Mining...");
miner.start(mining_threads);
} else {
miner.stop();
console.log("== No transactions! Mining stopped.");
}
}
console.log("checkWork() is defined");
eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });
checkWork();
- now run the node with the command (just need to add preload script| all others params are only for accessing it with metamask)
geth --networkid 47580 --datadir "./node1" --port 30303 --http --http.port '8545' --snapshot=false --ipcdisable --syncmode 'full' --allow-insecure-unlock --
http.corsdomain "" --http.vhosts "" --http.addr "0.0.0.0" --preload "startmine.js" console 2>> eth-new.log