Private Chain Construction

Prepare an Account

Access the working directory /directory/of/geth

$ ./geth account new --datadir ./data

The keystore file of the new account is located under the path/directory/of/dxc/build/bin/data/keystore.

Import the JSON file in Metamask.

Create genesis.json

  1. Create gensis.json file under /path/to/dxc/build/bin/

  2. Change chainId to 72

  3. Replace the initial address in extraData with your new account address

"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000a88548e97af8809afac9dc7a930650c1179510590000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
===>>>
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000'your new account'0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",

4. Set the initial balance in alloc for the new address, at least 0x50c783eb9b5c85f2a80000000

{
    "config": {
        "chainId": 72,
        "homesteadBlock": 0,
        "eip150Block": 0,
        "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "eip155Block": 0,
        "eip158Block": 0,
        "byzantiumBlock": 0,
        "constantinopleBlock": 0,
        "petersburgBlock": 0,
        "istanbulBlock": 0,
        "muirGlacierBlock": 0,
        "dpos": {
            "period": 3,
            "epoch": 28800
        }
    },
    "nonce": "0x0",
    "timestamp": "0x5fc58968",
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000a88548e97af8809afac9dc7a930650c1179510590000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": "0x280de80",
    "difficulty": "0x1",
    "alloc": {
        "0xa88548e97af8809afac9dc7a930650c117951059": {
            "balance": "0x50c783eb9b5c85f2a80000000"
        }
    },
    "number": "0x0",
    "gasUsed": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

Initialize the Genesis Block

$ ./geth init /path/to/genesis.json --datadir ./data

Start the Node

pageCompile and Run

Start Mining

  • Open the console ./geth attach --datadir ./data

  • Unlock miner account personal.unlockAccount("miner address","password",0)

  • Start mining miner.start()

Multi-nodes Mining

  1. Other nodes use the same genesis.json initial nodes

  2. Get the enode information for the master nodeadmin.nodeInfo

  3. New node geth attach

  4. Open the console, add the node information for master node admin.addPeer("enode info")

Last updated