const ethers = require('ethers');

// Ethereum network configuration
// const provider = new ethers.getDefaultProvider('https://mainnet.infura.io/v3/<TRUFFLEHOG_REDACTED_INFURA>');
const provider = new ethers.JsonRpcProvider('http://127.0.0.1:8545/');

const privateKey = 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';

// Uniswap V3 contract configuration
const uniswapV3SwapRouterAddress = '0xE592427A0AEce92De3Edee1F18E0157C05861564';
const uniswapV3SwapRouterABI = require('./abi.json');

// Token configuration
const tokenToSwapAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const tokenToReceiveAddress = '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984';
const tokenToSwapAmount = ethers.parseUnits('0.001', 'ether');

// Connect to wallet
const wallet = new ethers.Wallet(privateKey, provider);

// Load the Uniswap V3 contract
const uniswapV3SwapRouterContract = new ethers.Contract(uniswapV3SwapRouterAddress, uniswapV3SwapRouterABI, wallet);

async function executeTrade() {
  // Approve Uniswap V3 SwapRouter to spend tokenToSwap
  const tokenToSwapContract = new ethers.Contract(tokenToSwapAddress, uniswapV3SwapRouterABI, wallet);
  const approvalTx = await tokenToSwapContract.approve(uniswapV3SwapRouterAddress, tokenToSwapAmount);
  await approvalTx.wait();

  // Prepare swap transaction
  const swapParams = {
    tokenIn: tokenToSwapAddress,
    tokenOut: tokenToReceiveAddress,
    fee: 3000,
    recipient: wallet.address,
    deadline: Math.floor(Date.now() / 1000) + 60 * 20,
    amountIn: tokenToSwapAmount,
    amountOutMinimum: 0,
    sqrtPriceLimitX96: 0,
  };

  const swapTx = await uniswapV3SwapRouterContract.exactInputSingle(swapParams);

  console.log('Swap transaction hash:', swapTx.hash);

  // Wait for transaction confirmation
  await swapTx.wait();
  console.log('Swap transaction confirmed!');
}

executeTrade().catch((error) => {
  console.error('Error executing trade:', error);
});
PS C:\Users\lidor\Desktop\Trade Bot> node index.js
Error executing trade: TypeError: no matching function (argument="key", value="exactInputSingle", code=INVALID_ARGUMENT, version=6.4.1)
    at makeError (C:\Users\lidor\Desktop\Trade Bot\node_modules\ethers\lib.commonjs\utils\errors.js:118:21)
    at assert (C:\Users\lidor\Desktop\Trade Bot\node_modules\ethers\lib.commonjs\utils\errors.js:142:15)
    at assertArgument (C:\Users\lidor\Desktop\Trade Bot\node_modules\ethers\lib.commonjs\utils\errors.js:154:5)
    at Interface.getFunctionName (C:\Users\lidor\Desktop\Trade Bot\node_modules\ethers\lib.commonjs\abi\interface.js:433:39)     
    at buildWrappedMethod (C:\Users\lidor\Desktop\Trade Bot\node_modules\ethers\lib.commonjs\contract\contract.js:240:34)        
    at Contract.getFunction (C:\Users\lidor\Desktop\Trade Bot\node_modules\ethers\lib.commonjs\contract\contract.js:688:22)      
    at Object.get (C:\Users\lidor\Desktop\Trade Bot\node_modules\ethers\lib.commonjs\contract\contract.js:598:39)
    at executeTrade (C:\Users\lidor\Desktop\Trade Bot\index.js:42:52)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'INVALID_ARGUMENT',
  argument: 'key',
  value: 'exactInputSingle'
}
PS C:\Users\lidor\Desktop\Trade Bot> 
i have this error and i assume it's an abi issue so how do i get the official abi of uniswap