【问题标题】:Function invocation failed due to no matching argument type. web3.py, Python由于没有匹配的参数类型,函数调用失败。 web3.py, Python
【发布时间】:2021-06-02 15:49:45
【问题描述】:

我正在尝试使用 swapExactTokensForTokens()Pancakeswap 路由器功能)交换令牌。

这是我的代码

def swapTokens():
    amountIn = (w3.toWei(0.00001, 'ether'))
    amount1 = contractR.functions.getAmountsOut(
        amountIn,
        [wbnb, tokenToBuy]
    ).call()
    amountOutMin = amount1[1] * 0.9
    minAmountPrint = w3.fromWei(amountOutMin, 'ether')
    print('Minimum recieved:', minAmountPrint)

    swap_TX = contractR.functions.swapExactTokensForTokens(
        amountIn,
        amountOutMin,
        [wbnb, tokenToBuy],
        myAccount,
        (int(time.time()) + 1000000)
    ).buildTransaction({
        'from': myAccount,
        'value': w3.toWei(0.0001, 'ether'),
        'gas': 250000,
        'gasPrice': w3.toWei('5', 'gwei'),
        'nonce': nonce,
    })
    signed_TX = w3.eth.account.sign_transaction(swap_TX, private_key=privateKey)
    tx_token = w3.eth.send_raw_transaction(signed_TX.rawTransaction)
    print(w3.toHex(tx_token))

但结果我不断收到错误:

Could not identify the intended function with name `swapExactTokensForTokens`, positional argument(s) of type `(<class 'int'>, <class 'float'>, <class 'list'>, <class 'str'>, <class 'int'>)` and keyword 
argument(s) of type `{}`.
Found 1 function(s) with the name `swapExactTokensForTokens`: ['swapExactTokensForTokens(uint256,uint256,address[],address,uint256)']
Function invocation failed due to no matching argument types.

我检查了传递给函数的每个参数的类型并匹配。

【问题讨论】:

  • 你传递的第二个参数是类型'float'而不是'int'。这可能是问题吗?
  • 这就是问题所在。谢谢!顺便说一句,交易失败。您是否知道有一项服务可以帮助我弄清楚它在 tx 的哪一步失败?
  • 嘿@richie,既然是这样,也许考虑发布您的 somment 作为答案,以便 OP 可以接受它以获得甜蜜的 +10 声誉:b
  • 我喜欢我的代表@jemand771:D
  • 你可以用其他问题的详细信息编辑问题或用它打开一个新帖子吗?

标签: python web3py


【解决方案1】:

您传递的第二个参数是类型“float”而不是所需的“int”。

【讨论】:

    【解决方案2】:

    确保地址中没有双引号 "

    [wbnb.strip('"'), tokenToBuy.strip('"')]
    

    【讨论】:

      【解决方案3】:

      我刚刚解决了一个类似的问题,我花了3个多小时才弄明白:如果你的地址在开头或结尾有一个空格,那么它就不是地址,你会得到错误No matching argument type。但关键是,我从没想过一个空间可以占用我 3 个小时。因此,请检查您的地址是否有空格。

      【讨论】:

        猜你喜欢
        • 2021-10-16
        • 2020-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-25
        • 2017-05-08
        相关资源
        最近更新 更多