codedamn logo

How to estimate gas prices of a function in Remix IDE

  • Vishnupriya's profile image
    Team codedamn
How to estimate gas prices of a function in Remix IDE

Remix IDE is a popular choice among people who are starting Blockchain Development and want to try deploying a smart contract to the Blockchain without going through the hassle of setting up a local environment by themselves. As we know each function call on the blockchain requires a gas cost to be paid so that we can use the computational power of the EVM. As a developer, it is your job to ensure that each function call on your smart contract is optimised to a level that the lowest amount of gas is being used, this can be done by avoiding loops, grouping uints of the same value together, etc. Remix IDE allows you to check how much gas your function call might cost, it is an approximate value and is never constant as gas costs change every second on the Blockchain. Let’s see how to check this.

This is an example of an ERC-721 NFT smart contract.

As you can see the highlighted part shows the amount of gas that the function setCost will take when being called by the Owner.

As mentioned above sometimes gas is impossible to predict as it changes every second, in such cases the Remix IDE returns Infinite Gas.

User avatar