Gas
The cost of Ethereum transactions is measured by gas, a measurement that reflects the number of computational steps performed by a miner executing a transaction. Each type of operation on a smart contract has a set amount of gas required, specified by the Ethereum network. The total amount of gas for the contract is calculated as the sum of the cost for each operation in the contract.
The sender submitting the transaction has to specify to the network a gas price and a gas limit. The gas price is the per-gas-unit rate to be paid in Ether (ETH). The gas price times the units of gas consumed determines the fee in ETH paid by the transaction sender to the node that ultimately mines the transaction. The gas limit is the maximum amount of gas to be used when processing a contract before rejecting a transaction.
Since Ethereum contracts can contain complex logic and extensive loops, gas is used when evaluating the contract and the contract gas consumption can only be determined via execution. If the gas limit is reached and the contract has not been completed the transaction is rejected. This is to avoid the halting problem when malicious (DDOS) or accidental (infinite loops) attacks via a smart contract translation can debilitate the network. The sender is refunded for any unused gas at the end of the transaction.
A “gas replacement” transaction is also possible where the sender can resubmit a transaction with a higher transaction fee either to speed up the transaction (to be incorporated in the block) or push a transaction that could be cancelled through. Each transaction issued on the network carries a nonce, and blockchains must only include one transaction per (account, nonce) pair on the network. When a user reissues an unconfirmed transaction with the same (account, nonce) pair but a higher gas price, a miner will prefer the reissued transaction.