知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
目錄
開始學習以太坊時閲讀大量文章常常會提到 Mist 一頭霧水,後來才知道 Mist 就是 Ethereum Wallet。 Ethereum Wallet 是軟件名字, Mist 是項目名字。
Ethereum Wallet 可以在以太坊首頁下載,如果你需要安裝歷史版本可以訪問 https://github.com/ethereum/mist/releases
參數:
neo@MacBook-Pro ~ % "/Applications/Ethereum Wallet.app/Contents/MacOS/Ethereum Wallet" --help Usage: /Applications/Ethereum Wallet.app/Contents/MacOS/Ethereum Wallet --help [Mist options] [Node options] Mist options: --mode, -m App UI mode: wallet, mist.[string] [default: "wallet"] --node Node to use: geth, eth [string] [default: null] --network Network to connect to: main, test [string] [default: null] --rpc Path to node IPC socket file OR HTTP RPC hostport (if IPC socket file then --node-ipcpath will be set with this value). [string] --swarmurl URL serving the Swarm HTTP API. If null, Mist will open a local node. [string] [default: "http://localhost:8500"] --gethpath Path to Geth executable to use instead of default. [string] --ethpath Path to Eth executable to use instead of default. [string] --ignore-gpu-blacklist Ignores GPU blacklist (needed for some Linux installations). [boolean] --reset-tabs Reset Mist tabs to their default settings. [boolean] --logfile Logs will be written to this file in addition to the console. [string] --loglevel Minimum logging threshold: info, debug, error, trace (shows all logs, including possible passwords over IPC!). [string] [default: "info"] --syncmode Geth synchronization mode: [fast|light|full] [string] --version, -v Display Mist version. [boolean] --skiptimesynccheck Disable checks for the presence of automatic time sync on your OS. [boolean] Node options: - To pass options to the underlying node (e.g. Geth) use the --node- prefix, e.g. --node-datadir Options: -h, --help Show help [boolean]
Ethereum Wallet 工作原理非常簡單,啟動 Ethereum Wallet 是,Ethereum Wallet 會首先啟動 geth,然後在啟動 Ethereum Wallet 應用程序。
geth 負責與以太坊網絡連接,包括主網,Ropsten和Rinkeby兩個測試網,Solo 本地開發模式。geth
例如主網的啟動目錄是 /Users/neo/Library/Ethereum/geth.ipc 參數是:
/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth --syncmode light --cache 1024
/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth --testnet --syncmode light --cache 1024 --ipcpath /Users/neo/Library/Ethereum/geth.ipc
首先啟動 geth
錢包預設是連接到下面地址。
IPC endpoint opened: /Users/neo/Library/Ethereum/geth.ipc
連接到其他ipc地址
"/Applications/Ethereum Wallet.app/Contents/MacOS/Ethereum Wallet" --rpc /Users/other/Library/Ethereum/geth.ipc
在 Ethereum Wallet 啟動期間,隨時可以進入Javascript控制台。
neo@MacBook-Pro ~/Library/Ethereum/geth % geth attach Welcome to the Geth JavaScript console! instance: Geth/v1.8.1-stable-1e67410e/darwin-amd64/go1.9.4 modules: admin:1.0 debug:1.0 eth:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0 > eth.accounts ["0xb94054c174995ae2a9e7fcf6c7924635fba8ecf7", "0xf56b81a2bcb964d2806071e9be4289a5559bb0fa", "0x997e5ca600e19447d0b82afbf9c7f00de2b39b16"] >
/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth --syncmode light --cache 1024
/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth --testnet --syncmode light --cache 1024 --ipcpath /Users/neo/Library/Ethereum/geth.ipc
輸入賬號然後點擊 “Send me 1 test ether” 按鈕
當現實 “Your request was accepted” 時,表示你的請求已經接受,接下來耐心等待。
連接測試網絡,啟動 "Ethereum Wallet",主菜單-Develop-Network,選擇 "Rinkeby - Test network"。
如果這個菜單是灰色的,可以你在本地運行過 geth,解決方法如下:
mkdir ~/ethereum/rinkeby geth --datadir ~/ethereum/rinkeby --rinkeby --rpc console
在另一個終端窗口執行
neo@MacBook-Pro ~/ethereum/rinkeby % "/Applications/Ethereum Wallet.app/Contents/MacOS/Ethereum Wallet" ~/ethereum/rinkeby/geth.ipc
或者使用TCP方式連接
"/Applications/Ethereum Wallet.app/Contents/MacOS/Ethereum Wallet" --rpc http://localhost:8545
如果你沒有安裝 geth,可以使用下面的方法
neo@MacBook-Pro ~/ethereum/truffle % "/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth" --rinkeby --syncmode light --cache 1024 --ipcpath /Users/neo/Library/Ethereum/geth.ipc INFO [02-22|11:43:23] Maximum peer count ETH=0 LES=100 total=25 INFO [02-22|11:43:23] Starting peer-to-peer node instance=Geth/v1.8.1-stable-1e67410e/darwin-amd64/go1.9.4 INFO [02-22|11:43:23] Allocated cache and file handles database=/Users/neo/Library/Ethereum/rinkeby/geth/lightchaindata cache=768 handles=128 INFO [02-22|11:43:27] Persisted trie from memory database nodes=355 size=65.27kB time=399.41µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [02-22|11:43:27] Initialised chain configuration config="{ChainID: 4 Homestead: 1 DAO: <nil> DAOSupport: true EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 1035301 Engine: clique}" INFO [02-22|11:43:27] Loaded most recent local header number=1813389 hash=d58d6b…a489d9 td=3366103 INFO [02-22|11:43:27] Starting P2P networking INFO [02-22|11:43:29] UDP listener up net=enode://e84fbdb5d1b75d18fe45fdd13fdad9d5a8ff6d54b82cc8383525870054b91108010ccf8776ac8a50146c9abf9d43c0117af2bbe0cc2668874d269c3817dec47e@[::]:30303 WARN [02-22|11:43:29] Light client mode is an experimental feature INFO [02-22|11:43:29] RLPx listener up self="enode://e84fbdb5d1b75d18fe45fdd13fdad9d5a8ff6d54b82cc8383525870054b91108010ccf8776ac8a50146c9abf9d43c0117af2bbe0cc2668874d269c3817dec47e@[::]:30303?discport=0" INFO [02-22|11:43:29] IPC endpoint opened url=/Users/neo/Library/Ethereum/geth.ipc INFO [02-22|11:43:30] Mapped network port proto=udp extport=30303 intport=30303 interface="UPNP IGDv1-IP1" INFO [02-22|11:43:31] Mapped network port proto=tcp extport=30303 intport=30303 interface="UPNP IGDv1-IP1" INFO [02-22|11:43:32] Block synchronisation started INFO [02-22|11:43:33] Imported new block headers count=13 elapsed=245.507ms number=1813402 hash=08317c…fd1806 ignored=0 INFO [02-22|11:43:48] Imported new block headers count=1 elapsed=898.705µs number=1813403 hash=8a7c1b…5e1652 ignored=0 INFO [02-22|11:44:03] Imported new block headers count=1 elapsed=892.924µs number=1813404 hash=511a30…561d32 ignored=0
然後正常啟動錢包程序 Launchpad - Ethereum Wallet
啟動過程比較緩慢,啟動後會同步區塊信息
彈出第一個界面,讓你選擇網絡,這裡選擇 Rinkeby 測試網絡
輸入密碼,要求八位字母和數字組合
提示你備份錢包
生成賬號 0x36ccB50B007D3D409E69841905DEf1D77D114Ddc
這時你會看到右下角的數字不斷地變化,表示正在同步區塊信息。同步過程比較漫長,請耐心等待。
想獲取Rinkeby測試網絡中的以太幣,需要去申請,地址:
https://faucet.rinkeby.io輸入你的錢包地址,並點擊“Give me Ether”,有三種選項,前面是獲得的以太幣數量,後面是冷卻時間,在冷卻時間過後才能進行下一次以太幣申請。例如第一項是生成3個以太幣,8小時後才能再次申請。
如果一切順利,你會看到你的錢包地址已經多出了申請數量的以太幣。
注意:如果申請的人數很多,需要排隊等待
下載創世區塊
mkdir ~/.rinkeby cd ~/.rinkeby wget https://www.rinkeby.io/rinkeby.json
初始化區塊
geth --datadir=$HOME/.rinkeby init rinkeby.json
啟動以太坊,這裡採用Light node模式,僅僅下載區塊信息,不會運行交易,速度比較快。
geth --networkid=4 --datadir=$HOME/.rinkeby --syncmode=light --ethstats='yournode:Respect my authoritah!@stats.rinkeby.io' --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303
solo 實際上就是geth 的 --dev 參數
開發模式會創建一個賬號,同時啟動挖礦,ETH多的你用不完。
/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth --dev --minerthreads 1 --ipcpath /Users/neo/Library/Ethereum/geth.ipc
"/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth" --datadir=$HOME/ethereum/private init $HOME/ethereum/genesis.json "/Users/neo/Library/Application Support/Ethereum Wallet/binaries/Geth/unpacked/geth" --networkid=4444 --datadir=$HOME/ethereum/private --ipcpath /Users/neo/Library/Ethereum/geth.ipc
在 Ethereum Wallet 錢包上會顯示所有自己創建或者Watch的合約,有些合約僅僅是測試用的,用過即廢棄,合約列表依然會顯示在那裡,只是變成灰色並且無法選擇
怎樣把無用的合約從列表刪除呢?
1. Ethereum Wallet上打開開發者工具(從窗口選擇開發->切換開發工具->錢包界面,或者輸入快捷鍵Alt+Ctrl+I),顯示出控制台界面 2. 查詢Watch Contract列表 - 在控制台輸入命令: CustomContracts.find().fetch(); 3. 在合約列表中找到需要刪除的合約,並且複製ContractID 4. 刪除合約,在控制台輸入命令:CustomContracts.remove('<ContractID>')