In web3.js, if a revert occurs, it doesn't give a receipt along with it. I want to determine how much gas was actually used after a revert.
In 1.0, I can't even get the tx hash from the event transmitter.
In web3.js, if a revert occurs, it doesn't give a receipt along with it. I want to determine how much gas was actually used after a revert.
In 1.0, I can't even get the tx hash from the event transmitter.
EDIT: The below only works for ganache.
In my testing, the below works. The function storeAndRevert
, as you might imagine, stores the argument in a state variable and then revert
s:
instance.methods.storeAndRevert(42).send({ from: accounts[0], gas: 3000000 })
.on('error', async (err) => {
const receipt = await web3.eth.getTransactionReceipt(err.hashes[0]);
console.log(`Gas used: ${receipt.gasUsed}`);
});
As far as I know, the error
event is the only one you'll be able to listen for, though I think try/catch
will give you access to the same error object.
ganache
version? I was using ganache-core
at version 2.2.1.
– user19510
Oct 15 '18 at 14:21
geth
which gives you the real gas estimation on any transaction, erroneous or not, with gas refunds or without, contact me and I will send you the code – Nulik Sep 19 '18 at 0:46