以太坊系列 - geth常用命令

启动

开第一个

geth --datadir "目录" --keystore "目录" console
--datadir   指定以太坊数据和密钥目录,在开启私有链时需要指定私有链目录,默认为公有链目录
--keystore   指定keystore文件(账户密钥文件)目录,默认值在datadir目录下

在开启一个geth客户端的情况下,如果想要再开一个geth客户端,可以使用geth attach命令。

#attach到其他geth客户端
./geth attach ipc:/root/.ethereum/geth.ipc
./geth attach ./devChain/geth.ipc

启动后

若一開始建立沒有 RPC,但想要加入 RPC 可以 attach 後,輸入以下 function:

admin.startRPC("0.0.0.0", 8545, "*", "eth,web3,personal,net,miner,admin,db")

查看同步状态

eth.syncing

查看当前同步高度

eth.blockNumber

查看当前是不是已经连上其他节点了

net.peerCount

查看当前同步节点的详细信息

admin.peers

其它

1、eth.accounts     查看账户
2、eth.sendTransaction({
    
    from:"",to"",value:web3.toWei(2,"ether")})      从一个地址给另一个地址发送代币
3、eth.getTransaction("txid")    通过txid查询一个交易的信息
4、personal.newAccount("123456")      新建一个账户,密码为123456
5、personal.unlockAccount("address","password")      解锁账户
6、miner.start(1);admin.sleepBlocks(2);miner.stop(); 生产区块,生产2个块之后停止生产
7、eth.estimateGas({
    
    from:"",to:"",value:5000})    计算一笔交易所需要的gas

往期精彩回顾:
区块链知识系列
密码学系列
零知识证明系列
共识系列
公链调研系列
比特币系列
以太坊系列
EOS系列
Filecoin系列
联盟链系列
Fabric系列
智能合约系列
Token系列

猜你喜欢

转载自blog.csdn.net/wcc19840827/article/details/121330543