【发布时间】:2022-01-14 04:06:38
【问题描述】:
请帮帮我!
我不明白,为什么我不能从我的代币合约中批准。 我总是这样做,这段代码有效。但现在我遇到了错误。
我的代码:
def approves(w3, token_contract, router_contract, my_account, my_pk):
allowance_value = token_contract.functions.allowance(
my_account, router_contract.address).call()
print('allowance_value: ', allowance_value)
if allowance_value <= 1000000000000000:
approve_est_gas = token_contract.functions.approve(
router_contract.address,
100000000000000000000000
).estimateGas(
{
'from': my_account,
'nonce': w3.eth.get_transaction_count(my_account)
}
)
approve_tx_builder = token_contract.functions.approve(
router_contract.address,
100000000000000000000000
).buildTransaction(
{
'from': my_account,
'nonce': w3.eth.get_transaction_count(my_account),
'gas': approve_est_gas
}
)
signed_tx = w3.eth.account.sign_transaction(approve_tx_builder, my_pk)
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
print('tx_hash: ', tx_hash.hex())
我有这个错误:
ValueError: {'code': -32601, 'message': 'the method eth_maxPriorityFeePerGas does not exist/is not available'}
【问题讨论】:
-
看来 ETH 硬分叉可能在本次更新中发生了变化,您不能再使用该方法了。
-
@TamilSelvan 谢谢,我明白了。我尝试使用 web3==5.24.0 执行此方法,并且此方法有效,但我无法通过路由器 v2 进行交换没关系。我收到“传输失败”。
标签: python blockchain smartcontracts web3py bsc