0

When i run brownie run scripts/deploy.py the terminal gives me this error :

Brownie v1.16.4 - Python development framework for Ethereum

BrownieSimpleStorageProject is the active project.

Launching 'ganache-cli --port 8545 --gasLimit 12000000 --accounts 10 --hardfork istanbul --mnemonic brownie'...

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 10, in main
    deploy_simple_storage()
  File "./scripts/deploy.py", line 5, 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 769, in _parsePrivateKey
    return self._keys.PrivateKey(HexBytes(key))
  File "hexbytes/main.py", line 23, in __new__
    bytesval = to_bytes(val)
  File "hexbytes/_utils.py", line 17, in to_bytes
    return hexstr_to_bytes(val)
  File "hexbytes/_utils.py", line 50, in hexstr_to_bytes
    return binascii.unhexlify(ascii_hex)
Error: Non-hexadecimal digit found
Terminating local RPC client...

This is my config file :

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

my .env file :

export PRIVATE_KEY=0x123456abcdef......

and my deploy.py file:

from brownie import accounts, config


def deploy_simple_storage():
    account = accounts.add(config["wallets"]["from_key"])
    print(account)


def main():
    deploy_simple_storage()

I discovered that even if i create a new account, when the terminal asks me to enter the private key i get the same error. Please help!!!

1 Answer 1

1

After saving your .env file type into console source .env that should help.

Also I recommend using this function from Patrick Collins to get your account:

 from brownie import (
    network, 
    config, 
    accounts
  ) 



FORKED_LOCAL_ENVIRONMENTS = ["mainnet-fork"]
LOCAL_BLOCKCHAIN_ENVIRONMENTS = ["development", "ganache-local"]


def get_account(index=None, id=None):
    if index:
        return accounts[index]
    if id:
        return accounts.load(id)
    if (
        network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS
        or network.show_active() in FORKED_LOCAL_ENVIRONMENTS
    ):
        return accounts[0]
    return accounts.add(config["wallets"]["from_key"])

No matter where you test if on testnet or on local machine it will return the right account for you.

Your Answer

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

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