I am interested to analyze the execution cost of the function by considering the best practice to adopt, because of that I used bytes32 rather than String which decrease the execution cost of the function from infinite to finite.

I am eager to know whats the best way to find the accurate gas execution cost. I compile the same code 2-3 times in remix and sometimes it gives me the different execution gas cost. Like for below function sometimes it gives me

    Execution cost: 624gas 

and sometimes

    Execution cost: 454 gas.

The function is below which simply return the length of an array.

    function totalLoans() public view returns (uint){

1) Does the difficulty parameter also impact the execution gas cost? 2) Is there any way that we find the ideal gas cost?


The gas cost for the same function may be different depending on the state of the contract. I had asked a question here which will give you an idea on what factors gas depends on.

The best way I know to estimate Gas is to use estimate gas method. Since extra gas is returned in most cases ( not when tx fails because of assert statement), it is advised to send higher gas price than estimated. Extra gas send will be refunded.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.