Handling errors

Sometimes, things go wrong. For Avocado, this can happen in one of two ways:

  1. the standard way of a revert & failed transaction
  2. transaction is executed but actual execution of the arbitrary actions on the smart wallet failed for some reason

For 1., all errors for each contract are covered in the Contract docs section. For 2., the transaction will emit the events CastFailed on the smart wallet and ExecuteFailed on the AvoForwarder.

Note: It helps to avert errors by first using the verify() method on the smart wallet to make sure the params and signature(s) are valid. Broadcasting does this automatically, no additional logic needed!

To check whether a transaction was successful or not, you can use the Avocado RPC method api_getTransactionByHash:

// execute and get tx hash as explained in Getting started -> Execute

const txDetails = await avocadoProvider.send("api_getTransactionByHash", [txHash]);

// check status
// txDetails.status is of type 'pending' | 'success' | 'failed' | 'confirming'
// in case of 'failed', use the error message: txDetails.revertReason
if (txDetails.status === "failed") {
  // handle errors

The error (revertReason) will be a string in the format <action_index>_<error>, i.e. the revert reason will be prefixed with the index of the action that failed. E.g. if action 1 fails, then the error will be 1_<error>.

Note: No actions are executed if one action fails.

In some cases, actions might also be nested. For example for a flashloan (Avocado smart wallets support the Instadapp Flashloan Aggregator), if the flashloan callback fails, it will be prefixed with two numbers. E.g. if action 1 is the flashloan, and action 2 of flashloan actions fails, the error will be 1_2_<error>.

If the error starts with AVO__ the error happened in the Avocado smart wallet itself and it might be useful to look at the source code to find out more about the specific error.