Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

第 11 章 geth v1.8.16 命令詳解

目錄

11.1. api 相關參數
11.1.1. rpcapi
11.1.2. rpcaddr
11.2. 啟動 Websocket 連接埠
11.3. 日誌
11.4. 控制台
11.5. 連接控制台
11.5.1. 指定 geth.ipc 檔案位置
11.5.2. IPC 方式連接
11.5.3. TCP 連接控制台
11.5.4. WebSocket 方式
11.6. 賬號管理
11.6.1. 新建賬號
11.6.2. 查看賬號
11.6.3. 從私鑰導入以太坊地址
11.7. 配置自動解鎖賬號
11.8. 運行JS
11.9. 節點管理
11.10. 啟動挖礦
11.10.1. 挖礦綫程數
11.10.2. 指定曠工賬號
11.11. 運行智能合約
11.12. Ropsten測試網絡
11.13. 靜態節點
11.14. JavaScript Console
11.14.1. personal 管理
11.14.1.1. 創建賬號
11.14.1.2. 列出賬號
11.14.1.3. 解鎖賬號
11.14.2. eth 管理
11.14.2.1. 礦工賬號
11.14.2.2. 餘額
11.14.2.2.1. 單位轉換
11.14.2.2.2. 一次檢查所有賬號餘額
11.14.2.3. 解鎖賬號
11.14.2.4. 轉賬
11.14.2.5. 查看掛起的交易
11.14.2.6. 查看當前區塊總數
11.14.2.7. 查看當前Gas價格
11.14.2.8. 評估執行花費的GAS
11.14.2.9. 查看區塊信息
11.14.2.10. 返回交易信息
11.14.2.11. 返回交易收據
11.14.2.12. eth.syncing 同步狀態
11.14.2.13. 查看智能合約編譯器
11.14.3. web3
11.14.3.1. Ether幣的基本單位
11.14.3.2. web3.toWei
11.14.3.3. web3.fromWei
11.14.4. admin 管理
11.14.4.1. 看看 networkid
11.14.4.2. 節點管理
11.14.4.2.1. 顯示節點
11.14.4.2.2. 添加節點
11.14.4.2.3. 查看節點
11.14.4.2.4. networkid
11.14.5. miner 挖礦管理
11.14.5.1. 開始挖礦
11.14.5.2. 停止挖礦
11.14.5.3. 設置預設礦工賬號
11.14.6. txpool 管理
11.14.6.1. txpool.status
11.14.7. net
11.14.7.1. 監聽狀態

https://geth.ethereum.org

版本號

		
neo@MacBook-Pro ~/ethereum/web3 % geth version
Geth
Version: 1.8.16-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: darwin
GOPATH=
GOROOT=/usr/local/opt/go/libexec		
		
	

幫助信息

		
neo@MacBook-Pro ~/ethereum/web3 % geth --help
NAME:
   geth - the go-ethereum command line interface

   Copyright 2013-2017 The go-ethereum Authors

USAGE:
   geth [options] command [command options] [arguments...]
   
VERSION:
   1.8.16-stable
   
COMMANDS:
   account     Manage accounts
   attach      Start an interactive JavaScript environment (connect to node)
   bug         opens a window to report a bug on the geth repo
   console     Start an interactive JavaScript environment
   copydb      Create a local chain from a target chaindata folder
   dump        Dump a specific block from storage
   dumpconfig  Show configuration values
   export      Export blockchain into file
   import      Import a blockchain file
   init        Bootstrap and initialize a new genesis block
   js          Execute the specified JavaScript files
   license     Display license information
   makecache   Generate ethash verification cache (for testing)
   makedag     Generate ethash mining DAG (for testing)
   monitor     Monitor and visualize node metrics
   removedb    Remove blockchain and state databases
   version     Print version numbers
   wallet      Manage Ethereum presale wallets
   help, h     Shows a list of commands or help for one command
   
ETHEREUM OPTIONS:
  --config value                           TOML configuration file
  --datadir "/Users/neo/Library/Ethereum"  Data directory for the databases and keystore
  --keystore                               Directory for the keystore (default = inside the datadir)
  --nousb                                  Disables monitoring for and managing USB hardware wallets
  --networkid value                        Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: 1)
  --testnet                                Ropsten network: pre-configured proof-of-work test network
  --rinkeby                                Rinkeby network: pre-configured proof-of-authority test network
  --syncmode "fast"                        Blockchain sync mode ("fast", "full", or "light")
  --gcmode value                           Blockchain garbage collection mode ("full", "archive") (default: "full")
  --ethstats value                         Reporting URL of a ethstats service (nodename:secret@host:port)
  --identity value                         Custom node name
  --lightserv value                        Maximum percentage of time allowed for serving LES requests (0-90) (default: 0)
  --lightpeers value                       Maximum number of LES client peers (default: 100)
  --lightkdf                               Reduce key-derivation RAM & CPU usage at some expense of KDF strength
  
