So, how about to give it a try and create your very own blockchain? All you need is to follow the guide below.
Please note that we used Ubuntu, but the guide will be OK for people using other Linux distributions, MacOS (with Homebrew manager) and Windows 10 (using terminals and the latest stable binary).
Install Go Ethereum
Your first step is to install Go Ethereum (geth). Go Ethereum is one of the original implementations (along with C++ and Python) of the Ethereum protocol written in Go.
To install geth, Mac OS X users should use Homebrew, an additional package manager for MacOS. Homebrew installs the stuff you need but can't find in Apple store. Once you have the manager installed, run these commands:
brew tap ethereum/ethereum
brew install ethereum
To install Go Ethereum on Ubuntu, you only need to use apt-get. Run the following commands:
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:thereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
As for Windows users, they don't need to think too hard. All you need is to download the corresponding geth installation and run it.
Now you can create a new directory and write a json file to make a genesis block:
To create the genesis block, paste the following code into the newly created JSON file:
"extraData": "Custem Ethereum Genesis Block",
Press Ctrl+X, Y, Enter to save your new genesis block.
Create your blockchain
Run the following commands to create a blockchain (the maxpeers option is set to 0 in order to disable the network):
geth --datadir eth-new genesis.json init eth-new/genesis.json --networkid 123 --nodiscover --maxpeers 0 console
To make a new account and password type the following in the geth console (don't forget to specify login data in brackets). Oh, there's one more thing: you'll have to specify your new password twice:
The output after this should be a string of letters and numbers, i.e. an address of your account. To stay on the safe side, save the address specified somewhere else and exit (type "exit" and press Enter).
Send some ETH to your newly created account
Open the genesis block file once again and type the following:
Copy previously saved account address and paste it into the "alloc" brackets. Next, go ahead and give yourself an ETH balance. The amount shown next to "balance" below is equal to 10 ETH. Once you are done with making changes, save the file with Ctrl+X, Y, Enter.
Delete an old blockchain and create a fresh one. Use these commands to get rid of the old blockchain data and restart geth:
rm -rf chaindata dapp history nodekey
geth --datadir eth-new genesis.json --networkid 123 --nodiscover --maxpeers 0 console
In the geth console, type the following:
> primary = eth.accounts
> web3.fromWei(eth.getBalance(primary), "ether")
As a result, you get a new address and balance of 10 ETH.
To get yourself a full-fledged blockchain, you need to develop miners. To cope with this challenges, close the geth console (type "exit" + hit Enter).
Run the following command to start mining:
geth --mine --datadir eth-data --networkid 123 --nodiscover --> maxpeers 0 console 2>>geth.log
Congrats! You’ve just created your very own miner capable to collect ETH fees. If you want to check your cryptocurrency balance, run the following command:
> primary = eth.accounts
> balance = web3.fromWei(eth.getBalance(primary), "ether")
Install the Solidity Compiler
Just like other cryptocurrencies, the Ethereum uses the advantage of smart contracts written in Solidity. So, to use that contract-oriented programming language, you need to install the Solidity Compiler. To do this, type the following lines in a new terminal:
sudo add-apt-repository ppa:ethereum/ethereum
After getting a message: "Press ENTER to continue" press Enter and type the following:
sudo apt-get update
sudo apt-get install solc -y
This will provide a path to Solc that you'll need to remember. Now, return to the terminal window showing the geth console. Run the following commands, changing to the path value you got:
If you get ["Solidity"] as a response to the second command, it means, you got yourself the Solidity Compiler and can write in Solidity.
Difference between mortal and greeter contracts
Below is the code for a simple contract with added comments. It contains two types of contracts:
a mortal contract that can be killed by the person who wrote it and it needs to be declared as such, as contracts are immortal by default;
a greeter contract that is nothing but a "Hello World!" greeting.