这与 youtube 上的 Patrick Collins 的“Solidity、Blockchain 和智能合约课程——从初学者到专家 Python 教程”有关。
具体来说,在 Infura 的 Rinkeby 测试网上运行我的程序时出现以下错误。
HTTPError: 401 Client Error: Unauthorized for url: https://rinkeby.infura.io/v3/3d6c16...
我按照一些人的建议进行了以下检查:
检查私钥。这正是我 Metamask 钱包里的东西。
我的 .env 如下所示:
export PRIVATE_KEY=0xf77f98d99d11d5d70aa230770e478aa68b4d0fbf058def08d56909373f46b4c5
export WEB3_INFURA_PROJECT_ID=c2cdf41913e344bc94720dc8244950eb
brownie-config.yaml 看起来像这样:
dotenv: .env
wallets:
from_key: ${PRIVATE_KEY}
我尝试在 Infura.io 上打开一个新项目并向 .env 添加一个新项目 ID,但没有帮助。
该程序在 ganache-cli(使用命令:)上运行良好,brownie run scripts/deploy.py
但在 Rinkeby 测试网(命令:)上运行良好brownie run scripts/deploy.py --network rinkeby
。
该程序昨天按预期运行,但今天没有。互联网连接良好。完整的错误信息如下:
PS C:\Users\z640\demos\brownie_simple_storage> brownie run scripts/deploy.py --network rinkeby
INFO: Could not find files for the given pattern(s).
Brownie v1.16.4 - Python development framework for Ethereum
BrownieSimpleStorageProject is the active project.
Running 'scripts\deploy.py::main'...
File "C:\Python310\lib\site-packages\brownie\_cli\run.py", line 49, in main
return_value, frame = run(
File "C:\Python310\lib\site-packages\brownie\project\scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File ".\scripts\deploy.py", line 66, in main
deploy_simple_storage()
File ".\scripts\deploy.py", line 49, in deploy_simple_storage
simple_storage = SimpleStorage.deploy(
File "C:\Python310\lib\site-packages\brownie\network\contract.py", line 600, in __call__
return tx["from"].deploy(
File "C:\Python310\lib\site-packages\brownie\network\account.py", line 508, in deploy
receipt, exc = self._make_transaction(
File "C:\Python310\lib\site-packages\brownie\network\account.py", line 718, in _make_transaction
gas_price, gas_strategy, gas_iter = self._gas_price(gas_price)
File "C:\Python310\lib\site-packages\brownie\network\account.py", line 454, in _gas_price
return web3.eth.generate_gas_price(), None, None
File "C:\Python310\lib\site-packages\web3\eth.py", line 846, in generate_gas_price
return self._generate_gas_price(transaction_params)
File "C:\Python310\lib\site-packages\web3\eth.py", line 155, in _generate_gas_price
return self.gasPriceStrategy(self.web3, transaction_params)
File "C:\Python310\lib\site-packages\web3\gas_strategies\rpc.py", line 20, in rpc_gas_price_strategy
return web3.manager.request_blocking(RPC.eth_gasPrice, [])
File "C:\Python310\lib\site-packages\web3\manager.py", line 186, in request_blocking
response = self._make_request(method, params)
File "C:\Python310\lib\site-packages\web3\manager.py", line 147, in _make_request
return request_func(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "C:\Python310\lib\site-packages\web3\middleware\gas_price_strategy.py", line 90, in middleware
return make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "C:\Python310\lib\site-packages\web3\middleware\attrdict.py", line 33, in middleware
response = make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "C:\Python310\lib\site-packages\web3\middleware\buffered_gas_estimate.py", line 40, in middleware
return make_request(method, params)
File "C:\Python310\lib\site-packages\web3\middleware\exception_retry_request.py", line 105, in middleware
return make_request(method, params)
File "C:\Python310\lib\site-packages\web3\providers\rpc.py", line 88, in make_request
raw_response = make_post_request(
File "C:\Python310\lib\site-packages\web3\_utils\request.py", line 49, in make_post_request
response.raise_for_status()
File "C:\Python310\lib\site-packages\requests\models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized for url: https://rinkeby.infura.io/v3/3d6c16...