Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 556 Bytes

tx-gas-price.md

File metadata and controls

29 lines (21 loc) · 556 Bytes

txGasPrice

Signature

function txGasPrice(uint256) external;
function txGasPrice(uint256 newGasPrice) external;

Description

Sets tx.gasprice for the rest of the transaction.

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
}