Gnosis Safe Transaction Service API – Resolving Gas Estimation Failures

gnosis-safe

I am currently extending the CSV Airdrop Gnosis Safe App by adding a small diagram displaying an estimation on how much of the network's block gas limit will be used by the resulting transaction.

My first approach was to use pessimistic estimates on how much gas will be consumed by each transfer in the transaction and sum them up + some overhead / buffer.

Now I found this API: https://safe-transaction.xdai.gnosis.io/api/v1/safes/{safe-address}/multisig-transactions/estimations/

When trying to use it I always end up in:

{
  "code": 30,
  "message": "Gas estimation failed",
  "arguments": [
    "Cannot estimate gas with `eth_estimateGas`: {'code': -32016, 'message': 'The execution failed due to an exception.', 'data': 'Reverted'}"
  ]
}

I then tried to find out what the actual safe sdk uses when submitting the TX and realized on Gnosis chain it receives the same error:

Request Data

Request URL:
https://safe-transaction.xdai.gnosis.io/api/v1/safes/0x690738F7fFa5fbD5D90f0047293DecE9a38eA0F9/multisig-transactions/estimations/

{
    "to": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
    "value": "0",
    "data": "0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001a700690738f7ffa5fbd5d90f0047293dece9a38ea0f9000000000000000000000000000000000000000000000005f68e8131ecf80000000000000000000000000000000000000000000000000000000000000000000000c20c9c13e853fc64d054b73ff21d3636b2d97eab00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000690738f7ffa5fbd5d90f0047293dece9a38ea0f90000000000000000000000000000000000000000000000111ec132c103fffb390022570d137e36099700a9c80e5dddd4a0d353f6c20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006442842e0e000000000000000000000000690738f7ffa5fbd5d90f0047293dece9a38ea0f9000000000000000000000000690738f7ffa5fbd5d90f0047293dece9a38ea0f900000000000000000000000000000000000000000000000000000000000013dc00000000000000000000000000000000000000000000000000",
    "operation": 1
}

Response Body

{
  "code": 30,
  "message": "Gas estimation failed",
  "arguments": [
    "Cannot estimate gas with `eth_estimateGas`: {'code': -32016, 'message': 'The execution failed due to an exception.', 'data': 'Reverted'}"
  ]
}

Is this estimation service currently not working properly on gnosis chain?
Is my approach of using the service a good approach? Or could I estimate the gas limit of a multisend-transaction differently?
The created multisend transactions can contain native, erc20, erc721 and erc1155 transfers.

Best Answer

With Safe transaction (similar as with Ethereum transaction) it is easily possible to estimate how much gas is required if the transaction fails.

The Safe service estimation endpoint returns an error, because it cannot get the Safe transaction to execute successfully and therefore cannot provide an estimate. You will see a similar behaviour from eth_estimateGas if you try to estimate a transaction that will always revert.

I took a look at your transaction. You want to perform an Ether transfer, an ERC20 transfer and a ERC721 safeTransferFrom within one multisend. The problem is your choice of ERC20 token (vCOW). This token is not transferable and therefore throws an error. With multisend the whole transaction will revert if one of the inner transactions reverts, therefore it is not possible to successfully execute this transaction.

Related Topic