0

Tring to perform a swap in a dapp of mine on uniswap router v3.

export const swapFromRouter = async (
  tokenIn: string,
  tokenOut: string,
  fee: string,
  recipient: string,
  deadline: string,
  amountIn: string,
  amountOutMin: string,
  sqrtPriceLimitX96: string
) => {
  try{
    const params = {
      tokenIn: tokenIn,
      tokenOut: tokenOut,
      fee: fee,
      recipient: recipient,
      deadline: deadline,
      amountIn: amountIn,
      amountOutMin: amountOutMin,
      sqrtPriceLimitX96: sqrtPriceLimitX96
    }

    const signer = new ethers.providers.Web3Provider(window.ethereum).getSigner()
    const router = new ethers.Contract(routerAddress, SwapRouter.abi, signer)
    router.exactInputSingle(params, {value: '0'})
  }
  catch(error){
    console.log(error, 'this is the error for swapFromRoute')
  }
}

getting this error

Unhandled Rejection (Error): invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.6.0)

I'm passing a value there so i really do not know what i'm doing wrong. Can i have some third option?

1 Answer 1

1

Ethers prefers many things as a big number format

you would need to import the BigNumber from ethers, and convert any line/variable with that error to a BN

import { ethers, BigNumber } from "ethers";
BigNumber.from("0")

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.