首页 > 解决方案 > 实施 UniswapV2 swapExactTokensForETH 失败

问题描述

智能合约集成/实施交换之后,我的联系人喜欢下面

contract UniDemo {
    function swapTokensForETH(uint amountIn, uint amountOutMin, uint deadline)  public payable returns(uint) {
        // transfer
        require(Token.transferFrom(msg.sender, address(this), amountIn), 'transferFrom failed.');
        // approve
        require(Token.approve(UNISWAP_ROUTER_ADDRESS, amountIn), 'approve failed.');
        // swap
        uint[] memory outs = uniswapRouter.swapExactTokensForETH(amountIn, amountOutMin, getPathForTokenToETH(), msg.sender, deadline);

        return outs[1];
  }
}

我不断收到 EVM 还原错误,这是有问题吗?

发送示例:0x080555abe5287a8e7d67a9129e9464d2773955371fd9ffcf6e81b301d0a7f4df

标签: smartcontracts

解决方案


看起来您没有收到来自路由器 (uniswapRouter) 的任何响应,因此当您的数组为空时,returnouts[1]会引发恢复错误。outs


推荐阅读