I am trying to run a script in brownie, but I'm running into this error:

ValueError: The private key must be exactly 32 bytes long, instead of 0 bytes.
Terminating local RPC client...

I'm using a .env file with a PRIVATE_KEY environment variable.

What can I do to solve it?

  • What coin and wallet is this? This is a private key, not phrase you enter right? Jul 27, 2021 at 13:45
  • What are you trying to do? You haven't provided information that we can use to help.
    – Ismael
    Jul 27, 2021 at 14:58

3 Answers 3


When working with Brownie and private key environment variables, you'll need to make sure a few things are set.

  1. In your .env file, you have your PRIVATE_KEY variable set correctly. If using a .env file, it should look something like:
export PRIVATE_KEY='0xasdfasdfasdfasdfasdfasdfasdfas'

If you exported your private key from metamask, you'll want to append a 0x to the start of your key.

  1. You'll want to make sure your brownie-config.yaml is set to include a .env file, if that's what you're using to set your environment variable.

In your brownie-config.yaml:

dotenv: .env
  1. Then finally, you'll want your environment variable set correctly in your brownie-config.yaml, something like:
  from_key: ${PRIVATE_KEY}

Where you are using the appropriate $ and bracket syntax.

  • @Pratick Collins I followed all the steps you have listed in your answer. But, I am still getting the error ValueError: The private key must be exactly 32 bytes long, instead of 0 bytes. Dec 5, 2021 at 8:24
  • On doing source .env , everything worked. Do we have to run source .env everytime the .env file is changed? Or is there a way brownie can detect changes in the .env file. Dec 5, 2021 at 8:33

your PRIVATE_KEY in .env should be the wallet metamask private key not the encrypted private key showed the step before or the wallet adress. seems =0 that you didn't set up PRIVATE_KEY in .env


In your main script, add


If it prints [None] in the terminal, that mean its not reading your key. Make your its:

export PRIVATE_KEY='0xasdfasdfasdfasdfasdfasdfasdfas' [In Ubuntu]

PRIVATE_KEY='0xasdfasdfasdfasdfasdfasdfasdfas' [In windows]

Make sure to put 0x before the private key & = sign instead of : sign

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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