This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Overview
Opcode:0x3aIntroduced: Frontier (EVM genesis)GASPRICE pushes the gas price of the current transaction onto the stack, measured in wei per gas unit.
Specification
Stack Input:
[]
Stack Output:
gasPrice (uint256, wei per gas)
Gas Cost: 2 (GasQuickStep)Operation:
stack.push(transaction.gasPrice)
Behavior
Returns the gas price specified in the transaction. For EIP-1559 transactions, this is the effective gas price (baseFee + priorityFee).Key characteristics:
Same value throughout transaction
In wei per gas unit
For EIP-1559: min(baseFee + maxPriorityFeePerGas, maxFeePerGas)
contract GasPriceTracker { uint256[] public recentPrices; function record() public { recentPrices.push(tx.gasprice); } function averagePrice() public view returns (uint256) { uint256 sum = 0; for (uint i = 0; i < recentPrices.length; i++) { sum += recentPrices[i]; } return sum / recentPrices.length; }}
Gas Cost
Cost: 2 gas (GasQuickStep)
Common Usage
Transaction Cost Calculation
function estimateCost(uint256 gasEstimate) public view returns (uint256) { return gasEstimate * tx.gasprice;}
Minimum Gas Price
modifier minGasPrice(uint256 min) { require(tx.gasprice >= min, "Gas price too low"); _;}function urgentOperation() public minGasPrice(50 gwei) { // Only execute if gas price >= 50 gwei}
Security
EIP-1559 Considerations
Post-EIP-1559, tx.gasprice is effective gas price, not maxFeePerGas: