Error: Non-hexadecimal digit found when trying to add account using brownie on Linux

888 views Asked by At

I am trying to add an Ethereum account using Brownie. It is working if I add the private key hardcoded, but I get the following error if I try to use the environment variable (I am using Ubuntu on WSL):

Running 'scripts/advancedCollectable/deploy_advanced.py::main'...
File "brownie/_cli/run.py", line 51, 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/advancedCollectable/deploy_advanced.py", line 4, in main dev = accounts.add(config['wallets']['from_key']) File "brownie/network/account.py", line 142, 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 775, 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...

When I execute it with the private key hardcoded I get the following output (the expected one):

LAPTOP:/mnt/c/Users/pedro/study/2022/Aplicação da proposta _ NFT/contrato_nft$ brownie run scripts/advancedCollectable/deploy_advanced.py Brownie v1.18.1 - Python development framework for Ethereum

ContratoNftProject is the active project.

Launching 'ganache-cli --chain.vmErrorsOnRPCResponse true --server.port 8545 --miner.blockGasLimit 12000000 --wallet.totalAccounts 10 --hardfork istanbul --wallet.mnemonic brownie'...

Running 'scripts/advancedCollectable/deploy_advanced.py::main'... development Terminating local RPC client... alucard86@LAPTOP-EV5UN7EH:/mnt/c/Users/pedro/study/2022/Aplicação da proposta _ NFT/contrato_nft$

Below is the code I am using. I have changed two numbers from the private key

Using the environment variable (execution results in the mentioned error):

from brownie import AdvancedCollectible, accounts, network, config

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

.env file:

export PRIVATE_KEY=fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef

Tryed with '' and "" too (get the same error):

export PRIVATE_KEY='fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef'

export PRIVATE_KEY="fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef"

brownie-config.yaml:

dependencies:
  - OpenZeppelin/[email protected]
  - smartcontractkit/[email protected]
compiler:
  solc:
    remappings:
      - '@openzeppelin=OpenZeppelin/[email protected]'
      - '@chainlink=smartcontractkit/[email protected]'
wallets:
  from_key: ${PRIVATE_KEY}

Check env variable:

echo $PRIVATE_KEY
fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef

I have tried the private key with 0x at the begging of the string too, but I get the same error.

Hardcoded private key script (execution is fine):

from brownie import AdvancedCollectible, accounts, network, config

def main():
    dev = accounts.add('fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef')
    print(network.show_active())

When I run the code:

from brownie import AdvancedCollectible, accounts, network, config

def main():
    dev = accounts.add('fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef')
    print(network.show_active())
    publish_source = False
    print(config['wallets']['from_key'])

I get the output:

Brownie v1.18.1 - Python development framework for Ethereum

ContratoNftProject is the active project.

Launching 'ganache-cli --chain.vmErrorsOnRPCResponse true --server.port 8545 --miner.blockGasLimit 12000000 --wallet.totalAccounts 10 --hardfork istanbul --wallet.mnemonic brownie'...

Running 'scripts/advancedCollectable/deploy_advanced.py::main'... development 0xfdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef Terminating local RPC client...

I have to make it work using the env variable. What is wrong with this solution?

0

There are 0 answers