DEVELOPER CHAIN OPTIONS:
  --dev               Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled
  --dev.period value  Block period to use in developer mode (0 = mine only if transaction pending) (default: 0)
  
ETHASH OPTIONS:
  --ethash.cachedir                     Directory to store the ethash verification caches (default = inside the datadir)
  --ethash.cachesinmem value            Number of recent ethash caches to keep in memory (16MB each) (default: 2)
  --ethash.cachesondisk value           Number of recent ethash caches to keep on disk (16MB each) (default: 3)
  --ethash.dagdir "/Users/neo/.ethash"  Directory to store the ethash mining DAGs (default = inside home folder)
  --ethash.dagsinmem value              Number of recent ethash mining DAGs to keep in memory (1+GB each) (default: 1)
  --ethash.dagsondisk value             Number of recent ethash mining DAGs to keep on disk (1+GB each) (default: 2)
  
TRANSACTION POOL OPTIONS:
  --txpool.nolocals            Disables price exemptions for locally submitted transactions
  --txpool.journal value       Disk journal for local transaction to survive node restarts (default: "transactions.rlp")
  --txpool.rejournal value     Time interval to regenerate the local transaction journal (default: 1h0m0s)
  --txpool.pricelimit value    Minimum gas price limit to enforce for acceptance into the pool (default: 1)
  --txpool.pricebump value     Price bump percentage to replace an already existing transaction (default: 10)
  --txpool.accountslots value  Minimum number of executable transaction slots guaranteed per account (default: 16)
  --txpool.globalslots value   Maximum number of executable transaction slots for all accounts (default: 4096)
  --txpool.accountqueue value  Maximum number of non-executable transaction slots permitted per account (default: 64)
  --txpool.globalqueue value   Maximum number of non-executable transaction slots for all accounts (default: 1024)
  --txpool.lifetime value      Maximum amount of time non-executable transaction are queued (default: 3h0m0s)
  
PERFORMANCE TUNING OPTIONS:
  --cache value            Megabytes of memory allocated to internal caching (default: 1024)
  --cache.database value   Percentage of cache memory allowance to use for database io (default: 75)
  --cache.gc value         Percentage of cache memory allowance to use for trie pruning (default: 25)
  --trie-cache-gens value  Number of trie node generations to keep in memory (default: 120)
  
ACCOUNT OPTIONS:
  --unlock value    Comma separated list of accounts to unlock
  --password value  Password file to use for non-interactive password input
  
API AND CONSOLE OPTIONS:
  --rpc                  Enable the HTTP-RPC server
  --rpcaddr value        HTTP-RPC server listening interface (default: "localhost")
  --rpcport value        HTTP-RPC server listening port (default: 8545)
  --rpcapi value         API's offered over the HTTP-RPC interface
  --ws                   Enable the WS-RPC server
  --wsaddr value         WS-RPC server listening interface (default: "localhost")
  --wsport value         WS-RPC server listening port (default: 8546)
  --wsapi value          API's offered over the WS-RPC interface
  --wsorigins value      Origins from which to accept websockets requests
  --ipcdisable           Disable the IPC-RPC server
  --ipcpath              Filename for IPC socket/pipe within the datadir (explicit paths escape it)
  --rpccorsdomain value  Comma separated list of domains from which to accept cross origin requests (browser enforced)
  --rpcvhosts value      Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
  --jspath loadScript    JavaScript root path for loadScript (default: ".")
  --exec value           Execute JavaScript statement
  --preload value        Comma separated list of JavaScript files to preload into the console
  
NETWORKING OPTIONS:
  --bootnodes value     Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers)
  --bootnodesv4 value   Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes)
  --bootnodesv5 value   Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes)
  --port value          Network listening port (default: 30303)
  --maxpeers value      Maximum number of network peers (network disabled if set to 0) (default: 25)
  --maxpendpeers value  Maximum number of pending connection attempts (defaults used if set to 0) (default: 0)
  --nat value           NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>) (default: "any")
  --nodiscover          Disables the peer discovery mechanism (manual peer addition)
  --v5disc              Enables the experimental RLPx V5 (Topic Discovery) mechanism
  --netrestrict value   Restricts network communication to the given IP networks (CIDR masks)
  --nodekey value       P2P node key file
  --nodekeyhex value    P2P node key as hex (for testing)
  
