This post contains the steps to setup a private Ethereum blockchain.
First, you’ll need a Linux vm. Please note that this post assumes a medium/advanced level of knowledge. As such, it will be much more succinct than most posts in other categories.
INSTALL ETHEREUM
CREATE DIRECTORY TO STORE THE BLOCKCHAIN
CREATE TWO ACCOUNTS
CREATE GENESIS BLOCK
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"ethash": {}
},
"difficulty": "1",
"gasLimit": "8000000",
"alloc": {
"0x849b1448F8Cca9F3BCeE21F1ebcC1545f12b8e25": { "balance": "300000" },
"0x140DBCb0eC85B62A66aCBf52DeEFd9F01abCc22A": { "balance": "400000" }
}
}
INITIALIZE THE GENESIS BLOCK
Add the accounts created into the genesisblock.json file and initialize the blockchain with the following command…
geth -datadir="/home/matt/privatechain" init "/home/matt/privatechain/genesisblock.json"
CHAINDATA AND LIGHTCHAINDATA
The chaindata and lightchaindata directories in geth indicate that your blockchain network has been created.
MINING THE BLOCK
While the first block is being mined, ethers will be being added to your address. It may take a while depending on your parameters set in your genesisblock.json file
Now that mining has begun, you can see the new files that have appeared in the privatechain filesystem
SUMMARY
The steps performed above can be summarised as follows.
You can stop the mining process using the miner.stop() command
SMART CONTRACTS
“Smart contracts” is the name to describe a program that is compiled to execute on the blockchain network. Such programs running on Ethereum blockchains are written in the Solidity language.
SMART CONTRACT DEVELOPMENT ENVIRONMENT
Download ganache from here
It’s an .appimage weighing in at around 146MB. TruffleSuite Ganache is produced by ConsenSys Software Inc.
chmod +x the ganache appimage file and execute it.
GANACHE
Enter the seed phrase from Ganache into the Seed phrase field in Brave
Connect to the local Ethereum blockchain network on port 8545 (Ganache’s internal eth network) and you’ll see an initial balance of 100 ETH tokens.
Click on the coloured icon next to Localhost:8545 and Import a Wallet
In Ganache, click on the Key icon on one of the wallets (choose the 2nd one in the list of pre-configured wallets). Copy and Paste the private key into the Import screen shown above.
You can see in the screenshot above, two Accounts have been imported, each with a balance of 100 ETH tokens. You can import as many of the ETH wallets from Ganache as you like/need for your Solidity Smart Contract project.
Since Ganache is connected to our local private blockchain running on our localhost on port 8545, you can see the details of the genesis block in the BLOCKS section
REMIX SOLIDITY IDE
Next we need an IDE for creating code when developing, compiling and deloying Solidity smart contracts that will use our connected wallets to pay the gas fees required to store the smart contract on our private blockchain. Remix is a web-based IDE for this purpose.
Compile all the scripts 1_Storage, 2_Owner, 3_Ballot and 4_Ballot_Test files. Deploy the 4_Ballot_Test file.
CONFIRM TRANSACTIONS
The transactions in the smart contract will require confirmation by the owner of the connected wallet before being submitted to the private blockchain we created earlier where they’ll be mined.
AUDIT TRANSACTIONS STORED IN MINED BLOCKS
In Ganache that we connected to our local private Ethereum blockchain, you can click on the BLOCKS section and see the mined blocks that contain our recent two transactions, the date stamp of the transaction and gas used.
SUMMARY
So far, we have…
Installed Ethereum
Created a private Ethereum blockchain on our localhost
Initialised the private blockchain
Mined the Genesis block in our private blockchain
Installed Ganache and connected it to our private blockchain
Imported two of the ETH wallets in Ganache to our Web Browser’s crypto wallet extension
Connected to Remix Solidity Smart Contract IDE
Connected Remix to one of our ETH Wallets
Compiled some Solidity Code Smart Contracts
Deployed the BallotTest smart contract to our private blockchain, confirming the transactions and accepting the gas fees.
Audited the mined blocks containing our transactions in Ganache
EXTRAS
The other smart contracts were compiled and deployed, and new blocks containing those transactions show up in Ganache.
FINAL WORD
Note that all this information is referenced from the same blockchain, instead of the necessity of trusted third parties storing the same data in multiple places that could be changed and a conflict introduced into the history of the transactions in potentially mismatched ledgers. In addition to having an accurate central ledger that all parties reference, we can introduce more nodes in our network that each maintain a copy of the same blockchain.
The public ETH network that maintains the main net has many thousands of ETH nodes. It is this decentralised consensus that gives the value to blockchain, along with public keys being used to verify that the parties transacting have the necessary funds without revealing the private keys necessary to unlock those funds to the public internet.
The input and outputs between the wallet addresses are performed by the closed network, keeping everybody safe. The issuance of new coins is also controlled by the network to prevent abuse of the inflation rate that could affect the purchasing value of the tokens by driving the value down by diluting the supply ad infinitum (hyper inflation caused by excessive quantitative easing, effectively) .