How is Gas Used calculated for simple transactions? (Resolved)

dimfelddimfeld Member Posts: 22
EDIT: Figured it out, see my 2nd comment.

I recently sent this transaction: using this command: eth.sendTransaction({from: eth.accounts[0], to:"0xb4ecaafc5fb10d5d30a931de851f3ff1dad41141", value:web3.toWei(0.1, "ether")})

It took 90000 gas at a price of ~58 Shannon/gas. How was this calculated? I'm aware that gas is used for computation in contracts but not sure where this 90000 comes from, especially when the value I had seen before for a simple transaction was 21000 (though I'm not sure what the basis for that is either). What's the math involved here?

Post edited by dimfeld on


  • dimfelddimfeld Member Posts: 22
    And more confusing, looking at the block itself, it claims only 21,000 gas was expended, yet the transaction still says 90,000. Any ideas?

    > eth.getTransactionFromBlock(61476)
    blockHash: '0xd51ef68dfe0fd90e43e4a275c15e87df75a849669af1d5990ce43677ae6a17bd',
    blockNumber: 61476,
    from: '0xda076e9ee5a5156b3e7f206401899c854fc1d5fd',
    gas: 90000,
    gasPrice: '58039008293',
    hash: '0x68d7f506db88297b94ca0efd7524ab466d328e7e93f6fb6343ff96bbfda859df',
    input: '0x',
    nonce: 0,
    to: '0xb4ecaafc5fb10d5d30a931de851f3ff1dad41141',
    transactionIndex: 0,
    value: '100000000000000000'
    > eth.getBlock(61476)
    difficulty: '1734510313511',
    extraData: '0x476574682f76312e302e312f77696e646f77732f676f312e342e32',
    gasLimit: 3141592,
    gasUsed: 21000,
    hash: '0xd51ef68dfe0fd90e43e4a275c15e87df75a849669af1d5990ce43677ae6a17bd',
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    miner: '0x9746c7e1ef2bd21ff3997fa467593a89cb852bd0',
    nonce: '0x53d4328a8b4ccb1b',
    number: 61476,
    parentHash: '0x2496c1cc04677ed75cadda9b79e1ffbaab9c27dea37cd63f0dedf3444cfd47b3',
    sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
    size: 657,
    stateRoot: '0x26dd0fa10f350230da2f73f94193241f62dbe44b3cba7ff4606a4ecec055b723',
    timestamp: 1439172992,
    totalDifficulty: '67194061783014147',
    transactions: ['0x68d7f506db88297b94ca0efd7524ab466d328e7e93f6fb6343ff96bbfda859df' ],
    transactionsRoot: '0x123fb6b0ee49e45a984eb842e3e47a958140cc003d7a32af9eeee953c00db6cf',
    uncles: [ ]
  • dimfelddimfeld Member Posts: 22
    edited August 2015
    Ok... actually I think I understand now what's happening. Although lists the value 90000 in the transaction as "Gas Used," it's just the gas limit, not how much gas was actually used. Looking at the difference in my account balance before and after the transaction, it is consistent with 21000 gas used at a gas price of ~58 Shannon. So, mystery solved.

    That said, if anyone has a reference for where 21000 comes from, I'd love to read it. I assume it's somehow related to the cost of storing the transaction data in the blockchain.
Sign In or Register to comment.