I am trying to make a swap on Uniswap v3 through the SwapRouter contract via the ExactInputSingle function. The ABI states that this function gets tuple as the input parameter. How can I encode this data? When I try to encode input parameters in tuple I get an error: enter image description here

enter image description here

Are there any other methods of creating swap transaction?

  • Try to use an array instead.
    – v1bio
    Commented Feb 14, 2022 at 12:36
  • @v1bio If You mean to use list instead of tuple, then the same error occurs. Only this phrase changes: positional argument(s) of type (<class 'list'>,)
    – xKarma
    Commented Feb 14, 2022 at 16:24

1 Answer 1


create the contract instance using ethers.js

 uniSwapRouterV3 = new ethers.Contract(uniSwapRouterAddress, RouterAbi.abi, ethersProvider.getSigner());

create the params object:

  const params = {
        tokenIn: address,
        tokenOut: address,
        fee: poolFee,
        recipient: userAddress,
        deadline: Math.floor(Date.now() / 1000) + 900,
        amountIn: amountInToWei,
        amountOutMinimum: amountOutMin,  (or just leave it 0)
        sqrtPriceLimitX96: 0

and than the transaction:

const tx = await uniSwapRouterV3.exactInputSingle(params);

This is working and will return the sent transaction. If you want to get the receipt just wait for some confirmations.

  const receipt = await tx.wait([confirms = 1]);
  • OP is using web3.py library.. your answer is for ethers.js
    – BonisTech
    Commented Jan 31, 2023 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.