MINER OPTIONS:
  --mine                    Enable mining
  --minerthreads value      Number of CPU threads to use for mining (default: 8)
  --etherbase value         Public address for block mining rewards (default = first account created) (default: "0")
  --targetgaslimit value    Target gas limit sets the artificial target gas floor for the blocks to mine (default: 4712388)
  --gasprice "18000000000"  Minimal gas price to accept for mining a transactions
  --extradata value         Block extra data set by the miner (default = client version)
  
GAS PRICE ORACLE OPTIONS:
  --gpoblocks value      Number of recent blocks to check for gas prices (default: 20)
  --gpopercentile value  Suggested gas price is the given percentile of a set of recent transaction gas prices (default: 60)
  
VIRTUAL MACHINE OPTIONS:
  --vmdebug  Record information useful for VM and contract debugging
  
LOGGING AND DEBUGGING OPTIONS:
  --metrics                 Enable metrics collection and reporting
  --fakepow                 Disables proof-of-work verification
  --nocompaction            Disables db compaction after import
  --verbosity value         Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)
  --vmodule value           Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=5,p2p=4)
  --backtrace value         Request a stack trace at a specific logging statement (e.g. "block.go:271")
  --debug                   Prepends log messages with call-site location (file and line number)
  --pprof                   Enable the pprof HTTP server
  --pprofaddr value         pprof HTTP server listening interface (default: "127.0.0.1")
  --pprofport value         pprof HTTP server listening port (default: 6060)
  --memprofilerate value    Turn on memory profiling with the given rate (default: 524288)
  --blockprofilerate value  Turn on block profiling with the given rate (default: 0)
  --cpuprofile value        Write CPU profile to the given file
  --trace value             Write execution trace to the given file
  
WHISPER (EXPERIMENTAL) OPTIONS:
  --shh                       Enable Whisper
  --shh.maxmessagesize value  Max message size accepted (default: 1048576)
  --shh.pow value             Minimum POW accepted (default: 0.2)
  
DEPRECATED OPTIONS:
  --fast   Enable fast syncing through state downloads
  --light  Enable light client mode
  
MISC OPTIONS:
  --help, -h  show help
  

COPYRIGHT:
   Copyright 2013-2017 The go-ethereum Authors		
		
	

中文翻譯



