首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >UserWarning: eth_maxPriorityFeePerGas方法有一个问题。用eth_feeHistory进行计算

UserWarning: eth_maxPriorityFeePerGas方法有一个问题。用eth_feeHistory进行计算
EN

Stack Overflow用户
提问于 2022-06-12 17:00:59
回答 1查看 270关注 0票数 3

我遵循的是一个流行的坚实的过程,在这个过程中,许多人围绕着web3 gas_price问题。

下面是每个人都必须熟悉的原始脚本。

代码语言:javascript
代码运行次数:0
运行
复制
from solcx import compile_standard, install_solc
import json
from web3 import Web3

with open("./SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()

    install_solc("0.6.0")
    compiled_sol = compile_standard(
        {
            "language": "Solidity",
            "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
            "settings": {
                "outputSelection": {
                    "*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
                }
            },
        },
        solc_version="0.6.0",
    )
with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)

# Get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
    "bytecode"
]["object"]

# Get ABI
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]

# for connecting to ganache
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chain_id = 1337
my_address = "0xa217118d0C418048007B2f935489880F98650cC7"
private_key = "0x8a1e2a2b30b6a8886ba6dd1738af9d30237fd7e286f886495ae3528279f70f6b"

# Create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
print(SimpleStorage)

# Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)

# 1. Build a transaction
# 2. Sign a transaction
# 3. Send a transaciton
transaction = SimpleStorage.constructor().buildTransaction(
    {
        "gasprice": w3.eth.gas_price,
        "chainId": chain_id,
        "from": my_address,
        "nonce": nonce,
    }
)
print(transaction)

我试过

代码语言:javascript
代码运行次数:0
运行
复制
transaction = SimpleStorage.constructor().buildTransaction(
    {
        "gasprice": w3.eth.gas_price,
        "chainId": chain_id,
        "from": my_address,
        "nonce": nonce,
    }
)

但我还是会犯这个错误

代码语言:javascript
代码运行次数:0
运行
复制
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/eth.py:656: UserWarning: There was an issue with the method eth_maxPriorityFeePerGas. Calculating using eth_feeHistory.
  warnings.warn(
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/eth.py", line 654, in max_priority_fee
    return self._max_priority_fee()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'message': 'Method eth_maxPriorityFeePerGas not supported.', 'code': -32000, 'data': {'stack': 'Error: Method eth_maxPriorityFeePerGas not supported.\n    at GethApiDouble.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/geth_api_double.js:70:16)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at GethDefaults.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/gethdefaults.js:15:12)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at SubscriptionSubprovider.FilterSubprovider.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/subproviders/filters.js:89:7)\n    at SubscriptionSubprovider.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/subproviders/subscriptions.js:137:49)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at DelayedBlockFilter.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/delayedblockfilter.js:31:3)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at RequestFunnel.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/requestfunnel.js:32:12)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at Web3ProviderEngine._handleAsync (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:123:3)\n    at Timeout._onTimeout (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:107:12)\n    at listOnTimeout (internal/timers.js:531:17)\n    at processTimers (internal/timers.js:475:7)', 'name': 'Error'}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/alexander/demos/web3_py_simple_storage/deploy.py", line 49, in <module>
    transaction = SimpleStorage.constructor().buildTransaction(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/eth_utils/decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/contract.py", line 684, in buildTransaction
    return fill_transaction_defaults(self.web3, built_transaction)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/_utils/transactions.py", line 114, in fill_transaction_defaults
    default_val = default_getter(web3, transaction)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/_utils/transactions.py", line 64, in <lambda>
    web3.eth.max_priority_fee + (2 * web3.eth.get_block('latest')['baseFeePerGas'])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/eth.py", line 660, in max_priority_fee
    return fee_history_priority_fee(self)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/_utils/fee_utils.py", line 45, in fee_history_priority_fee
    fee_history = eth.fee_history(*PRIORITY_FEE_HISTORY_PARAMS)  # type: ignore
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/eth.py", line 876, in fee_history
    return self._fee_history(block_count, newest_block, reward_percentiles)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/web3/manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'message': 'Method eth_feeHistory not supported.', 'code': -32000, 'data': {'stack': 'Error: Method eth_feeHistory not supported.\n    at GethApiDouble.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/geth_api_double.js:70:16)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at GethDefaults.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/gethdefaults.js:15:12)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at SubscriptionSubprovider.FilterSubprovider.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/subproviders/filters.js:89:7)\n    at SubscriptionSubprovider.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/subproviders/subscriptions.js:137:49)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at DelayedBlockFilter.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/delayedblockfilter.js:31:3)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at RequestFunnel.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/requestfunnel.js:32:12)\n    at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n    at Web3ProviderEngine._handleAsync (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:123:3)\n    at Timeout._onTimeout (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:107:12)\n    at listOnTimeout (internal/timers.js:531:17)\n    at processTimers (internal/timers.js:475:7)', 'name': 'Error'}}

在我的情况下,添加代码"gas_price“似乎不起作用。关于我出了什么问题有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2022-06-13 13:23:23

找到解决办法了。“汽油价格”的价格必须是资本。

代码语言:javascript
代码运行次数:0
运行
复制
transaction = SimpleStorage.constructor().buildTransaction(
    {
        "gasPrice": w3.eth.gas_price,
        "chainId": chain_id,
        "from": my_address,
        "nonce": nonce,
    }
)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72594258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档