[英]web3.py swapExactTokensForTokens failing transaction
我正在嘗試調用路由器合約的 swapExactTokensForTokens,我需要將 tokenA 交換為 tokenB。 這是交易的代碼:
router = '0x0000000'
abi = '[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},.... {"stateMutability":"payable","type":"receive"}]'
router_contract = w3.eth.contract(router, abi=abi)
tokenA = '0x000...'
tokenB = '0x000...'
path = [tokenA, tokenB]
txn = router_contract.functions.swapExactTokensForTokens(amount, min_amount, path, personal_wallet, (int(time()) +1000) ).buildTransaction({
'gas': 81000,
'gasPrice': w3.toWei('10', 'gwei'),
'nonce': w3.eth.get_transaction_count(personal_wallet),
})
我在交易中收到以下錯誤:
更新:
當增加 gas 並在buildTransaction
中添加from
字段時,上面的代碼可以正常工作。
function = router_contract.functions.swapExactTokensForTokens(數量,
0,
[
tokenA,
tokenB
],
wallet,
int(time.time()) + 10 * 60)
estimated_gas = function.estimateGas({'from':'0x10780b34025a93927ae62776Fe43419166ec88D2'})
tx_params = {
'from': wallet,
'gas': estimated_gas,
'gasPrice': conf.w3.toWei('10', 'gwei'),
'nonce': conf.w3.eth.getTransactionCount(wallet)
}
transaction = function.buildTransaction(tx_params)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.