Web3 Errors Extract is a TypeScript implementation of the Ethereum JSON RPC API to get/extract EVM-based web3 transaction revert messages or any other errors.
You can install the package using NPM
npm install web3-errors-extract
yarn add web3-errors-extract
- ✍️ If you have questions submit an issue
const { Web3errors } = require("web3-errors-extract");
OR
import { Web3errors } from "web3-errors-extract";
const ABI1 = [{
"type":"function",
"name":"foo",
"inputs": [{"name":"a","type":"uint256"}],
"outputs": [{"name":"b","type":"address"}]
},{
"type":"event",
"name":"Event",
"inputs": [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"bytes32","indexed":false}],
}]
const ABI2 = [{
"type":"function",
"name":"foo",
"inputs": [{"name":"a","type":"uint256"}],
"outputs": [{"name":"b","type":"address"}]
},{
"type":"event",
"name":"Event",
"inputs": [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"bytes32","indexed":false}],
}]
const err = new Web3errors("YOUR RPC URL OR PROVIDER", [ABI1, ABI2] /* OPTIONAL ARRAY OF ABIs */);
/*
* Get an error message for a specific tx hash
*/
err.getErrOfTx("0x1234......fff").then(console.log).catch(console.error);
/*
* Get an error message by providing an exception error object of any blockchain (send or call) tx you received in return
*/
err.getErrorMessage(EXCEPTION ERROR OBJECT).then(console.log).catch(console.error);