Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Update truffle init artifacts #5320

Merged
merged 15 commits into from
Aug 12, 2022
Merged

Update truffle init artifacts #5320

merged 15 commits into from
Aug 12, 2022

Conversation

sukanyaparashar
Copy link
Contributor

@sukanyaparashar sukanyaparashar commented Jul 18, 2022

ISSUE

Update truffle init artifacts. See #5268.

SOLUTION

This PR follows the below mentioned steps to update truffle init artifacts -

  • Remove Migrations.sol from contracts.
  • Remove 1_initial_migration.js from migrations.
  • Update the sample truffle-config.js including the following -
    • Use Goerli or Sepolia as the testnet.
    • Change .secret to .env.
    • Get mnemonic and Infura project id from .env.
    • The comment says auto create at 9545, but the development environment config is 8545. What should be the ideal behaviour? I guess, the comment needs to be changed and use managed Ganache instance instead of development blockchain.
  • Add a .gitignore with .env in it.

@sukanyaparashar sukanyaparashar marked this pull request as draft July 18, 2022 19:24
@sukanyaparashar sukanyaparashar marked this pull request as ready for review July 22, 2022 17:16
Copy link
Contributor

@cliffoo cliffoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sukanyaparashar for taking this on! I've left a few comments. Note that issue#5268 also mentioned changing the comment on line 35 in truffle-config.js (from port 9545 to 8545)

@@ -0,0 +1 @@
.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a newline at the end.

Comment on lines 19 to 29
* If you want to use .env for keeping your secret variables, you'll need to install 'dotenv'
* (npm install dotenv). To get started with, add .env file in the root directory and declare
* your Infura MNEMONIC and PROJECT_ID variables.
* .gitignore is already added with this project with .env in it.
*/

// require('dotenv').config();
// const HDWalletProvider = require('@truffle/hdwallet-provider');
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

// const mnemonic = process.env.MNEMONIC;
// const projectId = process.env.PROJECT_ID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the default we give users is reading from process.env, that means we want users to use dotenv right? So I would phrase this as:

It is recommended to store your secret variables in a .env file (which you should include in .gitignore). In your project root, run npm i dotenv , create .env and declare your MNEMONIC and infura PROJECT_ID variables inside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also destructure maybe? const { MNEMONIC, PROJECT_ID } = process.env;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestions make sense to me. I will change the comments. Thanks @cliffoo.

// goerli: {
// provider: () => new HDWalletProvider(mnemonic, `https://goerli.infura.io/v3/${projectId}`),
// network_id: 5, // Goerli's id
// gas: 5500000, // Goerli has a lower block limit than mainnet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the comment about gas hold true for Goerli?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it does and maybe this is not very helpful in here. What do you think? Should we just get rid of this gas line altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any suitable documentation for this gas line. I guess we can just get rid of this for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gnidan @haltman-at Do you guys have any insight on where this gas comment is from? Should it be kept / changed now that it's goerli?

@@ -94,7 +99,7 @@ module.exports = {
// evmVersion: "byzantium"
// }
}
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comma should stay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier again :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, please don't use --no-verify flag on commits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what should you do when committing non-JS files or in situations like this where you don't want prettier to update things? I think in this case using that flag should be fine. Do you disagree or have a different solution?

Copy link
Contributor Author

@sukanyaparashar sukanyaparashar Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were discussing that if we can somehow exclude some files from using prettier. I have raised an issue for this #5360. For now, lets use --no-verify for this PR. And find a way to resolve this prettier issue later.

@sukanyaparashar
Copy link
Contributor Author

sukanyaparashar commented Jul 26, 2022

Thanks @sukanyaparashar for taking this on! I've left a few comments. Note that issue#5268 also mentioned changing the comment on line 35 in truffle-config.js (from port 9545 to 8545)

Thanks for the review @cliffoo. In regards to the point of changing the port from 9545 to 8545, there is a catch here. Port 9545 is used by the managed Ganache when truffle develop is run with no network config.

On the other hand, when truffle test is run, it looks for the development network settings in the config by default, where 8545 is mentioned (Note: ganache-cli has the default port 8545).

Any thoughts on what should be the ideal default values for the development configuration?

@cliffoo
Copy link
Contributor

cliffoo commented Aug 4, 2022

@sukanyaparashar Yea I think the development network config is fine, the confusion comes from here, where it mentions a "development blockchain", which makes one wonder if it's referring to the development network (it isn't). I don't really know how to call it instead, "dev"? "ephemeral"? Your call 😅

@sukanyaparashar
Copy link
Contributor Author

@sukanyaparashar Yea I think the development network config is fine, the confusion comes from here, where it mentions a "development blockchain", which makes one wonder if it's referring to the development network (it isn't). I don't really know how to call it instead, "dev"? "ephemeral"? Your call 😅

I guess a better name will be "managed Ganache instance" instead of a "development blockchain", may be?

@cliffoo
Copy link
Contributor

cliffoo commented Aug 4, 2022

Sounds fine by me 👍 It's nice that it maps to the variable name in code.

Copy link
Contributor

@eggplantzzz eggplantzzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cooool - hit approval but if there is anything left to address from the comments above then do that first before merging :)

@sukanyaparashar
Copy link
Contributor Author

cooool - hit approval but if there is anything left to address from the comments above then do that first before merging :)

Thanks for your approval @eggplantzzz. Yeah! I need to fix few comments and wait for @cliffoo's approval as well.

Copy link
Contributor

@cliffoo cliffoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sukanyaparashar! This is great. I'm just being picky about a few things, feel free to (not) make changes as you see fit. LGTM!


