0

我有完全相同的问题我正在使用以下代码在这部分的 Patrick Collins 课程中学习

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()

  • 我有布朗尼 v1.14.6
  • 我在同一个存储库中有 .env 和 brownie-config.ymal
  • 我已经尝试过 import os 一行,然后 print(os.getenv("PRIVATE_KEY")) 并返回相同的错误和“none”

我认为这是 .env 的问题(变量环境,以及我已经尝试手动添加 PATH 变量但仍然不起作用)返回相同的错误:

PS C:\Users\ericl\demos\brownie_simple_storage> brownie run .\scripts\deploy.py --network rinkeby
INFO: Could not find files for the given pattern(s).
Brownie v1.14.6 - Python development framework for Ethereum

BrownieSimpleStorageProject is the active project.

Running 'scripts\deploy.py::main'...
  File "c:\users\ericl\appdata\local\programs\python\python39\lib\site-packages\brownie\_cli\run.py", line 49, in main
    return_value, frame = run(
  File "c:\users\ericl\appdata\local\programs\python\python39\lib\site-packages\brownie\project\scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File ".\scripts\deploy.py", line 23, in main
    deploy_simple_storage()
  File ".\scripts\deploy.py", line 5, in deploy_simple_storage
    account = get_account()
  File ".\scripts\deploy.py", line 19, in get_account
    return accounts.add(config["wallets"]["from_key"])
  File "c:\users\ericl\appdata\local\programs\python\python39\lib\site-packages\brownie\network\account.py", line 132, in add
    w3account = web3.eth.account.from_key(private_key)
_utils\decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "c:\users\ericl\appdata\local\programs\python\python39\lib\site-packages\eth_account\account.py", line 246, in from_key
    key = self._parsePrivateKey(private_key)
  File "c:\users\ericl\appdata\local\programs\python\python39\lib\site-packages\eth_utils\decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "c:\users\ericl\appdata\local\programs\python\python39\lib\site-packages\eth_account\account.py", line 696, in _parsePrivateKey
    raise ValueError(
ValueError: The private key must be exactly 32 bytes long, instead of 0 bytes.

注意:我使用的是 Windows 10

4

0 回答 0