Skip to content

Instantly share code, notes, and snippets.

@ammarhaiderak
Last active August 2, 2024 12:05
Show Gist options
  • Save ammarhaiderak/88971810b97b9fe557dcb25af13d6e3d to your computer and use it in GitHub Desktop.
Save ammarhaiderak/88971810b97b9fe557dcb25af13d6e3d to your computer and use it in GitHub Desktop.
Solidity Cheatsheet

Cheat Sheet for common solidity functions

Gas Consumption inside contract

function foo() public {
        uint256 initialGas = gasleft();
        
        /* 
        
        Your function logic here
        
        */
        
        uint256 gasUsed = initialGas - gasleft();
        uint256 gasPrice = tx.gasprice;
        
        emit GasUsed(gasUsed, gasPrice);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment