3

I'm trying to swap tokens using swapExactTokensForTokens() (Pancakeswap Router function).

Here is my code

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))

But i keep getting error as the result:

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.

I checked type of every argument passed to the function and thy matched.

Danil
  • 4,781
  • 1
  • 35
  • 50

3 Answers3

3

the second argument u passed is type 'float' instead of the required 'int'.

richie
  • 181
  • 5
2

I've just solved a similar problem, and it took me more than 3 hours to figure out that: if your address has one space at the beginning or the end, then it is not an address and you will get the error No matching argument type. But the point is, I've never thought that a space can take me 3 hours. So, check your address if there is any space in it.

0

Make sure there are no double quotes " in addresses.

[wbnb.strip('"'), tokenToBuy.strip('"')]
Danil
  • 4,781
  • 1
  • 35
  • 50