1

I'm reading undefined for my enviroment variable.When I console log process.env I can't seem to find the variable I defined In my .env file at the root directory.

.env.local file

privateKey="444455....."

scripts/hardhat.config.js

mumbai: {
  url: 'https://polygon-mumbai.g.alchemy.com/v2/3333.....',
  accounts: [process.env.privateKey]
},

Is it because I'm reading process.env outside of pages? I aslo tried prefixing like NEXT_PUBLIC_privateKey="0033....." and then reading it process.env.NEXT_PUBLIC_privateKey but value would only show inside pages folder and not in scripts/hardhat.config.js

2 Answers 2

1

Make sure you have installed and initialized the doting NPM package that is needed to use environment variables.

Sign up to request clarification or add additional context in comments.

Comments

0

FINALLY WORKS

I ended up adding the dotenv AS SOMEONE SUGGESTED and starts reading.

Note to self

Enviroment variables outside next.js pages need that dotnev thing;

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.