I am working on react native project, using v6 of ethers.js and infuria as my node.

I initiate the contract like this:

    const uniswapRouterAddress = '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45';
  const uniswapRouterContract = new ethers.Contract(

I would like to swap sepolia eth for erc-20 token and this line throws an error:

const WETHAddress = await uniswapRouterContract.WETH();

[Error: could not decode result data (value="0x", info={ "method": "WETH", "signature": "WETH()" }, code=BAD_DATA, version=6.8.0)]

I tried WETH9() and I get same error. This is what I am trying to do.

const pairAddress = await uniswapRouterContract.getPair(WETHAddress, devTokenAddress);

// Create a contract instance for the Uniswap pair
const pairContract = new ethers.Contract(pairAddress, uniswapPairAbi, sepoliaProvider);

// Fetch reserves from the Uniswap pair
const reserves = await pairContract.getReserves();
const token0Reserve = reserves[0];
const token1Reserve = reserves[1];

// Calculate the exchange rate
const exchangeRate = token1Reserve / token0Reserve;

// Set the exchange rate in the component state

// Parse values to ensure they are valid
const parsedAmountToPay = ethers.utils.parseUnits(amountToPay, 'ether');
const parsedAmountToReceive = ethers.utils.parseUnits(amountToReceive, 'ether');

// Perform the swap with SEPOLIA ETH (represented by ethers.constants.AddressZero)
const result = await uniswapRouterContract.exactInputSingle({
  tokenIn: ethers.constants.AddressZero,
  tokenOut: devTokenAddress,
  fee: 3000, // Assuming a fee of 0.3%
  recipient: userAddress,
  deadline: deadline,
  amountIn: parsedAmountToPay,
  amountOutMinimum: parsedAmountToReceive,
  sqrtPriceLimitX96: 0,


Your Answer

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