dapptools icon indicating copy to clipboard operation
dapptools copied to clipboard

Estimate gas for contract deployment

Open odyslam opened this issue 4 years ago • 6 comments

I created a smol bash script that calculates the contract deployment cost based on current gas cost. It's PRed into the gakonst/dapptools-template repo but I was wondering if you would want it part of the dapp suite.

It could be particularly sweet to see the cost estimation for different tests during dapp test, as it outputs the gas already. This could give the dev a quick overview of how expensive a particular operation will be to the user.

PR: https://github.com/gakonst/dapptools-template/pull/11#issuecomment-917391978 Dependencies: jq, tput, column

odyslam avatar Sep 11 '21 13:09 odyslam

Yeah, this is nice, but I think the more general solution to this problem is to have seth send estimate the gas cost and set ETH_GAS to the result of seth estimate before sending

MrChico avatar Sep 11 '21 14:09 MrChico

Hey @MrChico,

Actually, the use-case that I had in mind was for the user to know when to send the contract. Ideally, I can see this running every X time and letting the user know that the contract 's deployment cost has reached some threshold.

Interestingly, seth estimate has a bit of a different output. It's more accurate, since it's used to deploy the contract. My script has more of a generic market view, while seth estimate tells you how your provider will expense you.

odyslam avatar Sep 16 '21 17:09 odyslam

Ah if that's what you meant @OdysLam I'll create another issue for estimating gas by default with seth send (instead of hardcoding 200k gas by default like we do now)

transmissions11 avatar Sep 17 '21 05:09 transmissions11

We could have both outputs with seth estimate and a flag

estimate --market estimate --provider (default)

Actually, @gakonst has created some good helpers for dapptools-template that could make sense to be integrated into the main project.

e.g what you are saying is already "implemented" in the deploy script: https://github.com/OdysLam/Loaded/blob/3c5e60be2550a1bc032e1ba67c7de989d7322467/scripts/common.sh#L126

odyslam avatar Sep 17 '21 05:09 odyslam

I'm not sure I follow. estimate just provides the gas cost, not anything relating to gas price. What does --market do?

MrChico avatar Sep 17 '21 09:09 MrChico

Right, sorry I meant seth gas-price.

odyslam avatar Sep 17 '21 09:09 odyslam