A new Web3 version was just released and it comes with a new feature that should make your life easier. With the latest version 1.2.5, you can now see the the revert reason if you use the new handleRevert option.
You can activate it easily by using web3.eth.handleRevert = true
. Now when you use call or send functions, precisely one of the following:
web3.eth.call()web3.eth.sendTransaction()contract.methods.myMethod(…).send(…)contract.methods.myMethod(…).call(…)
you will see a new message like
Error: Your request got reverted with the following reason string: This is the revert reason!\
If you have to use sendSignedTransaction, that is not yet implemented. However, you can work around that by catching a reverted transaction and then calling it.
try {
const result = await sendTxWithSendSignedTransaction()
console.log({ result })
} catch (error) {
TestContract.methods.myMethod(myParam).call({
from,
value,
}).then(result => { throw Error('unlikely to happen') })
.catch(revertReason => console.log({ revertReason }))
}This will hopefully make it a lot easier trying to find out why transactions reverted in a live system. Incorporate this into your error logging system to make the most use of it.
Compatibility note: This workaround describes Web3.js 1.2.5. The Web3.js project was sunset in 2025. An eth_call made later may run against different state, so treat the recovered message as diagnostic evidence rather than a guaranteed reproduction of the original transaction.




Join the conversation
Comments are hosted by Disqus and load only when you choose to enable them.