Book a free call

How to Cut Gas Costs in Polygon Smart Contracts

Polygon fees are already low, but a careless contract still wastes them. These gas efficiency tricks cut the cost of every call your contract makes.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Cut Gas Costs in Polygon Smart Contracts
On this page

Short answer

You cut gas costs in Polygon smart contracts by using less storage, packing data tightly, batching work into fewer transactions and setting fees with the EIP-1559 model. Polygon runs on POL as its gas token, with a base fee that is burned and a priority tip that must be at least 25 gwei, so both the code and the fee settings decide what you pay.

What is gas efficiency on Polygon?

Gas efficiency on Polygon is the practice of writing smart contracts that use as little computation and storage as possible, so each transaction costs less POL. Gas is the unit that measures the work a transaction does, and the fee is gas used multiplied by the price per unit of gas.

Polygon fees are already low. A simple transfer costs a fraction of a cent in normal conditions, and a complex swap costs a few thousandths of a dollar. But a contract that runs thousands of times a day, or that stores data it never needs, still adds up, and a badly written function can cost several times what a careful one costs.

Two levers control the bill. The first is how much gas your contract uses, which is decided by your code. The second is the price per unit of gas, which is decided by the network and your fee settings. This guide covers both, starting with the code.

How do Polygon gas fees work?

Polygon PoS uses the EIP-1559 fee model. Every transaction pays a base fee set by the protocol, which rises when blocks are full and falls when they are not, and the base fee is burned rather than paid to anyone. On top of that, the sender adds a priority tip for the block producer.

Polygon nodes enforce a minimum tip of 25 gwei, so a wallet that copies Ethereum defaults of 1 or 2 gwei will see its transaction sit unconfirmed. The gas token is POL, which replaced MATIC on Polygon PoS on 4 September 2024. A simple POL transfer always uses 21,000 gas, while contract calls use more depending on what the code does. Gas fee best practices cover the same model for everyday transactions.

ActionTypical gasNote
Send POL21,000Fixed for a plain transfer
Send an ERC-20 tokenAbout 65,000Runs the token contract
Mint an NFTAbout 120,000Creates and stores new data
DEX swapAbout 180,000Several contract calls in one
Deploy a contract1,000,000 or moreDepends on contract size

The Bhilai hard fork in July 2025 raised the block gas limit from 30 million to 45 million, which gave the network more headroom. Even so, a busy mint or a popular launch can still push the base fee far above its usual level, so fee settings matter most exactly when users care most. What gas fees are explains the same units in more detail.

Where does gas go in a smart contract?

Gas goes to four places in a smart contract: storage, computation, calldata and events. Storage is the most expensive by far, because every value written to the chain must be kept by every node forever. Computation covers the operations themselves, calldata is the data sent with the call, and events are the logs a contract emits.

Cost areaWhy it costsFix
Storage writesPermanent state on every nodePack variables, delete when done
ComputationEach operation costs gasFewer loops, simpler maths
CalldataBytes sent with the callShort inputs, batch calls
EventsLog storageLog only what clients need

A useful rule is to treat storage as the budget. If a value can be computed from other data, or read from an event instead of stored, it usually should be. The cheapest storage slot is the one you never write.

Which code tricks save the most gas?

The code tricks that save the most gas are the ones that cut storage writes. Packing small values into one storage slot, using the smallest integer type that fits, and deleting data you no longer need are the three biggest wins in most contracts.

Other tricks help in smaller ways. Marking a function view or pure when it does not change state avoids a transaction entirely. Using unchecked blocks for arithmetic that cannot overflow saves the cost of the safety checks.

Passing data as calldata instead of memory avoids a copy. Setting the compiler optimiser to a high run count tunes the code for repeated calls rather than cheap deployment. Building on Polygon is where most teams first meet these choices.

None of these tricks is free. Packing makes code harder to read, unchecked blocks need careful review, and a high optimiser run count makes deployment more expensive. Apply them where the function runs often, and keep the code readable where it runs rarely.

How do batching and design choices cut gas?

Batching cuts gas by turning several transactions into one. Approving a token, swapping it and sending the result in three separate transactions pays the fixed 21,000 gas cost three times. Doing the same work in one call pays it once, and the savings grow with every user.

Design choices matter as much as code. A contract that updates one balance per user per call is cheaper than one that loops over every user on each call. A pull pattern, where users claim their own funds, is cheaper than a push pattern that sends funds to many addresses in one transaction.

Caching also helps. Reading a value from storage once and reusing it in the same call costs far less than reading it five times. The same applies to external calls: one call to another contract that returns everything you need beats five calls that each return one value.

How do you measure and test gas before you deploy?

