Calculate gas without using dry-run

Hi,

we recently recognized that in our Java SDK we rely on the dry-run debug endpoint to calculate the required gas for contract deployments and contract calls.

Is there any possibility to calculate this without using the dry-run endpoint?

Possibly you shouldn’t run them every time. The gas being consumed is being subtracted from the provided gas and the test is being returned to the caller. If you add too much gas, the unused one is getting back to you so this shouldn’t be a problem. Then you only need a rough estimate to provide a reasonable gas limit and that’s it :slight_smile:

Regarding the gas price - this should be per user to decide - the higher gas price will likely result in the transaction being included faster. If not configured, the node is using the default gas price of 1 000 000 000 and most miners will not accept anything lower than that.

2 Likes

ok understood, thanks. but is it somehow possible to roughly estimate the minimum required gas without using the dry-run endpoint?

If there is a way, I don’t know it. Maybe @hanssv.chain does, though

As Dimitar says the gas price can’t be calculated :sweat_smile:

For gas usage, well you can do it with pen and paper, or by staring long and hard at the (byte) code. But I’d say that dryrunning is easier for the the casual user. If you are running the same/similar calls a lot you can probably spot a pattern and go from there as well. Why is dryrunning a problem?

1 Like

dry-run in general isn’t a problem. but there is a chance that nodes don’t run in debug mode and for those it wouldn’t be possible to perform a dry-run. maybe this endpoint should also be exposed when not running the node in debug mode?

@hanssv.chain @dimitar.chain does anything speak against exposing this endpoint by default?

Well, you could spend CPU cycles through this endpoint, so off by default makes sense I think…

1 Like

I support Hans on this one. Running contracts consumes CPU cycles and electricity. That’s what miners get paid in gas :slight_smile: Having this API exposed by default would mean node operators agree providing this service for free. It also means that they would there open for different attacks - for example sending them computationally heavy dry-runs. If you send enough requests, this could saturate the CPUs of the node.

ok - just needed to know this to improve user experience in that regards. for us that means that everyone that uses our sdk and wants to interact with smart contrtacts needs to have access to a node with debug mode enabled

1 Like