eth-revert-reason
Get the revert reason from a tx hash on Ethereum
Install
npm install eth-revert-reason
Notes
- For now, this works consistently with the Infura and Alchemy providers. Any other providers that you pass in may not work.
- There are rare cases where a revert reason may be 'x' from the context of one block but it will be 'y' from the context of another block. This may cause inconsistencies.
- This package relies on the ethers.js default provider. This provider may be subject to rate limits or inconsistencies. For consistent results, please pass in your own provider.
- Alchemy's provider v2 uses Geth.
Getting started
const getRevertReason = // Failed with revert reason "Failed test"console // 'Failed test'console // 'Failed test' // Failed with no revert reasonconsole // '' // Successful transactionconsole // '' // Call from the context of a previous block with a custom providerlet txHash = '0x6ea1798a2d0d21db18d6e45ca00f230160b05f172f6022aa138a0b605831d740'let network = 'mainnet'let blockNumber = 9892243let provider = // NOTE: getAlchemyProvider is not exposed in this packageconsole // 'BA: Insufficient gas (ETH) for refund'
Future work
The following features will be added over time:
- A better way to determine whether or not a node is full-archive.
- A better way to determine whether or not a node exposes Parity
trace
methods. - Reduce the number of calls made by the provider.
- Use raw RPC calls instead of a library
- Will require unwrapping the provider from the library if provider is still a parameter
- Note: this would still require using the ethers default provider
- Will require unwrapping the provider from the library if provider is still a parameter
Test
npm test