5

eth | KeyError:baseFeePerGas

 1 year ago
source link: https://benpaodewoniu.github.io/2022/11/24/eth45/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

eth | KeyError:baseFeePerGas

这是新版本 web3.py 导致的问题。

之前我们可以这样

tx_dic = test_contract_obj.functions.swapCoin(
routers,
tokenContracts,
receiveAddress,
receiveAmount,
one_router
). \
buildTransaction(
{
'gas': 500000,
}
)

但是,在新版本的 web3.py 中,这样会导致错误。

Traceback (most recent call last):
File "/Users/licong/python/Rhino/Rhino-Script/RhinoScript/RhinoGateway/Other/EVMSwapSol/SwapCoin.py", line 44, in <module>
print(swap_coin(routers, tokenContracts, receiveAddress, receiveAmount, one_router))
File "/Users/licong/python/Rhino/Rhino-Script/RhinoScript/RhinoGateway/Other/EVMSwapSol/SwapCoin.py", line 7, in swap_coin
tx_dic = test_contract_obj.functions.swapCoin(
File "/Users/licong/anaconda3/envs/py3.9/lib/python3.9/site-packages/web3/_utils/decorators.py", line 51, in wrapper
return to_wrap(*args, **kwargs)
File "/Users/licong/anaconda3/envs/py3.9/lib/python3.9/site-packages/web3/contract.py", line 1112, in buildTransaction
return self.build_transaction(transaction)
File "/Users/licong/anaconda3/envs/py3.9/lib/python3.9/site-packages/web3/contract.py", line 1099, in build_transaction
return build_transaction_for_function(
File "/Users/licong/anaconda3/envs/py3.9/lib/python3.9/site-packages/web3/contract.py", line 1672, in build_transaction_for_function
prepared_transaction = fill_transaction_defaults(web3, prepared_transaction)
File "cytoolz/functoolz.pyx", line 249, in cytoolz.functoolz.curry.__call__
File "/Users/licong/anaconda3/envs/py3.9/lib/python3.9/site-packages/web3/_utils/transactions.py", line 114, in fill_transaction_defaults
default_val = default_getter(web3, transaction)
File "/Users/licong/anaconda3/envs/py3.9/lib/python3.9/site-packages/web3/_utils/transactions.py", line 64, in <lambda>
web3.eth.max_priority_fee + (2 * web3.eth.get_block('latest')['baseFeePerGas'])
File "/Users/licong/anaconda3/envs/py3.9/lib/python3.9/site-packages/web3/datastructures.py", line 51, in __getitem__
return self.__dict__[key] # type: ignore
KeyError: 'baseFeePerGas'

应该这样使用

tx_dic = test_contract_obj.functions.swapCoin(
routers,
tokenContracts,
receiveAddress,
receiveAmount,
one_router
). \
buildTransaction(
{
'gas': 500000,
'gasPrice': test_w3.eth.gasPrice,
}
)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK