geth常用指令

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)  //查看区块信息

 

参考博客:

https://bitshuo.com/topic/5985c4c5876cd8953c30b378

posted @ 2018-04-16 18:42  tianlongtc  阅读(8992)  评论(0编辑  收藏  举报