命令:
account    管理賬戶
attach     啟動互動式JavaScript環境(連接到節點)
bug        上報bug Issues
console    啟動互動式JavaScript環境
copydb     從檔案夾創建本地鏈
dump       Dump(分析)一個特定的塊存儲
dumpconfig 顯示配置值
export     導出區塊鏈到檔案
import     導入一個區塊鏈檔案
init       啟動並初始化一個新的創世紀塊
js         執行指定的JavaScript檔案(多個)
license    顯示許可信息
makecache  生成ethash驗證緩存(用於測試)
makedag    生成ethash 挖礦DAG(用於測試)
monitor    監控和可視化節點指標
removedb   刪除區塊鏈和狀態資料庫
version    打印版本號
wallet     管理Ethereum預售錢包
help,h     顯示一個命令或幫助一個命令列表
ETHEREUM選項:
--config value          TOML 配置檔案
--datadir “xxx”         資料庫和keystore密鑰的數據目錄
--keystore              keystore存放目錄(預設在datadir內)
--nousb                 禁用監控和管理USB硬件錢包
--networkid value       網絡標識符(整型, 1=Frontier, 2=Morden (棄用), 3=Ropsten, 4=Rinkeby) (預設: 1)
--testnet               Ropsten網絡:預先配置的POW(proof-of-work)測試網絡
--rinkeby               Rinkeby網絡: 預先配置的POA(proof-of-authority)測試網絡
--syncmode "fast"       同步模式 ("fast", "full", or "light")
--ethstats value        上報ethstats service  URL (nodename:secret@host:port)
--identity value        自定義節點名
--lightserv value       允許LES請求時間最大百分比(0 – 90)(預設值:0) 
--lightpeers value      最大LES client peers數量(預設值:20)
--lightkdf              在KDF強度消費時降低key-derivation RAM&CPU使用
開發者(模式)選項:
--dev               使用POA共識網絡,預設預分配一個開發者賬戶並且會自動開啟挖礦。
--dev.period value  開發者模式下挖礦周期 (0 = 僅在交易時) (預設: 0)
ETHASH 選項:
--ethash.cachedir                        ethash驗證緩存目錄(預設 = datadir目錄內)
--ethash.cachesinmem value               在內存保存的最近的ethash緩存個數  (每個緩存16MB ) (預設: 2)
--ethash.cachesondisk value              在磁碟保存的最近的ethash緩存個數 (每個緩存16MB) (預設: 3)
--ethash.dagdir ""                       存ethash DAGs目錄 (預設 = 用戶hom目錄)
--ethash.dagsinmem value                 在內存保存的最近的ethash DAGs 個數 (每個1GB以上) (預設: 1)
--ethash.dagsondisk value                在磁碟保存的最近的ethash DAGs 個數 (每個1GB以上) (預設: 2)
交易池選項:
--txpool.nolocals            為本地提交交易禁用價格豁免
--txpool.journal value       本地交易的磁碟日誌:用於節點重啟 (預設: "transactions.rlp")
--txpool.rejournal value     重新生成本地交易日誌的時間間隔 (預設: 1小時)
--txpool.pricelimit value    加入交易池的最小的gas價格限制(預設: 1)
--txpool.pricebump value     價格波動百分比(相對之前已有交易) (預設: 10)
--txpool.accountslots value  每個帳戶保證可執行的最少交易槽數量  (預設: 16)
--txpool.globalslots value   所有帳戶可執行的最大交易槽數量 (預設: 4096)
--txpool.accountqueue value  每個帳戶允許的最多非可執行交易槽數量 (預設: 64)
--txpool.globalqueue value   所有帳戶非可執行交易最大槽數量  (預設: 1024)
--txpool.lifetime value      非可執行交易最大入隊時間(預設: 3小時)
性能調優的選項:
--cache value                分配給內部緩存的內存MB數量,緩存值(最低16 mb /資料庫強制要求)(預設:128)
--trie-cache-gens value      保持在內存中產生的trie node數量(預設:120)
帳戶選項:
--unlock value              需解鎖賬戶用逗號分隔
--password value            用於非互動式密碼輸入的密碼檔案
API和控制台選項:
--rpc                       啟用HTTP-RPC伺服器
--rpcaddr value             HTTP-RPC伺服器介面地址(預設值:“localhost”)
--rpcport value             HTTP-RPC伺服器監聽連接埠(預設值:8545)
--rpcapi value              基于HTTP-RPC介面提供的API
--ws                        啟用WS-RPC伺服器
--wsaddr value              WS-RPC伺服器監聽介面地址(預設值:“localhost”)
--wsport value              WS-RPC伺服器監聽連接埠(預設值:8546)
--wsapi  value              基于WS-RPC的介面提供的API
--wsorigins value           websockets請求允許的源
--ipcdisable                禁用IPC-RPC伺服器
--ipcpath                   包含在datadir裡的IPC socket/pipe檔案名(轉義過的顯式路徑)
--rpccorsdomain value       允許跨域請求的域名列表(逗號分隔)(瀏覽器強制)
--jspath loadScript         JavaScript加載腳本的根路徑(預設值:“.”)
--exec value                執行JavaScript語句(只能結合console/attach使用)
--preload value             預加載到控制台的JavaScript檔案列表(逗號分隔)
網絡選項:
--bootnodes value    用於P2P發現引導的enode urls(逗號分隔)(對於light servers用v4+v5代替)
--bootnodesv4 value  用於P2P v4發現引導的enode urls(逗號分隔) (light server, 全節點)
--bootnodesv5 value  用於P2P v5發現引導的enode urls(逗號分隔) (light server, 輕節點)
--port value         網卡監聽連接埠(預設值:30303)
--maxpeers value     最大的網絡節點數量(如果設置為0,網絡將被禁用)(預設值:25)
--maxpendpeers value    最大嘗試連接的數量(如果設置為0,則將使用預設值)(預設值:0)
--nat value             NAT連接埠映射機制 (any|none|upnp|pmp|extip:<IP>) (預設: “any”)
--nodiscover            禁用節點發現機制(手動添加節點)
--v5disc                啟用實驗性的RLPx V5(Topic發現)機制
--nodekey value         P2P節點密鑰檔案
--nodekeyhex value      十六進制的P2P節點密鑰(用於測試)
礦工選項:
--mine                  打開挖礦
--minerthreads value    挖礦使用的CPU綫程數量(預設值:8)
--etherbase value       挖礦獎勵地址(預設=第一個創建的帳戶)(預設值:“0”)
--targetgaslimit value  目標gas限制:設置最低gas限制(低於這個不會被挖?) (預設值:“4712388”)
--gasprice value        挖礦接受交易的最低gas價格
--extradata value       礦工設置的額外塊數據(預設=client version)
GAS價格選項:
--gpoblocks value      用於檢查gas價格的最近塊的個數  (預設: 10)
--gpopercentile value  建議gas價參考最近交易的gas價的百分位數,(預設: 50)
虛擬機的選項:
--vmdebug        記錄VM及合約調試信息
日誌和調試選項:
--metrics            啟用metrics收集和報告
--fakepow            禁用proof-of-work驗證
--verbosity value    日誌詳細度:0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)
--vmodule value      每個模組詳細度:以 <pattern>=<level>的逗號分隔列表 (比如 eth/*=6,p2p=5)
--backtrace value    請求特定日誌記錄堆棧跟蹤 (比如 “block.go:271”)
--debug                     突出顯示調用位置日誌(檔案名及行號)
--pprof                     啟用pprof HTTP伺服器
--pprofaddr value           pprof HTTP伺服器監聽介面(預設值:127.0.0.1)
--pprofport value           pprof HTTP伺服器監聽連接埠(預設值:6060)
--memprofilerate value      按指定頻率打開memory profiling    (預設:524288)
--blockprofilerate value    按指定頻率打開block profiling    (預設值:0)
--cpuprofile value          將CPU profile寫入指定檔案
--trace value               將execution trace寫入指定檔案
WHISPER實驗選項:
--shh                        啟用Whisper
--shh.maxmessagesize value   可接受的最大的消息大小 (預設值: 1048576)
--shh.pow value              可接受的最小的POW (預設值: 0.2)
棄用選項:
--fast     開啟快速同步
--light    啟用輕客戶端模式
其他選項:
–help, -h    顯示幫助

11.1. api 相關參數

rpcapi 啟動後允許連接到系統的API協議

			
geth --networkid 100000 --rpc --rpcapi "db,eth,net,web3" --rpccorsdomain "*" --datadir "/app/chain" --port "30303" console	
			
		

系統預設監聽 127.0.0.1 如果希望外部訪問本機,需要通過--rpcaddr指定監聽地址。

			
geth --networkid 123456 --rpc --rpcaddr="0.0.0.0" --rpccorsdomain "*" --nodiscover		
			
		

11.1.1. rpcapi

--rpcapi 可以控制訪問內容

				
$ geth --rpc --rpcapi personal,db,eth,net,web3 --rinkeby	
				
			

11.1.2. rpcaddr

預設是 127.0.0.1

HTTP endpoint closed: http://127.0.0.1:8545

通過 --rpcaddr="0.0.0.0" 指定監聽地址

HTTP endpoint opened: http://0.0.0.0:8545

				
neo@netkiller ~/ethereum % geth --networkid 123456 --rpc --rpcaddr="0.0.0.0" --rpccorsdomain "*" --nodiscover console  
INFO [01-20|01:41:33] Starting peer-to-peer node               instance=Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
INFO [01-20|01:41:33] Allocated cache and file handles         database=/home/neo/.ethereum/geth/chaindata cache=128 handles=1024
INFO [01-20|01:41:34] Initialised chain configuration          config="{ChainID: 15 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Engine: unknown}"
INFO [01-20|01:41:34] Disk storage enabled for ethash caches   dir=/home/neo/.ethereum/geth/ethash count=3
INFO [01-20|01:41:34] Disk storage enabled for ethash DAGs     dir=/home/neo/.ethash               count=2
INFO [01-20|01:41:34] Initialising Ethereum protocol           versions="[63 62]" network=123456
INFO [01-20|01:41:34] Loaded most recent local header          number=531 hash=1a2707…3a27bc td=79083846
INFO [01-20|01:41:34] Loaded most recent local full block      number=531 hash=1a2707…3a27bc td=79083846
INFO [01-20|01:41:34] Loaded most recent local fast block      number=531 hash=1a2707…3a27bc td=79083846
INFO [01-20|01:41:34] Loaded local transaction journal         transactions=0 dropped=0
INFO [01-20|01:41:34] Regenerated local transaction journal    transactions=0 accounts=0
WARN [01-20|01:41:34] Blockchain not empty, fast sync disabled 
INFO [01-20|01:41:34] Starting P2P networking 
INFO [01-20|01:41:34] RLPx listener up                         self="enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@[::]:30303?discport=0"
INFO [01-20|01:41:34] IPC endpoint opened: /home/neo/.ethereum/geth.ipc 
INFO [01-20|01:41:34] HTTP endpoint opened: http://0.0.0.0:8545 
Welcome to the Geth JavaScript console!

instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
coinbase: 0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6
at block: 531 (Tue, 14 Nov 2017 17:36:05 HST)
 datadir: /home/neo/.ethereum
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> INFO [01-20|01:41:40] Mapped network port                      proto=tcp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"