Autotask task failed due to Insufficient funds

This is my autotask code.

const { DefenderRelayProvider } = require('defender-relay-client/lib/web3');
const Web3 = require('web3');
const ABI =[contract abi]
exports.handler = async function(event) {
  const provider = new DefenderRelayProvider(event, { speed: 'fast' });
  const web3 = new Web3(provider);
  // Use web3 instance for querying or sending txs, for example...
  const [from] = await web3.eth.getAccounts();
  const contract = new web3.eth.Contract(ABI, "contract address", { from });
  await contract.methods.SomeFunction().send(); // very high computation function
}

I made it work so that the SomeFunction will run after 24 hours. Most of the time, the required gas is between 0.5 matic to 0.9 matic. However, since my relayer only has a balance of 5 matic, it gave me an error of insufficient balance.

Error while attempting request: Insufficient funds: 6.1548387823591164 MATIC required but 5.915268962088331684 MATIC are available for usage on the account.

6.15 matic gas is huge, and it's not normal that I'm getting a balance error, given that the average gas for this function is between 0.5 matic to 0.9 matic. When I tried running the function manually, the first attempt gave the same error, but it was successful on the second try.

Can someone please help me with this?

Hi @offfocs.1 -

That error indicates the total required to process all of a particular Relayer's pending transactions as well as the transaction that was just submitted. The calculation is gas price * gas limit for each pending transaction. In all likelihood, when you received this error there were a number of pending transactions such that the overall balance could not cover another transaction.

If the gas limit you are providing is higher than it needs to be, reducing that would be one way to manage this pending transaction cost calculation. Otherwise, I would recommend increasing this Relayer's balance.