Skip to content

Instantly share code, notes, and snippets.

@changwu-tw
Created February 5, 2017 16:39
Show Gist options
  • Save changwu-tw/959d150e887e5fb4318327f52fc2d204 to your computer and use it in GitHub Desktop.
Save changwu-tw/959d150e887e5fb4318327f52fc2d204 to your computer and use it in GitHub Desktop.
交易流程與手續費
> var acct1 = web3.eth.accounts[0]
> var acct2 = web3.eth.accounts[1]
> var acct3 = web3.eth.accounts[2]
> var balance = (acct) => { return web3.fromWei(web3.eth.getBalance(acct), "ether").toNumber() }
> web3.eth.sendTransaction({from: acct1, to: acct2, value: web3.toWei(1, "ether"), gasLimit: 21000, gasPrice: 2000000000})
'0xc597fb44d8bc1da0e3bdd8eebc45b642f49301869dc707beb5c381b8401b59bc'
> web3.eth.sendTransaction({from: acct1, to: acct2, value: web3.toWei(1, "ether"), gasLimit: 21000, gasPrice: 2000000000})
'0x94b02ec108f157c24adc213dafabdfc851d18c6064435066ce35d70687247626'
> var txHash = _
undefined
> balance(acct2)
102
> balance(acct1)
97.999916
> web3.eth.sendTransaction({from: acct1, to: acct2, value: web3.toWei(1, "ether"), gasLimit: 21000, gasPrice: 2000000000, nonce: 0})
Error: Error: the tx doesn’t have the correct nonce. account has nonce of: 2 tx has nonce of: 0
> web3.eth.getTransactionCount(acct1)
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment