1. 程式人生 > >(二)區塊鏈開發之以太坊CLI控制檯命令

(二)區塊鏈開發之以太坊CLI控制檯命令

1、賬戶管理

建立新賬戶(密碼:Testteam1&)

➜  geth geth --datadir "./db" account new INFO [10-09|17:20:34.942] Maximum peer count                       ETH=25 LES=0 total=25 Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase: Address: {751b9bad789fe375d498463bc8125892b3c433ad}

列出已存在賬號

➜  geth geth --datadir "./db" account list INFO [10-09|17:23:44.141] Maximum peer count                       ETH=25 LES=0 total=25 Account #0: {2dd6b2362d6351b18bd3af9519b8e5b2e44d0339} keystore:///Users/xxx/Desktop/nasnano/ethereum/geth/db/keystore/UTC--2018-10-09T04-00-29.721332367Z--2dd6b2362d6351b18bd3af9519b8e5b2e44d0339 Account #1: {98d03a20eb02fc526534cabbda6dc2e6b43de214} keystore:///Users/xxx/Desktop/nasnano/ethereum/geth/db/keystore/UTC--2018-10-09T05-12-32.419943606Z--98d03a20eb02fc526534cabbda6dc2e6b43de214 Account #2: {751b9bad789fe375d498463bc8125892b3c433ad} keystore:///Users/xxx/Desktop/nasnano/ethereum/geth/db/keystore/UTC--2018-10-09T09-21-18.110637457Z--751b9bad789fe375d498463bc8125892b3c433ad

修改賬號密碼

➜  geth geth --datadir "./db" account update 2dd6b2362d6351b18bd3af9519b8e5b2e44d0339 INFO [10-09|17:27:18.958] Maximum peer count                       ETH=25 LES=0 total=25 Unlocking account 2dd6b2362d6351b18bd3af9519b8e5b2e44d0339 | Attempt 1/3 Passphrase: INFO [10-09|17:27:27.612] Unlocked account                         address=0x2dd6b2362D6351B18BD3af9519b8E5B2e44d0339 Please give a new password. Do not forget this password. Passphrase: Repeat passphrase:

匯入祕鑰檔案(ecc.key是ECDSA的私鑰)

➜  geth geth --datadir "./db" account update import ecc.key

2、區塊資料管理(需要限制節點執行)

匯出區塊資料(匯出db目錄中的區塊資料到bak檔案)

➜  geth geth --datadir "./db" account update import ecc.key

移除區塊資料(移除db目錄中的區塊資料)

➜  geth geth --datadir "./db" removedb

匯入區塊資料

➜  geth geth --datadir "./db" init gensis.json

➜  geth geth --datadir "./db" import ./bak

跟新區塊資料(更新db目錄中區塊資料,會向其他節點重新同步資料)

➜  geth geth --datadir "./db" upgradedb

從區塊鏈中Dump指定區塊資料

➜  geth geth --datadir "./db" dump 0

geth dump number/blockHash,dump後可以傳入區塊編號或區塊hash值