0

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

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

4

3 回答 3

2

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

于 2021-06-02T20:36:09.243 回答
0

确保地址中没有双引号"

[wbnb.strip('"'), tokenToBuy.strip('"')]
于 2021-11-17T20:37:59.447 回答
0

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

于 2022-01-30T07:41:32.717 回答