geth訪問節點 Geth 命令詳解

2021-10-13 15:06:47 字數 1679 閱讀 5251

本文是 geth 的一篇學習筆記。

geth控制台啟動和退出

最簡單的啟動方式如下:

geth console

啟動成功之後可以看到輸入提示符 >

退出 geth 控制台也很簡單,只要輸入 exit` 即可.

geth 日誌控制

使用geth console啟動是,會在當前的互動介面下時不時出現日誌。

可以使用以下方式把日誌輸出到檔案。

geth console 2>>geth.log

可以新開乙個命令列終端輸入以下命令檢視日誌動態:

tail -f geth.log

重定向另乙個終端

也可以把日誌重定向到另乙個終端,先在想要看日誌的終端輸入:

tty就可以獲取到終端編號,如:/dev/pts/19

然後另乙個終端使用:

geth console 2>> /dev/pts/19

當然你也可以將日誌匯入到黑洞,即不輸出日誌

geth console 2>> /dev/null

啟動乙個開發模式測試節點

geth --datadir /data/testnet --dev console

連線geth節點

另外乙個啟動geth的方法是連線到乙個geth節點:

geth attach ipc: # geth.ipc 檔案路徑

geth attach # jsonrpc 的位址

geth attach ws:

如連線剛剛開啟的開發模式節點使用:

geth attach ipc:testnet/geth.ipc

啟動本地多節點連線集群

在搭建聯盟鏈測試的時候需要在本地啟動多個節點,組成乙個集群。

先啟動乙個節點:

geth --datadir ./data-init1/ --identity "testnode1" --rpc --rpcapi "db,eth,net,web3" --rpccorsdomain "*" --rpcport 8045 --port 30303 --networkid 88 --nodiscover console

不過需要注意的是,這個時候 –datadir, –identity –rpcport –port 這些引數每個節點要配置不同的引數。

比如啟動第二個節點:

geth --datadir ./data-init2/ --identity "tetnode2" --rpc --rpcapi "db,eth,net,web3" --rpccorsdomain "*" --rpcport 8046 --port 30304 --networkid 88 --nodiscover console

分別檢視節點資訊

> net.peercount

> admin.nodeinfo.enode

"enode://[email protected]:30301?discport=0"

使用admin.addpeer新增節點,建立連線:

> admin.addpeer("enode://....")

true

admin.startrpc

如果在啟動節點的時候忘記開啟 rpc 服務,可以通過 admin.startrpc() 工具來開啟:

> admin.startrpc("127.0.0.1", 8545)

true

centos安裝單節點geth

解壓tar zxvf go ethereum 1.9.6.tar.gz修改名字 mv go ethereum 1.9.6 go ethereum進行編譯 cd go ethereum make all 若編譯出錯 可執行命令 go env w goproxy echo export path pat...

geth 常用命令

geth attach ipc pipe geth.ipc personal.listaccounts 當前節點中是否已經存在賬號 eth.coinbase coinbase的賬戶位址 miner.setetherbase eth.coinbase 執行設定miner位址 miner.start 返...

Ubuntu以太坊(Geth)全節點搭建流程

文章搭建環境為 ubuntu 20.04,但適用於所有 linux 系統 前提條件 golang 1.11以上版本,linux搭建golang開發環境 cd go ethereum make geth vi bashrc export ethpath mnt go ethereum build bi...