SetUp a Private Ethereum Node

Iqra Naz
4 min readAug 23, 2022

--

In this blog, I will explain a detailed step by step procedure of setting up a private ethereum node on local machine. So let’s get started.

Step# 1: Installation
First of all we will have to install node from https://nodejs.org/en/download/,
Geth(Go-Ethereum) from https://geth.ethereum.org/downloads/,
Truffle by npm install -g truffle
and solidity compiler from https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity.

Step# 2: Setup and Configuration
Then we will create a genisis block and will initite chain in blockchain.
So create a folder/directory and then create a file named genesis.json
You can either use visual studio or any other code editor and place the code below in genesis file.

Here we have chain id that is unique identifier of blockchain, homestead block is first production release of chain, difficulty controls the complexity of mining puzzle, gas limit indicates the maximum amount of gas can be used to execute contract and alloc allows allocation of ethers to any specific address.

Step# 3: Creating a Folder for Blockchain
Now create a folder with command
mkdir blockchain
where blockchain will reside and initialize genesis.json in that folder using command
geth — datadir blockchain init genesis.json
later, you can see two more folders in your blockchain folder geth and keystore.

Step#4: Run Private Ethereum Blockchain
Now in your main folder privateBlockchain in my case, open a new terminal and run command
geth — port 3000 — networkid 58343 — nodiscover — datadir=./blockchain — maxpeers=0 — http — http.port 8543 — http.corsdomain “*” — allow-insecure-unlock — http.api “eth,net,web3,personal,miner”
and you will see something like this.

Now open a new terminal in main folder and run command
geth attach http://127.0.0.1:8543
This will open a Geth Javascript console. Now we can create a personal account here by following commands.
personal.newAccount(‘seed’)
personal.unlockAccount(web3.eth.coinbase, “seed”, 15000)

Now we can start mining fake ethers, can check balance and able to stop mining. You can also check ethers being mined on Geth network terminal window. Use following command.
miner.start()
web3.fromWei(eth.getBalance(eth.coinbase), “ether”)
miner.stop()

Step# 5: Creating a Smart Contract and Deploy it to Network
Now, we will create a new folder inside mean folder and will initialize truffle and create all the necessary files and folders inside it by following commands.
mkdir truffle
cd truffle
truffle init

Then, we will have to create smart contract by creating a new file “HelloWorld.sol” inside contract folder in truffle directory and put the code below. This smart contract is written in solidity language.

Now, go to migrations folder and create a file “2_deploy_contract.js” and put the code below.

Now, update “truffle-config.js” with the following code. This include all our network details and account addressed we generated privately before.

Now compile the smart contract we created in truffle and deploy it to our private ethereum network.

Hence, our contract is deployed to our private ethereum network.
Here you can see two contracts creation on private network with contract address and deployer address. One is highlighted and the other can be found in last lines of the image below.

Now open truffle console by the command to launch it from terminal
truffle console
Here, we can interact with our deployed contract by these command below.
var dApp
HelloWorld.deployed().then(function(instance) { dApp = instance; })
dApp.message.call()

--

--

Iqra Naz
Iqra Naz

Written by Iqra Naz

Software Engineer >Tech-Enthusiast > Blockchain Developer > Web Developer >Quantum Computing Explorer

No responses yet