由于没有匹配的参数类型,函数调用失败。 web3.py、Python

Function invocation failed due to no matching argument type. web3.py, Python

我正在尝试使用 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'.

确保地址中没有双引号 "

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

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