How to resolve the transaction underprice issue?

Created by Mayank Singhal, Modified on Tue, 29 Apr at 4:13 PM by Mayank Singhal

This can happen due to various reasons, and I'll provide some steps you can take to troubleshoot and potentially resolve the issue.

Polygon gas station has been deployed both on the Polygon mainnet & Amoy testnet. It queries the RPC for eth_feeHistory and fetches the 10th, 25th, and 50th percentiles of priority fees for transactions in each of the last 15 blocks. The average value of the 10th, 25th, and 50th percentiles become the safeLowstandard, and fast fee predictions.

Fetching Gas Price from Polygon Gas Station:

  • Instead of hardcoding the gas price in your transactions, consider using the Polygon Gas Station API to dynamically fetch the current gas price. The Gas Station API provides real-time data, including the recommended fast gas price, which ensures that your transactions are executed efficiently.

  • For mainnet gas station: https://gasstation.polygon.technology/v2

  • For Amoy testnet gas station: https://gasstation.polygon.technology/amoy


Properly Estimating Gas Limit:

  • Instead of setting a fixed gas limit for your transactions, you can use tools like ethers.js or web3.js to estimate the gas limit needed for each specific transaction. This ensures that you allocate the appropriate amount of gas and avoid any out-of-gas errors during execution.

Private RPC Providers like Alchemy and Infura:

  • Private RPC providers like Alchemy and Infura can offer enhanced reliability and performance compared to public nodes. Consider using one of these private providers for a more stable and consistent deployment experience.

  • To achieve these improvements, you can write a simple script using ethers.js or web3.js that interacts with the Polygon Gas Station API to fetch the gas price, estimate the gas limit for your transactions, and then execute the contract deployment using a private RPC provider.

  • Sharing a sample script: https://gist.github.com/grsLammy/a2eb6afeda700626da8d94664936852e

Nonce Management: 

The nonce of a transaction needs to be strictly sequential for each account. Make sure that the nonce you're setting is accurate and sequential. You're using a nonce tracker to manage this, but ensure that it's functioning correctly and not causing nonce gaps or duplicates.

By following these best practices, you can optimize the contract deployment process and increase the success rate of contract deployments on Mainnet or Mumbai testnet. Furthermore, you can save on gas costs and avoid unnecessary delays.

Additionally, you can take this GitHub repo as a reference

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article