1

still learning Solidity and all ecosystem around it and I still thinking about the best way how to perform deployment.

I have my solidity contracts (using HardHat suite) where I have some console.log statements as same as comments.

But I believe it would be better to clean all comments and console.log before deploying to production.

So what I would like to do is:

  • remove all console.logs
  • remove all comments
  • run prettier to re-format code

And then, tell HardHat to compile & deploy this modified contracts (for example exported to contracts.prod) and deploy it to production.

Are there any tools for that? Or should I write some scripts by myself by using regex/prettier manually?

Thanks

0

2 Answers 2

4

Yes, there is Hardhat plugin called hardhat-log-remover that can do this for you. You just add it as a plugin in your Hardhat config, and then you can run it from the terminal like this:

$ yarn run hardhat remove-logs
3
  • 1
    thanks, I will check it! Commented Dec 18, 2022 at 17:54
  • 1
    One more thanks for the reply. It seems that hardhat-preprocessor fits even more to my use case. Commented Dec 18, 2022 at 18:29
  • No worries, happy to help. Feel free to mark the answer as accepted if it helped you. Commented Dec 18, 2022 at 20:07
0

It is worth reviewing the work of hardhat-log-remover. For example:

if (condition) console.log('...');
action;

will be converted to:

if (condition) action;

which is wrong

If we use {}:

if (condition) { console.log('...'); }

will be converted to

if (condition) { }

which is redundant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.