1. Install Geth Client
Geth is the Go Ethereum, which is the Ethereum client implemented with the go language. Geth is a concrete implementation of the Ethereum protocol, through Geth, you can realize the various functions of ethereum, such as the new edit delete account, open mining, ether currency transfer, intelligent contract deployment and implementation and so on.
Download Address: https://geth.ethereum.org/downloads/
Installation Guide: Https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum
2. Start building Chain (refer to Blockchain Academy)
Step1: Creating Directories and Genesis.json
I set up the Tmpprivate folder in e-disk, in this folder to build Genesis.json files, open with notepad++, write to the inside:
{"
config": {
"Chainid": "
Homesteadblock": 0,
"Eip155block": 0,
"Eip158block": 0
}, "
nonce": "0x0000000000000042",
"timestamp": "0x00",
"Parenthash": " 0x0000000000000000000000000000000000000000000000000000000000000000 ",
" Extradata ":" 0x00 ",
" GasLimit ":" 0x80000000 ",
" difficulty ":" 0x400 ",
" Mixhash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ",
" Coinbase ":" 0x3333333333333333333333333333333333333333 ",
" Alloc ": { }
}
parameter Description:
Mixhash |
A hash that is generated by a portion of the previous block in conjunction with a nonce for mining. Note that he and the nonce settings need to meet Ethereum's yellow paper, 4.3.4. Block Header Validity, (44) The conditions described in the chapter: |
nonce |
a nonce is a 64-bit random number used to mine mining, noting that his and mixhash settings need to meet the Ethereum yellow paper, 4.3.4. Block Header Validity, (44) The conditions described in the chapter. |
Difficulty |
the difficulty of setting the current block, if the difficulty is too large, the CPU mining is difficult, here set a small difficulty |
Alloc |
The number of etheric coins used to pre-provision accounts and account numbers, because the private chain mining is easier, so we do not need to pre-set the account of the currency, when needed to create their own. |
Coinbase |
the miner's account, just fill it out. |
timestamp |
set the time stamp of the Genesis Block |
Parenthash |
The hash value of the previous chunk, because it is a Genesis block, so this value is 0 |
Extradata |
additional information, please fill in, can fill in your personal information |
Gaslimit |
This value sets the total consumption limit for gas, which is used to limit the sum of the transaction information that the block can contain, since we are the private chain, so fill the maximum. |
Several errors that may occur:
Fatal:invalid Genesis file:missing 0x prefix for hex data: This error message is very clear, it is your JSON file, for 16 binary data, you need to add a 0x prefix
Fatal:invalid Genesis File:hex String has odd length: Starting with v1.6, set the hexadecimal value, cannot be an odd digit, such as cannot be 0x0, but should be 0x00.
fatal:failed to write Genesis Block:genesis have no chain configuration: This error message, that is, the config part is missing from your JSON file. Seeing this information, we do not need to return the Geth to the v1.5 version, but we need to add the config section.
Error:invalid Sender undefined: This error will not cause the initialization to fail, but will occur at a later transfer (eth.sendtransaction), or when the smart contract is deployed. The workaround is that Chainid cannot be set to 0. This error will occur if you follow the official profile given on GitHub. Step2: Creating a Genesis block
command line into the Tmpprivate directory, enter
Geth--datadir "./" Init Genesis.json
Complete creation of the creation block, the results are as follows:
At this point, you can notice that the current directory will add two folders Geth and KeyStore:
Geth is a blockchain-related data store KeyStore stored in the chain is the user information step3: Create your own private chain
Execute the command to create a private chain:
Geth-DataDir "./"--nodiscover console 2>>geth.log
Parameters:
–datadir represents the folder address,
--nodiscover indicates that the private chain does not allow nodes on the public network to discover
The code console 2>> Geth.log represents a portion of the console output, output to the file Geth.log up. Execution Result:
STEP4: Create an account on your own private chain.
Enter Eth.accounts, return []
Because there are no users now, you need to create a user, execute
Personal.newaccount ("123")
A user is created, and "123" refers to a password.
You can execute this command more than once, generating several more users.
Results:
STEP5: Log of the output chunk chain
Here need to use tail.exe this thing, because Windows does not, so need to download, download and unzip in C:\Windows\System32 folder can.
Open a command-line window, enter the Geth.log directory, execute tail-f Geth.log can continue to see the changes in log content.
STEP6: Start Digging mine
The first command-line window executes the Miner.start () command, which starts the mining (the return value is true after the online execution of this command, but my return value is NULL, but finally mine is successful.) Not understand here). Then take a look at the log changes in the second window.
Some of the contents of the log:
For the first time, Mr. Mining will be the Dag file needed to dig the mine, this process is a bit slow, and when the progress reaches 100%, it will start digging, and the screen will be mining information brush screen.
Note the point: 1. Ether coins dug into the mine will be covered by default in the first account, i.e. eth.acccounts[0]. 2. Mining is the basis for implementing smart contracts. If you stop digging, not only will the etheric currency stop generating, but the call of all smart contracts will not work. 3. If you really want to stop mining, you can execute command miner.stop () to stop mining 4. According to the above command, it should be possible to achieve ethereum mining. If not, it could be a chain that existed before, and the previous data should be deleted. Delete the Ethash folder and the files inside windows. STEP7: View the number of ether coins dug in
ACC0 = eth.accounts[0]
eth.getbalance (ACC0)
Results:
As long as the quantity is not 0, it means that the mine has been successfully mined.
STEP7: Transfer of the etheric currency between two accounts
Show two accounts first (Acc0 has been written before, can not write)
ACC0 = eth.accounts[0]
acc1 = eth.accounts[1]
Set the transfer quantity, such as transfer 0.01 Ethereum (unit conversion):
Amount = Web3.towei (0.01)
Start transfer:
Eth.sendtransaction ({from:acc0, to:acc1, Value:amount})
However, it may fail, similar to the following illustration:
This is a protective mechanism for ethereum, and the account is automatically locked at every time, and this time any conversion between the accounts of the etheric currency will be rejected unless the account is unlocked.
This time we need to execute Personal.unlockaccount (acc0) and enter the password to unlock acc0. And then re-execute
Eth.sendtransaction ({from:acc0, to:acc1, Value:amount})
This order.
Check ACC1 's account at this time and the number of etheric coins will not be 0.
It is also important to note that in the account of the transfer of the etheric currency, mining can not be stopped, or the transfer will not be successful.
(This is the only one that will be added later)