For protocols with continuous transaction flows — automatic liquidations, rebalancing, keeper functions, bridge relayers — gas cost directly impacts economics. When liquidating $50 with a gas cost of $30, profitability depends on whether you send the transaction at 20 Gwei or 80 Gwei.
We develop comprehensive gas optimization systems — not a one-off contract refactor, but a combination of contract optimizations, dynamic timing, and monitoring infrastructure. Our experience: 10+ years in blockchain, 50+ projects with proven savings.
A common mistake: ignoring gas price volatility and sending all transactions with a fixed maxFeePerGas — the protocol loses up to 60% of its gas budget. We solve this via adaptive strategies. Example: a protocol with 5000 transactions per month reduced costs from $15,000 to $4,500 — real savings. Contact us to evaluate your project and get a turnkey solution.
How to Optimize Gas at the Smart Contract Level?
The first optimization layer is the contracts themselves. Performance gains can reach 30–70% compared to naive implementations.
Storage — the most expensive operation. SSTORE is one of the costliest opcodes. Strategies:
- Packing storage variables — variables in the same slot (32 bytes) are read and written together. Solidity compiler automatically packs variables smaller than 32 bytes if declared sequentially. Analyze via Foundry gas reports.
- Avoid repeated SLOADs in a single function. Read into memory once and work with that.
-
Custom errors instead of require strings —
error InsufficientBalancesaves ~200 gas on deploy and ~50 gas per call.
Calldata optimization: Zero bytes cost 4 gas, non-zero bytes 16 gas (EIP-2028). Use a bitmap for boolean flags instead of separate parameters:
function execute(uint8 flags) external { bool useFlashLoan = flags & 0x01 != 0; bool reinvest = flags & 0x02 != 0; bool autoCompound = flags & 0x04 != 0; } Multicall pattern — batching multiple calls into one transaction via OpenZeppelin Multicall. Savings: 21,000 gas × (N-1) for N operations.
Yul/Assembly for critical paths: For inner-loop functions with thousands of calls, inline assembly gives 10–40% savings. Example — optimized token transfer:
function _efficientTransfer(address token, address to, uint256 amount) internal { assembly { let ptr := mload(0x40) mstore(ptr, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) mstore(add(ptr, 0x04), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) mstore(add(ptr, 0x24), amount) if iszero(call(gas(), token, 0, ptr, 0x44, ptr, 0x20)) { revert(0, 0) } } } Use Yul only when profiling shows a real bottleneck — such code is harder to audit.
Dynamic Transaction Timing Strategy
The second layer is when to send transactions. Ethereum gas has a cyclical pattern: lowest on weekends (especially Sunday UTC 02:00–08:00), highest on weekdays during US trading session (14:00–22:00 UTC). For non-critical operations, delaying to low-gas periods saves real money (up to $5,000/month per our data).
EIP-1559 model: effectiveGasPrice = min(maxFeePerGas, baseFee + maxPriorityFeePerGas). baseFee adjusts algorithmically to network load. baseFee predictability 1–3 blocks ahead is high enough to wait for a drop.
Gas Oracle: a decision system with exponential backoff and jitter:
async function waitForOptimalGas(strategy: GasStrategy): Promise<void> { while (true) { const block = await provider.getBlock("latest"); const baseFee = block.baseFeePerGas!; if (baseFee <= strategy.maxBaseFee || block.number >= strategy.deadline) break; const waitMs = Math.min(12000, 3000 * Math.random() + 3000); await sleep(waitMs); } } Batch Operations and EIP-4337 Account Abstraction
Account Abstraction via EIP-4337 adds possibilities:
-
UserOperation batching: multiple operations in one
UserOpwith atomic execution. - Gas sponsorship (Paymaster): pay gas in ERC-20 tokens if the keeper wallet has no ETH.
- Parallel submission via EntryPoint: multiple UserOps from different users are batched by a bundler, savings shared.
| Strategy | Gas Savings | Implementation Complexity |
|---|---|---|
| Storage packing | 30–50% | Low |
| Multicall | 40–70% | Medium |
| EIP-4337 batching | 50–80% | High |
EIP-4337 batching saves 1.5–2× more gas than simple Multicall due to eliminating external calls.
Why Transactions Get Stuck and How to Prevent It?
When gas price spikes sharply, a transaction with low maxFeePerGas may remain unconfirmed for hours. A watchdog service is needed that sends a replacement with the same nonce and increased maxFeePerGas (+20%) after 10–20 blocks:
async function speedUpTransaction(originalTx: TransactionResponse) { const currentBaseFee = (await provider.getBlock("latest"))!.baseFeePerGas!; const newMaxFee = maxBigInt( originalTx.maxFeePerGas! * 120n / 100n, currentBaseFee * 2n ); return wallet.sendTransaction({ ...originalTx, maxFeePerGas: newMaxFee, maxPriorityFeePerGas: originalTx.maxPriorityFeePerGas! * 120n / 100n, }); } What You Get as a Result
- Optimized smart contracts (audit included)
- Transaction timing strategy with Gas Oracle
- Monitoring infrastructure (Prometheus + Grafana) with alerts
- Documentation and team training
- System warranty — 6 months of support
Additionally, we configure alerts for fee drops and anomalies in gas monitoring. Request a consultation — we'll tailor a solution for your protocol. Average savings for our clients: from $5,000 per year at moderate load.
Wikipedia: Gas (Ethereum) — the basic concept we account for.
The overall effect of a comprehensive gas optimization system for high-throughput protocols: 40–70% reduction in gas costs compared to unoptimized baseline. Specific numbers depend on operation type, network, and gas market volatility. Contact us to evaluate your project — we'll design and deploy a turnkey system.







