This article is based on the Geth client mentioned earlier in this article, explaining how to build your own private chain, as well as account management and transfer transactions.
1. The Genesis block file
The first chunk on the blockchain is called the Genesis block, and the creation of our private chain can be declared and defined by the creation block configuration file. Store the following file contents as a Genesis.json file
{
"Coinbase": "0x0000000000000000000000000000000000000000",
"config": {
"Homesteadblock": 5
},
"difficulty": "0x20000",
"Extradata": "0x",
"Gaslimit": "0x2fefd8",
"Mixhash": " 0x00000000000000000000000000000000000000647572616c65787365646c6578 ",
" nonce ":" 0x0 ",
" Parenthash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ",
" timestamp ":" 0x00 ",
" Alloc ": {
"Dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6": {
"balance": "100000000000000000000000000000"
}
}
}
2. Create a private chain
Open the command line, navigate to the file address path to save the private chain, initialize the private chain, open the private chain
To configure the default number of Etheric tokens for an account via the initialization file, add the user to the console and replace the account address with the Genesis.json alloc
DBDBDB2CBD23B783741E8D7FCF51E459B497E4A6, and then re-execute Geth--datadir "Privatechain" Init Genesis.json,
Another way is to add an account, the execution of mining Miner.start () to start mining, miner.stop () stop mining, during the period of the ether is automatically stored in the
The first account.
Operation commands as shown in figure
Private chain Creation success
Go to the console
Create a new user and view his balance
Modify the address of the new user to the Genesis.json file and re-geth the--datadir "Privatechain" init Genesis.json and go to the console to view the user balance
3. Account Management
On the command line we can create another account for subsequent transactions.
4. Trading
Transfer the balance of one account to the second account via the command line and see if it is credited. First unlock the status of each user and then define a variable to accept the account address
(Not defined or Yes, definition looks more concise)
Note that the trade fair costs gas, so see account one plus the balance of account two is not enough before the total amount. In addition, since the transaction must start mining to be synchronized to the block,
After the completion of the transaction will need to start mining. Due to the private chain environment, mining difficulty is very low, start mining will increase the account of the etheric currency.
And then execute
Miner.start ()
Stop mining after a while to see if the deal is complete
Miner.stop ()
Finally check the balance of account two
We can get a basic understanding of how ethereum blockchain technology works, and we will do this as a smart contract based on this.