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

9.3. 如何計算Gas手續費

下面我們用實例講解怎樣計算以太坊在執行交易時花費的 gas 費用。

		
> miner.start(1)
null
		
		

準備兩個賬號

		
> eth.getBalance(eth.accounts[3])
1000000000000000000
> eth.getBalance(eth.accounts[5])
0
		
		

開始計算 gas 費用

		
> var estimateGas = eth.estimateGas({from:eth.accounts[1], to: eth.accounts[2], value: web3.toWei(1)})
undefined
> console.log(estimateGas)
21000
undefined
> 
> var cost = estimateGas * gasPrice
undefined
> console.log(cost)
378000000000000
undefined
> web3.fromWei(cost)
"0.000378"
		
		

gas 花費 0.000378 ETH