I am using geth server for transaction. After transaction is done i got new block but this block not having any field like transaction fees. So my confused about that is block having any field which gives me transaction fees or i have to calculate it manually. If its calculated manually then what is the right formula to calculate transaction fees and how to convert it into ether.

When i google for transaction fees I found two formulas to calculate transaction fees.

  1. gas * gasPrice = transacrion fees.
  2. gasUsed * gasPrice = transaction fees.

But gas and gasUsed are two different fields which have different values. So I am confused which formula is correct. Thanks in advance.


You didn't mention if you are using web3.eth.getTransaction(hash) or web3.getTransactionReceipt(hash).

Have a look at this: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransactionreceipt

Notice that it can't get you the receipt until the transaction is mined, then it can give you gasUsed.

gasUsed * gasPrice is the cost in Ether. gasPrice is probably something your client already knows since it would have sent it with the transaction. If this is not convenient, you can use web3.getTransaction(hash) to find that detail.

The gasPrice is a property of the transaction that was signed and sent, while the gasUsed is reported when the transaction is mined and run. It's a little confusing because there is also a gas parameter sent with the transaction and reported by getTransaction(). That is the amount of gas provided by the sender to potentially be used. It's not a factor in the final cost of the transaction because unused gas is returned to the sender.

Since sending a transaction, getting a hash and waiting for the transaction to be mined is such a common pattern, this might be helpful: https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6

Hope it helps.

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.