1

I'm working on a basic application to track ETH transfers, and I'm making use of the web3j Java API to interact with the Ethereum blockchain. My app is working, but I'm having trouble figuring out how to correctly determine the fee.

I'm using the extremely convenient web3j.replayTransactionsObservable. My basic logic is this:

BigInteger gasPrice = HexToBigIntegerUtil.fromString(transaction.getGasPriceRaw());
BigInteger gasUsed = HexToBigIntegerUtil.fromString(transaction.getGasRaw());
BigInteger fee = gasPrice.multiply(gasUsed);

And that seems like it should be correct, but the getGasRaw() method returns the user's specified gas limit, rather than the actual gas used. And I'm afraid I'm not seeing a convenient way to access the actual gas fee.

Any pointers?

1 Answer 1

1

If we assume that a standard transaction costs 21000 gas, then the actual gas used is:

BigInteger actualGasUsed = transaction.getGasPrice().multiply(BigInteger.valueOf(21000));

I have searched through the web3j documentation and I can't find any built in way to get this fee. I would hope to see it as a method called from the transaction just like "getGasPrice()".

I'm uncomfortable assuming that the standard transaction cost will always be 21000 gas, so if you figure out a better way please let me know.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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