2

I seem to be running the following error when I try to run this script: ,

from brownie import AdvancedCollectible, accounts, network, config

def main():
    dev = accounts.add(config['wallets']['from_key'])
    print(dev)

My brownie-config.yaml:

# exclude SafeMath when calculating test coverage
# https://eth-brownie.readthedocs.io/en/v1.10.3/config.html#exclude_paths
reports:
  exclude_contracts:
    - SafeMath
dependencies:
  - smartcontractkit/chainlink-brownie-contracts@1.0.2
  - OpenZeppelin/openzeppelin-contracts@3.4.0
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/chainlink-brownie-contracts@1.0.2'
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.4.0'
dotenv: .env
wallets:
  from_key: ${PRIVATE_KEY}
  from_mnemonic: ${MNEMONIC} 

The error:

brownie run scripts/advanced_collectible/deploy_advanced.py 

Brownie v1.14.3 - Python development framework for Ethereum

NftdemoProject is the active project.

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

Running 'scripts/advanced_collectible/deploy_advanced.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/advanced_collectible/deploy_advanced.py", line 4, in main
    dev = accounts.add(config['wallets']['from_key'])
  File "brownie/network/account.py", line 132, 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 246, 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 694, 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

I made sure I have my keys set in my .env file as export PRIVATE_KEY='0x...", so why is it not able to pull the variable from it or am I missing some step here? Any advice would be appreciated. Thanks!

7
  • could you run echo $PRIVATE_KEY and verify that the private key is correct with the 0x appended? And could you add your brownie-config.yaml file to the question? May 13, 2021 at 13:59
  • Updated with my brownie-config.yaml Just ran echo $PRIVATE_KEY but it didn't return anything, I did notice that my .env file seems to be getting read as plaintext by visualstudio... could that be the problem?
    – rizonpoint
    May 14, 2021 at 18:50
  • Run source .env in your shell. Or add dotenv: .env to your brownie config May 14, 2021 at 18:57
  • I already had dotenv: .env in my brownie config (interesting why that didn't work), so I tried to run source .env per your advice, and that seems to now return the correct key from my .env file when i run echo $PRIVATE_KEY. Double checked it to make sure i have it appended correctly, but still getting the non-hexadecimal digit error.
    – rizonpoint
    May 14, 2021 at 20:17
  • Does it have the 0x at the front? May 14, 2021 at 21:04

2 Answers 2

1

I have the same error on my Windows system. When i hardcoded my private key in brownie-config.yaml from_key: 0x... everything works fine. So, i think the problem in python part, when it tries to get variable. Also, trying to get value in console using echo $Env:PRIVATE_KEY works fine.

0

I just encountered the same error, what should fix it is the python package python-dotenv. Once you install it python should be able to read those .env files.

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.