Ethereum development environment construction

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

  1. create a directory andgenesis.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": { } }
  2. 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 gethand keystore:

    • The data stored in geth is the relevant data of the blockchain
    • The keystore saves the user information in the chain
  3. Create your own private chain
  • Execute the simplest geth command to create your own private chain
    geth --datadir "./" --nodiscover console 2>>geth.log
  1. Create users on your own private chain
  • input the commandeth.accounts

    You can see that there are currently several accounts in the blockchain, and the public key address of each account
  • Create a new user with password xxxpersonal.newAccount("xxx")
  1. Output the log of the blockchain
  • Execute the following command

    geth --datadir "./" --nodiscover console 2>>geth.log

    Enter command line mode, where the parameter
    • --datadirRepresents the folder address
    • --nodiscoverIt means that the chain does not want to be discovered by other nodes,
    • console >> geth.logRepresents the console output to the file geth.log
  • Open another terminal, find geth.logthe directory where it is located, and execute the command tail -f geth.logto continuously output the logs of Ethereum

  1. 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文件夹和里面的文件即可。
  1. 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!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326431701&siteId=291194637