module.exports = {
/**
* Networks define how you connect to your ethereum client and let you set the
* defaults web3 uses to send transactions. If you don't specify one truffle
* will spin up a development blockchain for you on port 9545 when you
* will spin up a managed Ganache instance for you on port 9545 when you
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Comment on lines 89 to 90
solc: {
version: "0.8.15", // Fetch exact version from solc-bin (default: truffle's version)
version: "0.8.15", // Fetch exact version from solc-bin (default: truffle's version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this from here isn't actually resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! I guess I missed that. Will do the required changes. Thanks @cliffoo.

Comment on lines 25 to 28
// require('dotenv').config();
// const HDWalletProvider = require('@truffle/hdwallet-provider');
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

// const { MNEMONIC, PROJECT_ID } = process.env;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the require dotenv line should be adjacent to the destructure line, and separated from the hdwallet-provider line? Like so:

require dotenv
destructure

hdwallet-provider

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do this to make dotenv usage clearer. I will change this. Thanks for pointing that out @cliffoo.

Copy link
Contributor

@cliffoo cliffoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! Thanks @sukanyaparashar

@sukanyaparashar
Copy link
Contributor Author

Nice one! Thanks @sukanyaparashar

Thanks for the approval @cliffoo. I am making few more changes to the truffle-config.js file comments, after discussing with @cds-amal and @gnidan to make it more appealing to the users to read (like recommending to use truffle dashboard for better security practices).

Copy link
Contributor

@cliffoo cliffoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @sukanyaparashar! Definitely a plus to mention dashboard and various trade-offs. My comments are merely suggestions, please proceed with whatever you think is clear and informative 👍

Comment on lines 26 to 27
* PLEASE NOTE 🗒️: This is an insecure workflow! It is possible through human error to leak
* your mnemonic on Github.
Copy link
Contributor

@cliffoo cliffoo Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't sell hdwallet-provider as insecure haha. Maybe it's okay to end it off here? Since it's mentioned above that you shouldn't commit .env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I, kind of agree with you @cliffoo. We may not want to directly say hdwallet-provider as "insecure". We have already mentioned to add .env in .gitignore.

Comment on lines 32 to 35
* Are you concerned about the security 🤔? Use this approach to get rid of this hassle 🤦‍♀️:
*
* A more secure 🔒 workflow is to use truffle dashboard which leverages
* Metamask for signing your transactions and does not require you to reveal your mnemonic to Truffle.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first sentence isn't so clear about what the security and this hassle are. Perhaps this section can be more succinct? Something like:

Are you concerned about security? Truffle dashboard lets you review transactions in detail, and leverages MetaMask for signing so there's no need to copy-paste your mnemonic.

Of course you can insert emojis to your heart's content 🦄

@@ -73,7 +87,7 @@ module.exports = {
//
// Useful for private networks
// private: {
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
// provider: () => new HDWalletProvider(MNEMONIC, `https://network.io`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

*
* A more secure 🔒 workflow is to use truffle dashboard which leverages
* Metamask for signing your transactions and does not require you to reveal your mnemonic to Truffle.
* Are you concerned about the security 🤔? Truffle dashboard lets you review transactions in detail,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final pick, can you remove the in this? All good on my side after this ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Okay! Cool! :)

gnidan
gnidan previously requested changes Aug 11, 2022
Copy link
Contributor

@gnidan gnidan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new truffle-config.js writeup looks great! Just a couple notes

* Deployment with Truffle Dashboard
* ---------------------------------
*
* Are you concerned about the security 🤔? Truffle dashboard lets you review transactions in detail,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Are you concerned about the security 🤔? Truffle dashboard lets you review transactions in detail,
* Are you concerned about the security 🤔? Truffle Dashboard lets you review transactions in detail,

*
* Are you concerned about the security 🤔? Truffle dashboard lets you review transactions in detail,
* and leverages MetaMask for signing, so there's no need to copy-paste your mnemonic.
* Please see this link for more details 🔎: https://trufflesuite.com/docs/truffle/getting-started/using-the-truffle-dashboard/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make sure that all comments fit under 80 characters per line? (My comment here applies generally; this line is just the one that stood out as longest)

@sukanyaparashar
Copy link
Contributor Author

The new truffle-config.js writeup looks great! Just a couple notes

Thanks for the quick review, @gnidan. I will make the suggested changes. :)

Copy link
Member

@cds-amal cds-amal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising security awareness here @sukanyaparashar! Looks good to me.

@@ -11,25 +11,31 @@
* Hands-off deployment with Infura
* --------------------------------
*
* Is your application complex and requires lots of transactions to deploy?
* Is your application complex and require lots of transactions to deploy?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y'know, figuring out whether this should be singular or plural would be a lot easier if this question was correct grammar in the first place... proper grammar here would be "Is your application complex and does it require..." but that sounds so wordy...

Maybe this should be "Do you have a complex application that requires lots of transactions to deploy?" or something that doesn't require combining clauses with an "and".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the poor grammar in the initial wording I wrote for this!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a complex application that requires lots of transactions to deploy?

I like it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! @gnidan. I agree with @cds-amal. I like this "Do you have a complex application that requires lots of transactions to deploy?" wording too. Simple grammar ;)

@gnidan gnidan dismissed their stale review August 12, 2022 04:07

Thanks for making those edits!

Copy link
Contributor

@gnidan gnidan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have another approve :)

Copy link
Contributor

@cliffoo cliffoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have yet another one

@sukanyaparashar sukanyaparashar merged commit 9560b32 into develop Aug 12, 2022
@sukanyaparashar sukanyaparashar deleted the update-truffle-init branch August 12, 2022 18:39
@kevinbluer kevinbluer mentioned this pull request Aug 18, 2022
8 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants