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?