taquito: Document how to capture failwith errors
Doc how Taquito users can smart contract errors surfaced by the FAILWITH michelson instruction.
catch (ex) {
if (ex instanceof TezosOperationError) {
if(ex.message === "E_TOMANYBLURBS") {
//handle error
}
}
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (6 by maintainers)
Ha, yes, I forgot this issue is for me and by me to document this feature 😆 Thank you @DalyIng
Hi @DalyIng
Yes, Taquito supports this in the latest version. This relies on the Michelson FAILWITH instruction.
If you are using Ligo for example, a contract that has a function such as the following;
And the
failwithgets executed during an operation, you can catch that error in Taquito as follows;I recommend you define error codes when using
failwith, instead of human-readable strings.We have a demo app that implements this here: https://github.com/ecadlabs/proposal-vote/blob/bf738d68361711a081f399928cbec7edb250e17f/src/components/voter-panel.tsx#L99 for your reference.
If this covers your question, please feel free to close this issue. 😃