简体   繁体   中英

Uniswap swapRouter02 Error: Transaction reverted without a reason string

I'm testing uniswap's swap transaction

my new contract swap() -> uniswap swapRouter02 contract exactInputSingle() which is not from wallet to contract swap

Specifically below code is trying swap my contract's 0.08 WETH to some UNI. and I checked my contract has 0.08 weth.

0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 => WETH token address
0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 => UNI  token address  
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 => Uniswap SwapRouter02 contract address

but error message when try

ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);

Error: Transaction reverted without a reason string at ~~

what does this message mean? and how can I debug this error?

My test environment is hardhat local forking mainnet. The error message is from hardhat forking mainnet

hardhat: {
  chainId: 31337,
  forking: {
    url: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,
    blockNumber: 14390000
  },
},

function swap() external payable override lock returns (uint256) {
    //approve 
   address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).call(abi.encodeWithSelector(IERC20.approve.selector, 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45, 0x011C37937E080000));

    //test
    uint256 amountOut;
    ISwapRouter02.ExactInputSingleParams memory params =
        IV3SwapRouter.ExactInputSingleParams({
            tokenIn: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
            tokenOut: 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984,
            fee: 0,
            recipient: msg.sender,
            //deadline: _params.deadline,
            amountIn: 0x011C37937E080000,   //0.08
            amountOutMinimum: 0x0,
            sqrtPriceLimitX96: 0
        });
    
    ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);

    return 1;
}

Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="Error: Transaction reverted without a reason string", method="estimateGas", transaction={"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","to":"0xd5a946A0C214d732a8cf5678be593d26E1bf2170","data":"","accessList":null}, error={"name":"ProviderError","code":-32603,"_isProviderError":true,"data":{"message":"Error: Transaction reverted without a reason string","data":"0x"}}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)

I found my fault, reason was amountOutMinimum value must be not 0x0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM