Given a smart contract, How do I figure out the total amount of gas used? Say for example a smart contract which has a parameterized constructor which stores 5 variables which are address type variables, passed in the parameter of a function. What would be the amount of gas this function uses?

also, whoever uses the smart contract can give their choice of gas cost?


Each operation in the EVM costs gas. Different operations cost different amount of gas - you can read more for example here: https://hackernoon.com/ether-purchase-power-df40a38c5a2f (and its references). I'm not too familiar with the opcodes so I can't tell you how much storing 5 addresses would exactly cost.

Clients typically provide you with a gas estimate when you are about to send a transaction. Often this is an accurate estimate but sometimes it's impossible to estimate it properly.

Whoever sends a transaction to a contract can decide the gas price. The higher price you give the faster miners will probably include you transaction in a block but also the more Ether the transaction costs for you.

| improve this answer | |

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.