0

I want to evaluate the maximum gas consumption (minimum safe gas limit that will not fail) that calling a specific contract method would consume given that I have the contract source code / byte code.

I remember a few months ago seeing a website where you can enter the solidity code and it calculates how much gas this code would consume, but I can't find this website anywhere.

Just to clarify - I know there's a method in the API that can estimate gas consumption of transaction which is only an estimate since it's based on the variables that can change (such as block number etc), but I'm talking about maximum gas consumption given the contract source code / byte code is known.

Is there a website that calculates this?

UPDATE WITH USE CASE:

For EtherDelta's contract (link) how can I determine what would be the maximum possible gas consumption for calling a specific method (say: the 'approve' method), so that I can tell what is the minimum safe gas limit that would never fail?

0

I think you may be alluding to the online remix compiler for Solidity. This will allow you to see easily how much gas a transaction to a function will need/spent.

If you execute a state changing function then inspect the details of the transaction you'll get more information. Please see the example below:

enter image description here

Here we can see trasaction cost & execution cost. Everything you need. Hope this helps.

  • thank you! I think that's exactly what I was looking for. I've edited my original post and added a specific use case just before I've seen your answer. To understand, in a case when the gas consumed by calling a method changes depending on certain conditions is there a way to check the maximum gas consumed - suppose method says: if before block number X do A (which would consume 100000 gas) and if after block number X do B (which would consumes 150000 gas)? – Amit Dec 12 '17 at 17:53
  • Cool, do you want to mark the question as answered so that other users know? To test that exact case I'd look at either manually creating blocks by sending many transactions or change the Environment used to have your own provider i.e. Injected Web3. This way you'll be able to control more accurately how many blocks you're at. You should be able to test block height conditions easier this way. – Malone Dec 12 '17 at 18:04
0

As per the question you linked to, the estimateGas RPC method is completely accurate aside from things that may change between when you perform the estimate and when the transaction is processed. If the gas used in the contract you're calling does not vary based on such things (e.g. other transactions submitted, the block number/hash, etc.), then estimateGas will give you an exact correct number.

Having the source code doesn't help here except for your own understanding; you would prefer to use the bytecode anyway.

  • I meant inaccurate in the sense that it depends on those other things such as block number etc which are not known in advance.. I agree it's not very clear from my post :) I've edited it to make it clearer and added a specific use case. – Amit Dec 12 '17 at 17:39
  • I see. I know of no tool that offers that kind of analysis. – user19510 Dec 12 '17 at 17:40

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.