0

I am using custom error like these:

error BadIndexError();

revert BadIndexError();

Now, if I want to retrieve these errors how would I retrieve it in frontend?

Plus, I am using custom framework for tests for my company. How would I retrieve such errors in my tests as well? Right now I just get revert and no error message.

Any simple way? Does ethersjs support it?

1 Answer 1

0

I have some posts about custom errors in my blog.

for Ethers.js: https://blog.emn178.cc/en/post/ethers-js-parse-custom-error/

for Web3.js: https://blog.emn178.cc/en/post/using-web3-js-to-parse-custom-error/

If you use hardhat for testing, you can check document, usage will looks like

await expect(
 contract.someMethod()
).to.be.revertedWithCustomError(contract, 'BadIndexError');

If you use custom framework for tests, you may use parseCustomError function mentioned in my blog and check its name and args.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.