1

I am trying to make transactions on Polygon Mainnet, but unfortunately when I automatically try to calculate the transaction fees, the transaction gets reverted because I assume that the fees are to low. Here is what I automatically generate:

{
'data':'0xf0f63daddb56b93eae180d01fea3e85f986af747f3903959afd249061e871d35a11417fa0000000000000000000000000000000000000000000000000000000064d017e00000000000000000000000000000000000000000000000000000000000000000'
'gas'      : 169986
 'maxFeePerGas': 191060633150
 'maxPriorityFeePerGas': 30000000000
 'nonce'    : 54
 'to'       : '0x38f1CAd3B8Ee3a93Dd3aE30bb5f0Df900f05771F'
 }

That is why I tried to manually adjust the values to:

{
 'data'     : '0xf0f63dad94a098029154d1664f2565f762099c82ec54ef69af8eb06252147950c0e82cf80000000000000000000000000000000000000000000000000000000064d017e00000000000000000000000000000000000000000000000000000000000000000'
 'gas'      : 169986
 'maxFeePerGas': 169307244988
 'maxPriorityFeePerGas': 30000000000
 'nonce'    : 54
 'to'       : '0x38f1CAd3B8Ee3a93Dd3aE30bb5f0Df900f05771F'
}

However with those new values, sometimes it works, sometimes it doesn't. Can you advise me what should I change in order to be sure that the transaction always succeeds. The wallet which pays the transaction fees has always enough balance.

2 Answers 2

0

You can try raising the amount of gas you are willing to spend. For example, maybe change the 169986 to 500000

4
  • Unfortunately, it didn't help
    – Dakata
    Aug 30 at 19:40
  • @Dakata Sorry to hear that, by chance does it show you how much gas was spent on each call?
    – Rohan Nero
    Aug 30 at 23:28
  • yes, here take a look in the transaction, hope it helps you polygonscan.com/tx/…
    – Dakata
    Aug 31 at 10:45
  • @Dakata could you set the gas to 700,000 and then show me the tx that fails? I want to see if it is still using 100% of the gas provided
    – Rohan Nero
    Aug 31 at 16:34
0

The error means the balance in tx account was not enough (see: https://github.com/search?q=repo%3Amaticnetwork%2Fbor%20ErrInsufficientFunds&type=code).

To optimise the fee per gas setting, you might want to fetch those data through eth_feeHistory https://docs.alchemy.com/reference/eth-feehistory api and calculate (with [1, 50 ,99] percentile => low, normal, fast option).

And for the gasLimit, it should be fine (enough for the contract execution).

2
  • Unfortunately, I tried it but the return values are lower than my transaction fees and even if I increase it manually it won't always work.
    – Dakata
    Aug 30 at 19:40
  • github.com/maticnetwork/bor/blob/… github.com/maticnetwork/bor/blob/… cost = value + gas price * gas And for dynamic transaction, gasPrice would be GasFeeCap (maxFeePerGas), you probably can set this number in transaction. To make sure the transaction was injected into memory pool, you can call eth_call before send transaction.
    – Peter Lai
    Sep 8 at 2:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.