PatrickAlphaC / brownie_simple_storage

25 stars 32 forks source link

Deploy.py results in "The private key must be exactly 32 bytes long, instead of 42 bytes" #15

Closed smellyd closed 2 years ago

smellyd commented 2 years ago

My brownie-config.yaml

dotenv: .env
wallets:
     from_key: ${PRIVATE_KEY}

My .env file

export PRIVATE_KEY='0x########################################'

export WEB3_INFURA_PROJECT_ID=####################

My deploy.py

account = accounts.add(config["wallets"]["from_key"])

I have :

New script

import os

def main():
    print(os.getenv("PRIVATE_KEY"))

Here is my current deploy.py

from brownie import accounts, config, SimpleStorage, network

def deploy_simple_storage():

    account = get_account()
    simple_storage = SimpleStorage.deploy({"from": account})
    stored_value = simple_storage.retrieve()
    print(stored_value)
    transaction = simple_storage.store(15, {"from": account})
    transaction.wait(1)
    updated_stored_value = simple_storage.retrieve()
    print(updated_stored_value)

def get_account():
   if network.show_active() == "development":
        return accounts[0]
     else:
         return accounts.add(config["wallets"]["from_key"])

def main():
    deploy_simple_storage()

I ran

brownie run scripts/deploy.py --network rinkeby

Here is all of the deployment message.

Running 'scripts/deploy.py::main'...
  File "brownie/_cli/run.py", line 49, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/deploy.py", line 38, in main
    deploy_simple_storage()
  File "./scripts/deploy.py", line 11, in deploy_simple_storage
    account = accounts.add(config["wallets"]["from_key"])
  File "brownie/network/account.py", line 140, in add
    w3account = web3.eth.account.from_key(private_key)
  File "eth_utils/decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "eth_account/account.py", line 250, in from_key
    key = self._parsePrivateKey(private_key)
  File "eth_utils/decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "eth_account/account.py", line 771, in _parsePrivateKey
    raise ValueError(
ValueError: The private key must be exactly 32 bytes long, instead of 42 bytes.
Terminating local RPC client...

Any help would really be appreciated!

is-it-ayush commented 2 years ago

export PRIVATE_KEY='0x########################################' I can notice you are using `` after = in the .env file. Remove the colon's ('') and then try running deploy.py. It will resolve the issue. It should finally look like this export PRIVATE_KEY = 0x########################################

smellyd commented 2 years ago

I have tried export PRIVATE_KEY = 0x######################################## export PRIVATE_KEY = 0x########################################
export PRIVATE_KEY =0x######################################## export PRIVATE_KEY=0x######################################## and I get the same error message.

PatrickAlphaC commented 2 years ago

If you'd like, I'd do this:

  1. Make a new metamask
  2. Create an account
  3. Paste the Private key here (MAKE SURE THE ACCOUNT HAS NO MONEY IN IT)
  4. We'll tell you exactly what to put in your .env
smellyd commented 2 years ago

@PatrickAlphaC and @is-it-ayush,

Thank you so much.

I would like to take this time to admit that I apparently didn't copy the entire private key and have spent 5 days reading Brownie docs and bugging you guys. 👎

Thank you for the responses because it got me to the solution.