The transaction usually fails when the gas price, which is being sent along the transaction payload, is low. This transaction then goes to the 'pending' status, which generally means that the network has received your transaction, but it's not being indexed yet by the indexer, and then finally, after waiting for some time, it gets failed.
So, to avoid this, it is recommended to switch to a dedicated private RPC URL such as Infura or Alchemy, and fetch the maxFeePerGas from https://gasstation.polygon.technology/amoy for the Amoy testnet and from https://gasstation.polygon.technology/v2 for the Polygon mainnet.
After fetching, make sure to convert the fetched price from GWEI to WEI. If you are setting a static gas limit, then we suggest you estimate the gas limit. If your transaction still shows pending, then you can overwrite it by resetting your Metamask or by fetching the nonce and resending the transaction with a higher gas price.
Moreover, you can try putting in a retry logic to resend the transaction with a higher gas price after a certain time (eg, Infura ITX supports retry).
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article