web3.py swapExactTokensForTokens 交易失败

时间:2021-02-27 22:26:54

标签: python web3py

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

1 个答案:

答案 0 :(得分:1)

更新:

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