Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:(forge) Size of contracts via 'forge size' or 'forge build --size' #588

Closed
pbshgthm opened this issue Jan 26, 2022 · 4 comments
Closed
Labels
C-forge Command: forge D-easy Difficulty: easy P-low Priority: low T-feature Type: feature

Comments

@pbshgthm
Copy link
Contributor

pbshgthm commented Jan 26, 2022

It'll be useful to have a command that prints out the contact sizes in kb. This would help optimise contract size and stay below the 24kb limit, especially while importing multiple libraries. The command could look something like this

$ forge size

SampleContract       :      23kb
AnotherContract      :       2kb
NewContract          :      16kb

Alternatively, this feature can also be part of forge build with a tag, something like

$ forge build --size

compiling...
success.

SampleContract       :      23kb
AnotherContract      :       2kb
NewContract          :      16kb

If you think this could be a useful addition to forge, I can take this up.

@pbshgthm pbshgthm changed the title feat:(forge) Size of contracts via forge size feat:(forge) Size of contracts via 'forge size' or 'forge build --size' Jan 26, 2022
@onbjerg onbjerg added C-forge Command: forge D-easy Difficulty: easy P-low Priority: low T-feature Type: feature labels Jan 26, 2022
@odyslam
Copy link
Contributor

odyslam commented Jan 26, 2022

Absolutely, I created a script for dapptools-template and I remember it was widely accepted as a good idea.

On top of that, we could use a gas price API to show the approximate price of deploying the contract at current gas market conditions.

Here is the bash script that did all of that: https://github.com/gakonst/dapptools-template/blob/master/scripts/common.sh

An easy hack is to count the chars of the bytecode and divide that by 2, since due to encoding every ascii character encodes 2 bytes. A hardhat plugin had some issue with proper size estimation when non-ascii characters were used in the contract (e.g part of some string)

@pbshgthm
Copy link
Contributor Author

Awesome, the gas price would be an interesting feature too. I'll look into it.

@onbjerg
Copy link
Member

onbjerg commented Mar 21, 2022

Was this addressed in #682?

@onbjerg
Copy link
Member

onbjerg commented Apr 16, 2022

Closing this because of #682

@onbjerg onbjerg closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge D-easy Difficulty: easy P-low Priority: low T-feature Type: feature
Projects
None yet
Development

No branches or pull requests

3 participants