天天看點

基于以太坊搭建聯盟鍊

yum install golang

yum install git

安裝go-ethereum:

git clone https://github.com/ethereum/go-ethereum.git
cd  go-ethereum
make geth
make all
修改環境變量:export PATH=/home/soft/go-ethereum/build/bin:$PATH
           

安裝node

(1)下載下傳node源碼:

https://nodejs.org/en/download/

上傳伺服器

(2)解壓:tar -xf node-v9.3.0.tar.gz

(3)安裝:

cd node
        ./configure
        make && make install           

(4)測試:node -v npm -v

安裝truffle:npm install -g truffle

建立項目:mkdir pet-shop-tutorial

cd pet-shop-tutorial
        truffle unbox pet-shop
           

初始化私有鍊:geth --datadir=./chaindata/ init ./genesis.json

啟動私有鍊:geth --datadir=./chaindata console

檢視節點資訊:admin.nodeInfo.enode

添加節點:admin.addPeer()*注意裡面的ip要換掉

檢視添加的節點資訊:admin.peers

查詢賬戶:web3.eth.accounts

添加賬戶:web3.personal.newAccount("123456")

查詢餘額:web3.eth.getBalance("0xbe323cc4fde114269a9513a27d3e985f82b9e25d") /eth.getBalance(eth.coinbase)

解鎖賬戶:web3.personal.unlockAccount(acc0,"123456")

交易:web3.eth.sendTransaction({from:acc0,to:acc1,value:web3.toWei(3,"ether")})

開始挖礦:miner.start()

停止挖礦:miner.stop()