错误:尝试在Linux上使用布朗尼添加帐户时发现了非Xexadecimal Digit

发布于 2025-01-24 01:01:36 字数 4427 浏览 0 评论 0原文

我正在尝试使用布朗尼添加一个以太坊帐户。如果我添加私有密钥硬编码,它正在工作,但是如果我尝试使用环境变量(我在WSL上使用ubuntu),我会收到以下错误:

运行'脚本/AdvanceCollectable/decoly_advanced.py :: main'...
文件“布朗尼/_cli/run.py”,第51行,主要 return_value,frame = run(文件“布朗尼/project/scripts.py”,第103行,运行 return_value = f_locals [method_name](*args,** kwargs)file” ./scripts/advancedCollectable/deploy_advanced.py,第4行, dev = accounts.add(config ['Wallets'] ['from_key'])文件“ brownie/network/account.py”,第142行,添加 w3account = web3.eth3.eth.account.from_key(private_key)文件“ eth_utils/decorators.py”,第18行,in _wrapper 返回self.method(obj, *args,** kwargs)文件“ eth_account/account.py”,第250行,in_key key = self.__parseprivatekey(private_key)文件“ eth_utils/decorators.py”,第18行,in _wrapper 返回self.method(obj, *args,** kwargs)文件“ eth_account/account.py”,第775行,in _parseprivatekey 返回self。 bytesval = to_bytes(val)文件“ hexbytes/_utils.py”,第17行,在to_bytes中 返回hexstr_to_bytes(val)文件“ hexbytes/_utils.py”,第50行,在hexstr_to_bytes中 返回binascii.unhexlify(ascii_hex)错误:已找到终止本地RPC客户端的非HEXADECIMAL DIGIT ...

当我使用私钥硬编码执行它时,我会得到以下输出(预期的输出):

笔记本电脑:/mnt/c/users/pedro/study/2022/aplicaçãodaproposta _ nft/contrato_nft $布朗尼运行 脚本/AdvanceCollectable/decoly_advanced.py Brownie v1.18.1- 以太坊的Python开发框架

contratonftproject是活动项目。

启动'ganache-cli -chain.vmerrorsonrpcrespsesse true true -server.port 8545 -miner.blockgaslimit 12000000 -wallet.totalaccounts 10 -Hardfork Istanbul -wallet.mnemonic Brownie'...

运行'脚本/AdvanceCollectable/decoly_advanced.py :: main'... 开发终止本地RPC客户端... alucard86@laptop-ev5un7eh:/mnt/c/users/pedro/study/2022/aplicaçãoda proposta _ nft/contrato_nft $

以下是我正在使用的代码。 我使用环境变量更改了两个数字

(在上述错误中执行结果):.

from brownie import AdvancedCollectible, accounts, network, config

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

env文件:

export PRIVATE_KEY=fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef

尝试使用'''''''''''和“也(获取相同的错误):

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}

检查env变量:

echo $PRIVATE_KEY
fdb0ee33d87a414d57244c1eb5df7b3cd15a69c3041214584e4eb2d2b220e2ef

我在字符串的乞讨时也尝试了带有0x的私钥,但是我遇到了相同的错误。

硬编码的私有密钥脚本(执行很好):

from brownie import AdvancedCollectible, accounts, network, config

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

当我运行代码:

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'])

我得到输出:

布朗尼V1.18.1-以太坊的Python开发框架

contratonftproject是活动项目。

启动'ganache-cli -chain.vmerrorsonrpcrespsesse true true -server.port 8545 -miner.blockgaslimit 12000000 -wallet.totalaccounts 10 -Hardfork Istanbul -wallet.mnemonic Brownie'...

运行'脚本/AdvanceCollectable/decoly_advanced.py :: main'... 发展 0xFDB0EE33D87A414D57244C1EB5DF7B3CD15A69C3041214584EE4EB2D2B220E2EF 终止本地RPC客户端...

我必须使用ENV变量使其正常工作。这个解决方案有什么问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文