current position:Home>Win10 uses geth client to build Ethereum private chain

Win10 uses geth client to build Ethereum private chain

2022-02-02 22:07:55 Stack_ scatter

One 、 Download and install Geth client

Download address*

Download the latest version of geth(win10 edition Stable releases)( Choose the version of your computer )
Choose the first 3 individual , Download and install ( When installing, you can choose a path convenient for your own operation ):
 Insert picture description here
 Insert picture description here

Open the folder when the download is complete :

 Insert picture description here

Verify that the installation was successful :

open cmd, Enter the following command ( View help documents ):geth -help

If the following content appears, the installation is successful

 Insert picture description here

So far, the Ethereum client has been installed

test geth Synchronize primary network ( If you configure the private chain, you can do nothing at this step )

Open it directly geth.exe

geth Will automatically run synchronization , At the beginning, the prompt also explains where the storage path of the block is

My path is :C:\Users\Edward\AppData\Roaming\Ethereum ( Usually in the administrator account path )

 Insert picture description here
 Insert picture description here

Be careful : To see AppData, You need to check the view hidden items in the view
 Insert picture description here

Two 、 Genesis block configuration file ( Start building a private chain : Be careful to turn off the... That is synchronizing the main network geth)

Create a new Genesis block file

stay geth New in the installation directory *genesis.json*( This is the file name ) file , Enter the following ( And save )

  "config": {
    "chainId": 8434,
    "homesteadBlock": 1,
    "eip150Block": 2,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 3,
    "eip158Block": 3,
    "byzantiumBlock": 4,
    "alien": {
      "period": 2,
      "epoch": 300,
      "maxSignersCount": 5,
      "minVoterBalance": 100000000000000000000,
      "genesisTimestamp": 1536136198,
      "signers": [
  "nonce": "0x0",
  "timestamp": "0x5b8f92c2",
  "extraData": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x1",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"

Description of important parameters

Parameter name describe
chainID A separate blockchain network is specified ID. The Internet ID It's used when connecting to other nodes , Ethereum public network ID yes 1, In order not to conflict with the public chain network , When running a private chain node, you need to specify your own network ID. Different ID The nodes of the network cannot connect to each other


The value is 0 Indicates that... Is in use homesteadBlock edition . The development of Ethereum is divided into four stages :( The progress of each stage to the next stage is realized by hard bifurcation )1.Frontier( the front ):2015 year 7 month 30 Japan , Ethereum released Frontier Stage , At this time, the software is not very mature , But it can be used for basic mining test and decentralized application (Dapps), The participants in this stage are mainly developers . 2.HomesteadBlock( home ): stay 2016 year 3 month 14 Japan ( PI node ), Ethereum released HomesteadBlock Stage . Ethereum began to run smoothly , A wallet that provides a graphical interface , Ordinary users can also experience and use Ethereum . 3.Metropolis( The metropolitan ):Metropolis It is divided into two stages :Byzantium( Byzantine ) and Constantinople ( Constantinople ). 2017.10.16, Ethereum Byzantine hard bifurcation success , The introduction includes :zk-SNARKs( Concise non interactive zero knowledge proof )、revert function 、return And abstract accounts . 2019 year 2 End of month , The... Of Ethereum blockchain 7,080,000 The block officially opened the Constantinople hard bifurcation as the activation point , The point is to change Ethereum's consensus mechanism from PoW towards PoW+PoS Mixed mechanism transition , So as to make the whole Ethereum network more lightweight 、 Fast and safe . Officially , Specifically in the existing Ethereum PoW The main network upgrades are as follows 5 In terms of :1).EIP 145: to EVM Shift dependent instruction increases , Including moving left SHL, Logical shift right SHR, Arithmetic shift right SAR(2).EIP 1014: A new rule for generating contract addresses , Related to status channel . The rule is keccak256( 0xff ++ address ++ salt ++ keccak256(init_code)))[12:](3).EIP 1052: by EVM increase EXTCODEHASH Instructions , This order can get a contract bytecode Of keccak256 Of hash value ;(4).EIP 1283: modify EVM Of SSTORE Instructions gas Calculation method , It is expected to reduce the cost of many contracts gas Consume , Requires hard bifurcation support ;(5).EIP 1234: Will be potentially the most controversial proposal , Hard bifurcation support is also required , It includes difficulty bombs (Difficulty Bomb) The agreement was postponed 12 Months and mining reward adjustment , The difficulty bomb makes mining more and more difficult over time , The mining reward adjustment will change the mining reward from 3 Down to 2 individual ;4.Serenity( quiet )
eip155Block eip yes ethereum improvement proposal Abbreviation , Your chain won't diverge because of these proposals , Therefore, it is set as “0” that will do
mixhash One 256 Bit hash proof , And nonce Use a combination of , It is proved that sufficient calculations have been made for this block : Proof of workload (PoW).
nonce One 64 Bit hash proof , And mixhash Use a combination of , It is proved that sufficient calculations have been carried out on this block : Proof of workload (PoW).
difficulty The current difficulty of setting blocks , If it's too difficult ,cpu Mining is hard , It's a little bit more difficult here
alloc Ethereum account information , You can leave it blank , Wait until the deployment is completed before starting Ethereum to create an account ; You can also pre configure the Ethereum account and its balance . The account balance here is in wei In units of .
coinbase Miner's account number , Random filling
timestamp Set the timestamp of the creation block
parentHash Of the last block hash value , Because it's genesis , So this value is 0
extraData Additional information , Random filling , You can fill in your personal information
gasLimit This value is set for GAS The total consumption limit of , Used to limit the total amount of transaction information a block can contain , Because we're private chains , So fill in the maximum .

3、 ... and 、 initialization

stay genesis.json Open under folder path cmd, Carry out orders :geth --datadir .\db init genesis.json
 Insert picture description here

After executing this command, it will be in geth An... Appears in the installation directory db Folder , among chaindata Store block data ,keystore Deposit account data

 Insert picture description here
 Insert picture description here

Four 、 Start node

command :geth --http --http.api db,eth,net,web3,personal --datadir .\db --networkid 1997 console 2>> log2020526.log

Be careful : During the construction process, my geth It has been in an unclosed state
Explanation of important parameters :

port: Specify the Ethernet listening port , The default is 30303

http: Turn on HTTP-RPC service , You can deploy and test smart contracts

http.api: be based on HTTP-RPC Provided API

http.addr: Appoint HTTP-RPC Service monitoring address , The default is localhost

http.port: Appoint HTTP-RPC Service monitor port number , The default is 8545

networkid: Specify Ethereum network id, The default startup id by 1, Represents the public chain , We built a private chain , So it's designated as chainId( stay genesis.json To configure )

console: Start command line mode

2>> log2020526.log: Redirect , Log

After successful startup, it is shown in the following figure :
 Insert picture description here

Node information can be verified
command :admin.nodeInfo

 Insert picture description here

5、 ... and 、 New account

Input eth.accounts View existing accounts :

 Insert picture description here
[] Description no account number

Enter the following instructions to create an account :personal.newAccount()

You will be prompted to enter the password , Need to remember , The test should not be too complicated

In double quotation marks is your address

After successful execution, the public key of the account will be generated ( Address ), And then in keystore The corresponding account file will be generated under the folder :
 Insert picture description here

You can view the balance of the corresponding account through the following command

eth.accounts[0] // Check the first account address


eth.getBalance(“0x7326bc89fe5a1d593afb5fa02479974be776a081”) // You can also fill in the address directly in brackets
 Insert picture description here
Found that the account balance is 0, Therefore, it is necessary to obtain ether coins through mining

6、 ... and 、 Download wallet MetaMask And import the created account

MetaMask It's a chrome plug-in unit
Once the download is complete , A little fox sign will appear in the upper right corner , It opens at , Click the network to show the hidden network localhost 8545( And connect )

There is a problem here, that is, import your own local account, and the little fox will collapse , Never responded ( I haven't solved it yet )

 Insert picture description here

So we adopt to import to our local private chain metamask Account created on

Reference resources :

 Insert picture description here

Export the private key

 Insert picture description here

Copy the private key to a local txt Save in file
 Insert picture description here

Then input

geth account import + Your private key file path

You will be prompted to enter the password , This code is in geth The password used by the console

It is found that the generated account is in MetaMask On account of .

View the location of the currently generated key file :

geth account list

Find the storage location behind the corresponding account , Put the file in the project where we created the private chain keystore In the folder .
 Insert picture description here
 Insert picture description here

stay geth Input in eth.accounts View the newly imported account

 Insert picture description here

7、 ... and 、 dig

The reward from mining goes to the miner's account , This account is called coinbase, By default coinbase It's the first account in a local account , As shown in the figure below : Instructions :eth.coinbase

 Insert picture description here

You can enter miner.setEtherbase( account number ) Set mining account

I now set the account just imported as the mining address
 Insert picture description here

Check the balance eth.getBalance( account number )
 Insert picture description here

Start mining with the following command , The parameter is the number of threads , I'm going to set it to 1**( Tips null Don't pay any attention to )**

 Insert picture description here

You can see that the account balance is increasing by entering instructions and opening the little fox

 Insert picture description here

 Insert picture description here

Stop mining with the following instructions miner.stop()

 Insert picture description here

At this point, our private chain construction is complete

Reference link

copyright notice
author[Stack_ scatter],Please bring the original link to reprint, thank you.

Random recommended