This content originally appeared on DEV Community and was authored by Loading Blocks
Transaction Fee
Transaction fee = Gas units * Gas price
Core Concepts
- Gas units: unit of computation for executing an operation.
- Gas price: how much ETH you pay for every gas unit, it is composed of base fee and priority fee (tip).
- Gas limit: the maximum gas you allow for one transaction.
Important Mechanism
- Gas refund: unused gas will be refunded to sender after the transaction finish.
-
Out of Gas: if
gasUsed > gasLimit
, transaction will fail and rollback all state changes, but the gas already used will not be refunded. - Batching: better to split heavy computation into multiple smaller transactions to avoid exceeding gas limit.
// ❌ Bad:
// function doMassiveLoop() public {
// for (uint i = 0; i < 1000000; i++) {
// // ... do work
// }
// }
// ✅ Good: batches
uint public start = 0;
uint public constant INCREMENT = 100;
function doWorkInBatches() public {
uint end = start + INCREMENT;
for (uint i = start; i < end; i++) {
// ... only do small part of work
}
start = end; // update next starting index
}
This content originally appeared on DEV Community and was authored by Loading Blocks
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
Loading Blocks | Sciencx (2025-08-21T14:40:02+00:00) Gas Cost & Estimation. Retrieved from https://www.scien.cx/2025/08/21/gas-cost-estimation/
" » Gas Cost & Estimation." Loading Blocks | Sciencx - Thursday August 21, 2025, https://www.scien.cx/2025/08/21/gas-cost-estimation/
HARVARDLoading Blocks | Sciencx Thursday August 21, 2025 » Gas Cost & Estimation., viewed ,<https://www.scien.cx/2025/08/21/gas-cost-estimation/>
VANCOUVERLoading Blocks | Sciencx - » Gas Cost & Estimation. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/21/gas-cost-estimation/
CHICAGO" » Gas Cost & Estimation." Loading Blocks | Sciencx - Accessed . https://www.scien.cx/2025/08/21/gas-cost-estimation/
IEEE" » Gas Cost & Estimation." Loading Blocks | Sciencx [Online]. Available: https://www.scien.cx/2025/08/21/gas-cost-estimation/. [Accessed: ]
rf:citation » Gas Cost & Estimation | Loading Blocks | Sciencx | https://www.scien.cx/2025/08/21/gas-cost-estimation/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.