Ethereum creates a private chain go-ethereum

Table of contents

start node sync

Synchronize mainnet blocks

Synchronize the blocks of the testnet

Synchronize the blocks of the Ropsten testnet

 Synchronize RinkeyBy test network blocks

Build your own private chain 

Create genesis.json

init initialize gensis.json 

Start private chain


start node sync

Synchronize mainnet blocks

Geth is installed, now we can try to run it as follows. Execute the following command, geth will start synchronizing blocks and store them in the current directory. The --syncmode fast parameter here means that we will sync blocks in "fast" mode.

In this mode, we direct the download of each block header and block body , but do not verify all transactions until all blocks are synchronized before obtaining the state of a system. This saves a lot of time in transaction verification.

geth --datadir .--syncmode fast

Usually, when synchronizing the Ethereum blockchain, the client downloads and verifies each block and each transaction at the beginning , that is, it can start from the genesis block.

There is no doubt that if we don't add --syncmode fast parameter, sync will take a long time and has high resource requirements (it will need more RAM, and if you don't have fast storage, it will take a long time) .

Some articles will write this parameter as --fast, this is the parameter writing method of the fast synchronization mode in the past, and it has been replaced by

--syncmode fast replaces

Synchronize the blocks of the testnet

Synchronize the blocks of the Ropsten testnet

geth --testnet --datadir .--syncmode fast

 --testnet This parameter will tell geth to start and connect to the latest test network, which is Ropsten. The number of blocks and transactions of the test network will be significantly less than that of the main network, so it will be faster. But even syncing the testnet in quick mode can take hours.

 Synchronize RinkeyBy test network blocks

geth --Rinkeby --datadir .--syncmode fast


Build your own private chain 

Create genesis.json

Because there are too many blocks in the public network and synchronization takes too long, we can quickly understand Geth in the future, and we can try to use it to build a private chain that only belongs to us

First, we need to create the "genesis" state of the network, which is written in a small JSON file (for example, we named it genesis.json):

chainId: chain id, try not to be consistent with public chain id and test chain id

difficulty: mining difficulty coefficient, 2000 is not too big

gasLimit: the upper limit requirement of gas in a block

alloc: Initial account information, including an address and object, indicating how much money is in the balance once the genesis block is created

balance: balance, the unit is wei

{
    "config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0
    },
    "alloc": {
    "0x1E17ECE93b3c72277E4B22a58B87934C9F654089":{"balance":"900000000000000000000"}},
    "coinbase": "0x0000000000000000000000000000000000000000",
    "difficulty": "0x200",
    "extraData": "",
    "gasLimit": "0x2fefd8",
    "nonce": "0x0000000000000042",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp": "0x00"
}

init initialize gensis.json 

To create a blockchain with it as the genesis block, we can use the following command:

Where path/to/custom/data/folder is the directory where you store

geth --datadir path/to/custom/data/folder init gensis.json

 

 init initial trial private chain success

geth --datadir ~/桌面/geth-project/myChain/ init ~/桌面/geth-project/myChain/genesis.json

Start private chain

Running geth in the current directory will start this private chain

Note that the networkid must be set to be consistent with the chainId in the genesis block configuration

geth --datadir path/to/custom/data/folder --networkid 15

We can see that the node started normally:

geth --datadir ~/桌面/geth-project/myChain --networkid 15

In this way, we have started a private chain of our own

Guess you like

Origin blog.csdn.net/m0_46262108/article/details/123273386