txGasPrice
Signature
Section titled “Signature”function txGasPrice(uint256) external;function txGasPrice(uint256 newGasPrice) external;Description
Section titled “Description”Sets tx.gasprice for the rest of the transaction.
Examples
Section titled “Examples”We can use this to get accurate gas usage for a transaction.
function testCalculateGas() public { vm.txGasPrice(2); uint256 gasStart = gasleft(); myContract.doStuff(); uint256 gasEnd = gasleft(); uint256 gasUsed = (gasStart - gasEnd) * tx.gasprice; // tx.gasprice is now 2}