美文网首页
私有Ethereum 搭建

私有Ethereum 搭建

作者: SeanC52111 | 来源:发表于2020-08-14 19:08 被阅读0次

    首先,将go-ethereum从github上clone下来

    git  clone https://github.com/ethereum/go-ethereum.git
    

    然后,安装最新版本的GO语言包
    因为geth需要使用GO和C的编译器,所以执行以下代码:

    sudo apt-get install -y build-essential
    

    最后,进入go-ethereum文件夹,并编译go-ethereum:

    cd go-ethereum
    make geth
    

    编译好之后,可以在build/bin/geth中执行geth
    创建private-ethereum文件夹用来保存key和数据,并进入private-ethereum文件夹

    mkdir private-ethereum
    cd private-ethereum
    

    在执行geth之前,首先创建账户

    geth --datadir ./data account new
    

    并记住产生的账户地址
    随后在private-ethereum中创建genesis.json文件

    {
        "config" : {
        "chainId": 10,
        "homesteadBlock": 0,
      "eip150Block": 0,
      "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "eip155Block": 0,
      "eip158Block": 0,
      "byzantiumBlock": 0,
      "constantinopleBlock": 0,
      "petersburgBlock": 0,
      "ethash": {}
        },
        "difficulty" : "0x10",
        "extraData"  : "0x00",
        "gasLimit"   : "0xffffffffff",
        "nonce"      : "0xdeadbeefdeadbeef",
        "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
        "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
        "timestamp"  : "0x00",
        "alloc"      : {
            "0x004E00477eC7729D5FE105e27BAeFbBeAa4a4f12": { "balance": "9999999999999" },
            "0x806EFBbefD03Fb4817Cc049997a57A683FEcfa28": { "balance": "9999999999999" }
        }
    }
    

    注意,alloc里面的地址即为刚刚创建好的账户地址,并且为他们分配了一定量的balance
    有了genesis.json文件,我们就可以初始化区块链数据:

    geth --nousb --datadir ./data init genesis.json
    

    随后便可以启动geth:

    geth --allow-insecure-unlock --nousb --identity "newEth" --rpc --rpcport 8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*" --datadir "data" --port 30303 --rpcapi "eth,net,web3" --networkid 999 console
    

    注意,这里面--allow-insecure-unlock可以在console中解锁账户。

    如果需要使用POA挖矿方式,使用一下genesis.json

    {
        "config" : {
        "chainId": 10,
        "homesteadBlock": 0,
      "eip150Block": 0,
      "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "eip155Block": 0,
      "eip158Block": 0,
      "byzantiumBlock": 0,
      "constantinopleBlock":0,
      "petersburgBlock": 0,
      "clique": {
        "period": 1,
        "epoch": 300
    }
        },
        "difficulty" : "0x00",
        "extraData"  : "0x0000000000000000000000000000000000000000000000000000000000000000004e00477ec7729d5fe105e27baefbbeaa4a4f120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "gasLimit"   : "0xffffffffffff",
        "nonce"      : "0xdeadbeefdeadbeef",
        "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
        "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
        "timestamp"  : "0x00",
        "alloc"      : {
            "0x004E00477eC7729D5FE105e27BAeFbBeAa4a4f12": { "balance": "0xffffffffffff" },
            "0x806EFBbefD03Fb4817Cc049997a57A683FEcfa28": { "balance": "0xffffffffffff" }
        }
    }
    

    注意,extraData中间为signer的地址。

    相关文章

      网友评论

          本文标题:私有Ethereum 搭建

          本文链接:https://www.haomeiwen.com/subject/hivpwctx.html