Search code examples
pythonweb3py

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


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.


Solution

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