1. Installing the Geth Client
Enter the command:
sudo add-apt-repository-y ppa:ethereum/ethereum#启动PPA储存库
sudo apt-get update#访问源列表里的每个网址, and read the software list and then save it to your computer
sudo apt-get install Ethereum#安装Go Ethereum
2. Check after installation is complete
Using commands
Geth versionTo check if the installation was successful
3. Creating catalogs and Genesis.json
mkdir Tmpprivate
CD tmpprivate/
Vim Genesis.json(If no vim command, can be installed, as shown)
Vim Genesis.json
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 are often encountered:
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.
4. Execute the command to create the Genesis block
geth--datadir "./" Init GENESIS.JSON
Attention:
At this point, you can note that at this time, the current directory will be added two folders Geth and KeyStore
Geth is a blockchain-related data store
User information in the chain is saved in the KeyStore
5. Start, create your own private chain
geth--datadir "./"--nodiscover console 2>>geth.log
Attention:
–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.
Open another terminal, locate the directory where the Geth.log is located, execute the command tail-f Geth.log and continue to output the Ethereum log
6. Create a user on your own private chain
Enter the command eth.accounts and we will find that the return value is []
This is because while the ethereum private chain has been created, there are no accounts yet.
Enter the command personal.newaccount ("xxx"), the command will create a new user, the user's password is xxx. Of course users can also change the XXX to 123, or 123456, or any password
Enter the command again eth.accounts, we will find a new user was created, which means we have created an account, repeat Personal.newaccount () & Eth.accounts We can create several accounts
7. Mining
Execute command Miner.start () on the command line and start digging on our blockchain
Attention:
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 the command miner.stop () to stop the 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 the Mac
5 after mining starts, view the number of etheric coins in the master account
ACC0 = Eth.accounts[0]
Eth.getbalance (ACC0)
Execute the command tail-f Geth.log thereby continuing the output of the Ethereum log, generating a chunk of the log record screenshot:
8. Trading
The public key (address) of each account is the core of all Ethereum account operations, but the address string is too long, we use ACC0/ACC1 respectively for accounts[0] and [1], and the other is set to transfer 0.01 etheric coins.
Use Eth.sendtransaction to transfer 0.01 of your etheric coins from acc0 to ACC1.
ACC0 = eth.accounts[0]
acc1 = eth.accounts[1]
amount = Web3.towei (0.01)
eth.sendtransaction ({from:acc0, TO:ACC1, Value:amount})
Screenshots:
Attention:
1. The reason the trading times are wrong is because
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. (pictured above)
2. After entering the order of the trade, I immediately check the acc1 balance and find that it is 0 ...
This is because the transaction submission has not been processed and we can verify through this by looking at Txpool.status, if we see pending:1,pending represents a transaction that has been submitted but not yet processed;
To make a deal, you have to dig mine. (as pictured above, I opened mine)
Screenshot of this successful transfer (but the first view is still 0):