Measuring gas before deployment is the only way to know whether a change helped. Guessing from the code alone is unreliable, because the compiler and the storage layout decide much of the cost.

  1. Set the optimiser runs to match expected use. A high run count suits a contract that will be called often; a low one suits a contract called rarely.
  2. Run the test suite with gas reporting. Most toolchains can print the gas used by each function in every test.
  3. Compare each function before and after a change. Keep the numbers, so a change that looks clever but costs more is caught.
  4. Test on the Polygon Amoy testnet. Real fee conditions show how the contract behaves when the base fee moves.
  5. Check the gas station estimate. The Polygon Gas Station gives current fee tiers, so the priority tip can be set from live data.
  6. Set a gas limit with headroom. Allow room for variation, but not so much that a runaway loop goes unnoticed.

Repeat the measurement after every change that touches storage or loops. Gas work is not a one-time task. Each new feature can undo the savings of the last one, and the test suite is the only place that shows it. Tokenomics on Polygon shows the same measure-first habit applied to token design.

Example (hypothetical): one function, before and after

Example (hypothetical): a rewards contract has a claim function that uses 100,000 gas. At a base fee of 50 gwei and a priority tip of 25 gwei, the price is 75 gwei per unit of gas. One call costs 100,000 times 75 gwei, which is 7,500,000 gwei, or 0.0075 POL. At an assumed POL price of 0.50 dollars, that is 0.00375 dollars per call.

After packing storage and removing one storage read, the function uses 60,000 gas. One call then costs 60,000 times 75 gwei, or 4,500,000 gwei, which is 0.0045 POL, or 0.00225 dollars at the same assumed price. That is a 40 percent saving on every call.

At 10,000 calls a month, the original function costs 37.50 dollars and the optimised one costs 22.50 dollars, saving 15.00 dollars a month. The saving is small for one user and large for a contract that runs for years, which is why gas work pays for itself. Polygon costs put these figures in the wider context of building on the network.

What are the common mistakes?

The most common Polygon gas mistakes are setting a 1 gwei tip and wondering why nothing confirms, storing data that could be an event, and deploying without gas reporting.

  • Setting a 1 gwei tip. Polygon nodes enforce a 25 gwei minimum tip. A wallet that copies Ethereum defaults stalls.
  • Storing data that could be an event. Data nobody needs to read on-chain belongs in an event log, not in storage.
  • Looping over unbounded lists. A loop that grows with the user base will one day cost more than the block gas limit allows.
  • Deploying without gas reporting. Without measured numbers, a change that costs more looks the same as one that saves.
  • Optimising for deployment, not for calls. A cheap deployment that makes every call expensive is the wrong trade for a busy contract.
  • Ignoring fees during a busy mint. The base fee spikes exactly when users care most, so fee settings deserve a test under load.

Key takeaways

  • Polygon uses EIP-1559: a burned base fee plus a priority tip with a 25 gwei floor
  • POL is the gas token, replacing MATIC on Polygon PoS in September 2024
  • Storage is the most expensive gas cost, so pack variables and delete what you no longer need
  • Batching turns several 21,000-gas fixed costs into one
  • Measure gas in the test suite and on Amoy before every deployment

Frequently asked questions

What is the minimum gas tip on Polygon?

Polygon nodes enforce a minimum priority tip of 25 gwei. A transaction with a lower tip will sit unconfirmed, because the node software will not include it. Wallets that copy Ethereum defaults of 1 or 2 gwei are the usual cause of a stalled Polygon transaction.

What token pays for gas on Polygon?

POL pays for gas on Polygon PoS. POL replaced MATIC as the gas token on 4 September 2024, when MATIC held on Polygon PoS was upgraded automatically. A wallet needs POL on the Polygon network to pay gas; a balance on another network does not pay the bill.

How much gas does a simple transfer use on Polygon?

A plain POL transfer always uses 21,000 gas. Contract calls use more: an ERC-20 token transfer is about 65,000 gas, an NFT mint about 120,000, and a DEX swap about 180,000. Real contracts vary, so treat these as ballpark figures for planning.

What is the cheapest way to store data in a smart contract?

The cheapest storage is no storage. If a value can be computed from other data, or read from an event log instead of a storage slot, it usually should be. When storage is needed, pack small values into one slot and use the smallest integer type that fits.

Does the compiler optimiser really save gas?

Yes, for contracts that are called often. Setting a high optimiser run count tunes the code for repeated calls, which lowers the gas of each call but makes deployment more expensive. A low run count suits a contract that is deployed once and called rarely.

Why did my Polygon transaction stall?

The usual cause is a priority tip below the 25 gwei floor, often because a wallet copied Ethereum defaults. Another cause is a base fee spike during a busy mint or launch, which pushes the total fee above the maximum the wallet set. Check the Polygon Gas Station for current fee tiers.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building on Polygon and want lower gas bills? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Polygon Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to contact@hertiv.com.

Prefer email? Write to contact@hertiv.com
Estimate costBook a call