Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

创建私链

  1. 创建账户

geth

  1. 初始化

geth --datadir smallc init genesis.json

  1. 启动

geth --identity smallchain --http --http.api net,web3,eth,personal --datadir smallchain --mine --miner.threads 0 --http.corsdomain "*" --http.addr 0.0.0.0 console --networkid 666

  • miner.threads 线程数量,默认是0

参数说明

identity //唯一标识,在众多节点中快速找到当前节点 networkid // 当前节点网络id

genesis.json

{   
    //64位随机数,用于挖矿,注意他和mixhash 的设置需要满足以太坊黄皮书的要求
    //直接用这个也可以
    "nonce":"0x0000000000000042",
     //与nonce 共同用于挖矿,注意他和mixhash 的设置需要满足以太坊黄皮书的要求
    "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",
    //挖矿难度,你可以随意控制,这里设置的难度比较小
    "difficulty": "0x4000",
    //用来提前设置帐号的以太币数量,例:
    //"alloc": {
    //“0x0000000000000000000000000000000000000001”:{"balance":"10000000"},
    //"0x0000000000000000000000000000000000000002":{"balance":"20000000"}
    //},
    "alloc": {},
    //挖矿的账户,默认钱包地址,这里因为没有地址,所有全是0
    //后面运行geth 后创建新账户时,如果geth 发现没有地址,会默认将第一个账户地址设置为矿工帐号
    "coinbase":"0x0000000000000000000000000000000000000000",
    //创世块的时间戳
    "timestamp": "0x00",
    //上一个区块的Hash值,因为是创世块,前面没有,所以是0
    "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
    //附加信息,随便填文本或不填也行
    "extraData": "0x00000000",
    //gas 最高限制,以太坊运行交易,合约等消耗的gas最高限制,这里设置为最高
    "gaslimit":"0xffffffff",
    "config": {
        "chainId": 666, //链ID 随便起 和主链、测试连不同就OK,公链ID为1
        "homesteadBlock": 0,
        "eip150Block": 0,
        "eip155Block": 0,
        "eip158Block": 0,
        "byzantiumBlock": 0,
        "constantinopleBlock": 0,
        "petersburgBlock": 0,
        "istanbulBlock": 0
    },
}

完整例子

{
    "config": {
        "chainId": 666,
        "homesteadBlock": 0,
        "eip150Block": 0,
        "eip155Block": 0,
        "eip158Block": 0,
        "byzantiumBlock": 0,
        "constantinopleBlock": 0,
        "petersburgBlock": 0,
        "istanbulBlock": 0
    },
    "alloc": {
        "aee29ddd94a36f6d3415310046863929a59e30be": { "balance": "100" }
    },
    "coinbase": "0x0000000000000000000000000000000000000000",
    "difficulty": "0x2000",
    "extraData": "",
    "gasLimit": "0x2fefd8",
    "nonce": "0x0000000000000042",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp": "0x00"
}