0

I'm checking the balance of an account after a payable transaction in a Truffle test. Below is my code:

// amount is the value supplied to the txn
assert.equal(Number(String(currentBalance)),
             Number(String(previousBalance)) + amount - (gasUsed * 100000000000),
            'Account balance for ' + String(acct) + ' incorrect after txn.');
// previous account bal: 99965457999999999000
// current account bal: 99954881999999998000
// gasUsed: 105760
// amount: 1000

As you can see, I have to multiply the gasUsed value by 10^11 or my test will fail... I don't really understand why it's 10^11? GWEI (10^9) makes a lot more sense. At least a multiple of 3 right? This isn't in the web3 documentation at all.

EDIT: to clarify I'm trying to figure out what gasUsed is and if web3 or Truffle are overwriting the default gas price. The gas price according to my Ganache interface is 20000000000, which doesn't work with my calculations. That's why I was lead to believe gasUsed is the total txn fee in wei.

  • Can you give us the actual value returned? – Florian Castelain Jan 29 '18 at 3:27
  • I just added the values of all variables! – nickjm Jan 29 '18 at 4:00
0

Gas is not ether. Gas is used to estimate the work made by the EVM. It has nothing to do with weis/ether etc...

If you want to know how much ether is worth this gas, multiply it by the gasPrice value.

  • And from your calculation, it sounds like your gas price is probably 100 gwei (10^11 wei). – smarx Jan 29 '18 at 4:03
  • That's what I initially thought too, but I'm using Ganache and according to the Ganache interface, my gas price is 20000000000 by default. Does web3 overwrite this with it's own default – nickjm Jan 29 '18 at 4:08
  • If gasPrice is not provided in the transaction object, geth will get the gas price from the EVM itself when processing the transaction. – Florian Castelain Jan 29 '18 at 4:09
  • Ok maybe this should be a question about Ganache and it's misleading interface then – nickjm Jan 29 '18 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.