【问题标题】:web3.py swapExactTokensForTokens failing transactionweb3.py swapExactTokensForTokens 交易失败
【发布时间】:2021-05-29 21:49:16
【问题描述】:

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

【问题讨论】:

    标签: python web3py


    【解决方案1】:

    更新:

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

    【讨论】:

      猜你喜欢
      • 2021-10-22
      • 2022-01-04
      • 2019-02-21
      • 2021-10-07
      • 2021-05-11
      • 2018-11-04
      • 2014-04-09
      • 2018-09-19
      • 1970-01-01
      相关资源
      最近更新 更多