Geth搭建私鏈初學筆記

安裝geth客戶端

這裏採用的是github的安裝方法:

進入https://github.com/ethereum/go-ethereum

git clone 到本地,執行make geth

將geth添加到環境變量

sudo vim /etc/profile 添加:

export PATH=$PATH:/home/liu/geth/go-ethereum/build/bin

到最後一行,注意修改爲你自己的geth安裝地址

輸入 geth version 查看配置,注意:裝geth之前需要先裝go環境

創建測試私鏈

在上述github裏面有一段Genesis.json代碼

隨意創建一個空目錄:mkdir mychain   再 vim genesis.json

把json代碼複製進去,注意network id 改成15就好

然後geth init path/to/genesis.json創建私鏈

查看你的mychain目錄下是不是多了一個叫geth的文件夾

輸入geth --datadir . --networkid 15

在當前目錄下啓動networkid爲15的私鏈

和私鏈交互:

geth --datadir . --networkid 15 console

開啓私鏈的同時開啓控制檯(JavaScript)

常用命令 web3

eth.accounts:查看賬戶

Eth.getBalance("")查看賬戶餘額

Web3.fromWei(eth.getBalance(""),'ether'):轉換單位到以太

eth.blockNumber:區塊高度

Personal.newAccount()

查看賬戶餘額:

eth.getBalance(eth.accounts[0])

轉賬必須要解鎖:

Personal.unlockAccount(eth.accounts[0])

Miner.start(1)開始挖礦

Miner.stop()停止挖礦

geth --datadir . --networkid 15 console 2>output.log

 將輸出寫入到output.log

tail -f output.log 事實追蹤最新log

發佈了12 篇原創文章 · 獲贊 7 · 訪問量 3595
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章