I spend a lot of time trying to understand where is the mistake.

I try to swap USDC to any token on uniswap router v3 with ethers.js on frontend.

I use Polygon network in app and in metamask too.

I have a confirmation in my metamask to approve USDC, but after it I have no confirmation about swapping. I see an error in console:

inpage.js:1 MetaMask - RPC Error: Internal JSON-RPC error. code: -32603 data: code: -32000 message: "execution reverted"

This is my code:

const provider = new ethers.providers.Web3Provider(window.ethereum);

const send_account = await provider.getSigner().getAddress();  //my address

//Swap from USDC to MTS or any other token

addressOfUSDC='0x2791bca1f2de4661ed88a30c99a7a9449aa84174' // Address of USDC in Polygon
const ERC20Contract = new ethers.Contract(addressOfUSDC, ERC20ABI, provider);
swapRouterAddress="0xe592427a0aece92de3edee1f18e0157c05861564"; //Uniswap v3 router
indadr="0x440416D85E5D51424da371297E3d7Ef28312BF62"; //Any token address to which I want to swap

approvalAmount=12; //12 USDC

await ERC20Contract
    .approve(swapRouterAddress, approvalAmount*1000000)

//After this step we see confirmation to spend 12$ in metamask

bn=ethers.BigNumber.from(approvalAmount*1000000); //BigNumber from approvalAmount

const params = {
    tokenIn: addressOfUSDC,
    tokenOut: indadr, 
    fee: ethers.BigNumber.from(3000),  
    recipient: send_account,
    deadline: ethers.BigNumber.from(Math.floor(Date.now() / 1000) + (60 * 10)),
    amountIn: bn,
    amountOutMinimum: ethers.BigNumber.from(0),
    sqrtPriceLimitX96: ethers.BigNumber.from(0),

const UniswapContract= new ethers.Contract(swapRouterAddress, ERC20ABI2, provider);

dd=await UniswapContract


And after this step I have no confirmation in metamask and error in console: MetaMask - RPC Error: Internal JSON-RPC error. execution reverted

Maybe the problem is that I use two different router ABIs?

Please help me to understand the problem! Thanks in advanse!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy