alchemyplatform / hello-world-tutorial

28 stars 24 forks source link

I can't figure this out...env string not read. #2

Closed SpiralBlu closed 2 years ago

SpiralBlu commented 2 years ago

I have written out the code, copied the code. I have the .env file created with my API_URL and PRIVATE_KEY in it, but VSCode keeps saying that PRIVATE_KEY is declared but it's value is never read. (ts6133). I have puzzled over this for about 3 hours hoping to figure it out.

Really appreciate the class on creating smart contracts. I'm just stuck and really want to learn.

When I try to compile it gives an error: "* Invalid account: #0 for network: ropsten - private key too short, expected 32 bytes"

VSCode never highlights the accounts PRIVATE_KEY string either.

Any thoughts would be helpful. I'm sure it's something simple stupid.

hello-world-hardhat-config-js

jaypaik commented 2 years ago

Looks like you want backticks here instead of a single quote:

-        accounts: ['0x${PRIVATE_KEY}']
+        accounts: [`0x${PRIVATE_KEY}`]

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Hope that helps!

SpiralBlu commented 2 years ago

Looks like you want backticks here instead of a single quote:

-        accounts: ['0x${PRIVATE_KEY}']
+        accounts: [`0x${PRIVATE_KEY}`]

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Hope that helps!

Doh...I bet you're right. I knew it had to be something simple stupid. Teaches me to swing from Python to Solidity.

The error had me thinking it wasn't picking the variable up out of .env.

SpiralBlu commented 2 years ago

That's what it was. Thank you for a second set of eyes. I was sure it was something stupid simple.