Geth installation
The full name is Go Ethereum, official website address: https://github.com/ethereum/go-ethereum/wiki/geth
Installation instructions:
brew tap ethereum/ethereum
brew install ethereum
Version detection:
geth version
Ethereum production network/test network/private network
测试网络
It is officially provided for development, debugging and testing.- Because the network is officially provided, the understanding of the underlying implementation of Ethereum technology, various parameter interfaces of Geth, and the real performance of the entire Ethereum technology will be much weaker.
- From a development point of view, a better choice is Private Network, which can deeply understand Ethereum from the bottom of the technology.
private network
Ethereum 私有网络
, as the name suggests, is a private network created by users themselves through Geth, which is a network that is very suitable for development, debugging and testing.
advantage
- It is convenient for developers to deeply understand the technical bottom layer of Ethereum
- Because there are relatively few nodes, the speed is faster
- Users can create at any time, destroy at any time, and rebuild an Ethereum network at any time
- Randomly increase the number of nodes, or delete nodes,
- It can be created on the server or on your own Windows or Mac machine
- Even one machine can establish multiple nodes to implement a multi-node private network on one machine.
shortcoming
- Because it is not global, only nodes in the private network can view the execution, invocation, etc. of smart contracts.
Build a private network
- create a directory and
genesis.json
- Create a directory, e.g. tmpPrivate
- Create the file genesis.json and fill in the following content
{ "nonce": "0x0000000000000042", "timestamp": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x0", "gasLimit": "0x80000000", "difficulty": "0x1", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x3333333333333333333333333333333333333333", "alloc": { } }
Execute the command to create a genesis block
geth --datadir "./" init genesis.json
After execution, two new folders will be added under the current directory
geth
andkeystore
:- The data stored in geth is the relevant data of the blockchain
- The keystore saves the user information in the chain
- Create your own private chain
- Execute the simplest geth command to create your own private chain
geth --datadir "./" --nodiscover console 2>>geth.log
- Create users on your own private chain
input the command
You can see that there are currently several accounts in the blockchain, and the public key address of each accounteth.accounts
- Create a new user with password xxx
personal.newAccount("xxx")
- Output the log of the blockchain
Execute the following command
Enter command line mode, where the parametergeth --datadir "./" --nodiscover console 2>>geth.log
--datadir
Represents the folder address--nodiscover
It means that the chain does not want to be discovered by other nodes,console >> geth.log
Represents the console output to the file geth.log
Open another terminal, find
geth.log
the directory where it is located, and execute the commandtail -f geth.log
to continuously output the logs of Ethereum
- start mining
- Execute the command
miner.start()
to start mining on our blockchain
important point:
1. 挖矿挖到的ether币会默认保存在第一个账户中,即eth.acccounts[0]中。
2. 挖矿是执行智能合约的基础。如果停止挖矿的话,不仅以太币会停止生成,所有智能合约的调用也会不起作用。
3. 如果真的要停止挖矿,可以执行命令miner.stop()来停止挖矿
4. 按上面的命令,应该是可以实现以太坊挖矿的。如果不行的话,有可能就是之前有存在的链,此时应该删除之前的数据。在Mac下即删除~/.ethash文件夹和里面的文件即可。
- After mining starts, check the amount of ether in the main account
acc0 = eth.accounts[0]
eth.getBalance(acc0)
As long as the result is not 0, it means that the mining is successful!