ubuntu下載: https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
geth account new
git clone https://github.com/ethereum/go-ethereum
確保自己go的版本在1.7以上
ubuntu升級go版本(http://www.cnblogs.com/tianlongtc/articles/8856644.html)
sudo apt-get install -y build-essential golang
cd go-ethereum
make geth
You can now run build/bin/geth
to start your node.
記住你geth現在的路徑,以后要用的時候進到這個路徑來運行下面的代碼。
> 代表在geth里面執行, 不加>表示在terminal執行
創建賬戶
$ geth account new
> personal.newAccount("password")
查看賬戶
$ geth account list
快速同步模式
$ geth --fast console 2>network_sync.log
瀏覽日志
> tail -f network_sync.log
查看賬戶余額
> eth.getBalance(eth.accounts[ ])
解鎖賬戶
> personal.unlockAccount(eth.accounts[], <password>)
挖礦
$ geth --mine --minerthreads=4
> miner.start(8)
結束挖礦
> miner.stop()
查看挖礦速率
> miner.getHashrate()
查看區塊高度
> eth.blockNumber
查看挖礦賬戶
> eth.coinbase
設置挖礦賬戶
> miner.setEtherbase(eth.accounts[0])
預估手續費
> bytecode = ""
> web3.eth.estimateGas({data: bytecode})
以發起一個 0.01 個 ether 的轉賬交易為例
> var sender = eth.accounts[0];
> var receiver = eth.accounts[1];
> var amount = web3.toWei(0.01, "ether")
> eth.sendTransaction({from:sender, to:receiver, value: amount, gas: gasAmount})
在控制台里,使用這些命令檢查連接狀態
> net.listening:檢查是否連接
> net.peerCount:連接到的節點個數
> admin.peers:返回連接到的節點的詳細信息
> admin.nodeInfo:返回本地節點的詳細信息
賬戶操作
eth.accounts //查看賬戶 personal.listAccounts //查看賬戶 personal.newAccount("***") //新建賬戶 personal.unlockAccount("**********") //解鎖賬戶 personal.lockAccount("**********") //鎖定賬戶
代幣操作
eth.getBalance() //查看余額 web3.fromWei() //單位換算
節點操作
- net模塊
net.listening //查看節點狀態 net.peerCount // 查看節點鏈接的數量
- admin模塊
admin.nodeInfo //查看節點信息 admin.addPeer() //添加節點 admin.peers //查看添加的節點的信息
一些設置命令
miner.setEtherbase(eth.accounts[n]) //etherbase地址並不需要一定是本機上 miner.setExtra("zhou") //寫一些額外信息 eth.getBlock(n) //查看區塊信息
參考博客: