Polygon Mainnet Autotask error "cannot estimate gas"

I was creating a autotask calling a write function via relayer for Mumbai Polygon Testnet successfully a scheduler ran succesful 24h. Now I thought I just could do the same for the mainnet but ran into some strange errors and confusions which make absolutely no sense to me. Wondering if I had discovered a bug here.

  1. First I ran the autoatask manually I received the error "cannot estimate gas; transaction may fail or may require manual gas" I tried to resolve the issue by adding the required gacPrice and gasLimit (which I got from a manual run via Polygonscan.com) as an option to the contract call function (via ethers),

  2. Now I received "Error while attempting request: Insufficient funds: 0.05 ETH required but 0.0 ETH are available." even tho I had 1 MATIC on the balance wondering why Defender showing 0 ETH. Also I was confused because I thought I had to pay in MATIC and not in ETH the relayer gas fee.

  3. As I was wondering, I saw my only salvation in sending mainnet ETH to my Polygon mainnet relayer. I ran the autotask manually and suddenly received a succesful transaction! Confusingly my sent ETH was not spend from my account only my MATIC. Confirming my old idea that relayer fees would have to be paid in the currency of the network and not in ETH.

  4. As this autotask was scheduled to run in 24h i was sure it would execute now correctly the next day but I again received the error seen and described before under 1) Also I created a copy of the polygon relayer so I can withdraw my ETH from this address again, since it seems "not really" dependend.

that is my autotask code.

  const provider = new DefenderRelayProvider(event);
  var options = { gasPrice: ethers.utils.parseUnits('40', 'gwei'), gasLimit: 2500000 };
  const signer = new DefenderRelaySigner(event, provider, options);
  const contract = new ethers.Contract(ADDRESS, ABI, signer);
  const tx  = await contract.distributeRewards(10,options)

My problem is I get a warning my ETH balance would be 0 even tho I have a relayer on the Polygon mainnet. This seems wrong to me.

Hey @inspiraluna! The Insufficient funds error message about not enough ETH should actually be referring to the native currency of the network you're working on, in this case MATIC as you say. So if you want to start sending txs to the Polygon main network, you'd need to:

  • Create a new Relayer on Matic
  • Send MATIC to its address, such as using a bridge to go from Ethereum to Polygon
  • Connect your Autotask to this new relayer

Thank you for your help. But I have the Relayer on Matic already and it has enough Matic on it already and its connected with my autotask.

You mean it would make sense to create another Relayer on Matic network? Its not clear why this should help. I didn't do anything on Ethereum Mainnet. Also it doesn't show the correct balance (0) - I have 1 MATIC on that Polygon relayer.

Understood. Just keep in mind that a Relayer in Mumbai is different from a Relayer in Matic though, so if you were using a Relayer on the Mumbai network originally and you want to move to Matic, then you will need to create a new one on Matic!

Do you mind sharing the address or ID (you can get it from the URL) of the relayer, so I can take a look into it? Feel free to send it privately to defender-support@openzeppelin.com if you prefer not to disclose it here.

Yes, i created a new relayer for Matic mainnet and didn't use the Mumbai testnet.

That is my relayer on Matic mainnet. It worked as described in my previous post exactly one time only, this was short after I send ETH to my relayer on matic. then it showed again
"Error while attempting request: Insufficient funds: 0.05 ETH required but 0.0 ETH"
https://defender.openzeppelin.com/#/relay/3cacba0f-473c-4a9c-8949-eed4ab24e984/settings
But I have 0.97 MATIC left as a balance correctly shown in the dashboard!

If I execute my autotask call https://defender.openzeppelin.com/#/autotask/d6f739d9-aa7b-45c1-9d46-4b35cb6742c0 above error message.

Remark: the contract call requires a certain address which I had (not at the moment) pointed to the relayer address. Right now it has a different address which I call via an alternative / manual way at the moment. Also the Mumbai Testnet relayer + autotask works seemlessly.

Since we have an upgradable contract, I simplified the contract call and increased the gasLimit one more time and now it works stable as on the testnet. I came to following conclusions:

  1. if the contract call consumes a lot of gas, the fee estimation on Polygon Mainnet for some reason doesn't work "cannot estimate gas"

  2. When adding the gasPrice and gasLimit manually as a contract parameter in the contract call itself we receive a wrong error message about 0 ETH Balance even tho the network has MATIC as currency and greater than 0 on the the relayer address. So this should be investigated by the OpenZeppelin Team in my opinion how this can be possible.