0

Context

I have a perfectly working dapp I'm trying to adapt to a Safe App. To test the dapp, I have to use a test network (Avalanche Fuji Testnet here), which is not supported by the current Safe web app. I therefore developed my own local Safe infrastructure for this purpose. I did everything the documentation told me to do. The dapp works well in the Safe iframe, except on the following points:

Issues

  • Code 901: A method in my contracts calling for transaction signature generates a code 901 error (transaction reverted), only when called via the Safe App with the Safe App acting as a Web3 provider. The method otherwise works perfectly on all occasions when called via the Safe App with Metamask as a web3 provider, or outside the Safe App. The error details indicate a gas estimation issue (see code below). When the error appears, it is then impossible to process the transaction (even after refresh). The error is generated even before the Safe transaction modal appears. On the other hand, when I pass the method directly to the contract (via Remix or Open Zeppelin Defender, for example), everything works, and the Safe App no longer generates a 901 error. Note that this method is usually called at the end of a series of transactions of different types.
    The error appears systematically after the occurrence of a specific type of transaction (NFT mint). I suspect that the gas fee estimation is not done correctly with the problematic call, and that the provider must therefore use the previous gas fee estimation, i.e. that of the mint transaction, which must not be adapted to the next transaction, which fails then.
Error: cannot estimate gas; transaction may fail or may require manual gas limit 
[ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] 
(reason="Error: execution reverted", method="estimateGas", transaction={"from":"MY_ADDRESS","to":"CONTRACT","data":"0x171165d[...REMAINING _DATA...]","accessList":null}, error={}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.7.2)

EDIT:

I can confirm the above assumption. The Safe looks to take the previous transaction as a reference to estimate the gas limit of the next one. If the previous transaction was based on a gas calculation lower than the gas required for the current transaction, then the current transaction fails. If you setup a manual gas limit (large enough) it works, but using a function to estimate gas programmably does not work.

Stack

  • React single page app (CRA)
  • Soidity Contracts (Avalanche EVM)
  • EthersJS to deal with everything web3 (provider, contract calls)
  • safe-apps-react-sdk & safe-apps-provider (to be used with Ethers) for the Safe app integration.

Questions

  • Is code 901 linked to the gas estimate? EDIT: answer looks to be YES.
  • and if so, how can this be managed with the Safe library?
1
  • Please include full error message with the transaction details
    – mikheevm
    Aug 14, 2023 at 17:07

0

Your Answer

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

Browse other questions tagged or ask your own question.