ubuntu系统搭建以太坊私有链

一、安装curl、gitnode

apt-get updatelinux

apt-get install gitgit

apt-get install curlgolang

二、安装gonpm

curl -O https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gzubuntu

Unpack it to the /usr/local (might require sudo)api

tar -C /usr/local -xzf go1.5.1.linux-amd64.tar.gzbash

三、配置go的环境变量cors

mkdir -p ~/go; echo "export GOPATH=$HOME/go" >> ~/.bashrcdom

echo "export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin" >> ~/.bashrc

source ~/.bashrc

验证go :

go version

四、nodejs、npm

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

apt-get install nodejs

验证是否安装成功

node -v

npm -v

五、安装以太坊环境

sudo apt-get install software-properties-common

sudo add-apt-repository -y ppa:ethereum/ethereum

sudo add-apt-repository -y ppa:ethereum/ethereum-dev

sudo apt-get update

sudo apt-get install ethereum

六、安装solc(solidity编译环境)

sudo add-apt-repository ppa:ethereum/ethereum

sudo apt-get update

sudo apt-get install solc

七、建立三个帐户

连续输入三次命令:geth account new

获得三个公钥地址

八、编辑创世块文件

将三个地址放入"alloc"中,

{
    "nonce": "0x0000000000000042",
    "difficulty": "0x1",
    "alloc": {
        "0d2e08a2615d5c46734058f34b307db0eda5ba6e": {
            "balance": "20000009800000000000000000000"
        },
        "1f9035c1ed2802fe7f96e8a28890d8816af14c9c": {
            "balance": "20000009800000000000000000000"
        },
        "59b0a1db6b4de1d303d440da1d02fafd3f4f41af": {
            "balance": "20000009800000000000000000000"
        }
    },
"config": { "chainId": 15, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 },
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x0000000000000000000000000000000000000000",

"timestamp": "0x00",

"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",

"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",

"gasLimit": "0xb2d05e00"
}

注意:划线部分若是不添加,会出现如下错误:

 

九、配置自动解锁帐号的脚本

在./ethereum下建立password文件,在里面输入密码,每一个帐号一行密码如:

123456
123456
123456

十、配置以太坊启动脚本private_blockchain.sh(名字自取)

geth --rpc --rpcaddr="0.0.0.0" --rpccorsdomain="*" --unlock '0,1,2' --password ~/.ethereum/password   --nodiscover --maxpeers '5' --networkid '1234574' --datadir '~/.ethereum'  console

每次启动geth节点时,只须要输入一下命令

bash private_blockchain.sh

十一、启动后,输入eth.getCompilers(),可能会出现一下状况

这是由于,安装以太坊环境时自动下载了geth客户端是1.6以上版本的,可是1.6版本客户端中没有getCompilers()函数,后续可能会开发别的方法来实现这个功能。

个人解决办法是下载geth1.5.9版本,覆盖掉原来的geth。

以后,输入eth.getCompilers(),会出现,

这是由于没有指定编译器,另开一个终端,输入which solc

以后,在geth终端中输入:

会出现这个是由于我用的ubuntu虚拟机,提示我虚拟机的内存不足,当我把虚拟机内存增长到2G后,这个问题就解决了。

再次输入:

大功告成!

相关文章
相关标签/搜索