gpt4 book ai didi

python - web3.py swapExactTokensForTokens 交易失败

转载 作者:行者123 更新时间:2023-12-04 15:04:32 25 4
gpt4 key购买 nike

我正在尝试调用路由器合约的 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),
})

我在交易中收到以下错误:

screenshot of the transaction

最佳答案

更新:

当增加 gas 并在 buildTransaction 中添加 from 字段时,上面的代码工作正常。

关于python - web3.py swapExactTokensForTokens 交易失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66404029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com