current position:Home>Uniswap docking ethtokenswapinput displays false transaction mined but execution failed

Uniswap docking ethtokenswapinput displays false transaction mined but execution failed

2022-02-03 22:48:34 Q & A of Denglian community

Writing the same sol file , It has been imported uniswapfactroy and uniswapexchange Interface file of , Next, create a new one util File complete ethToTokenSwapInput, The code is as follows

contract UniswapUtils {    // ropsten testnet    address public constant UNISWAP_FACTORY_ADDRESS = 0x9c83dCE8CA20E9aAF9D3efc003b2ea62aBC08351;    // DAI address    address public constant DAI_ADDRESS = 0xaD6D458402F60fD3Bd25163575031ACDce07538D;function getUniswapExchange(address _tokenAddress)        public        view        returns (address)    {        return            IUniswapFactory(UNISWAP_FACTORY_ADDRESS).getExchange(_tokenAddress);    }/**     * @dev ETH=>DAI     * @param _ethAmount amount of ETH sold     * @return Amount of DAI bought     */    function ethToDai(uint256 _ethAmount)         public         returns (uint256)     {        return ethToDai(_ethAmount, uint256(1));    }    /**     * @dev ETH=>DAI     * @param _ethAmount amount of ETH sold     * @param _minTokenAmount minimum DAI bought     * @return Amount of DAI bought     */    function ethToDai(uint256 _ethAmount, uint256 _minTokenAmount)        public        returns (uint256)    {        IUniswapExchange uniswapExchange=IUniswapExchange(getUniswapExchange(DAI_ADDRESS));        return uniswapExchange.ethToTokenSwapInput.value(_ethAmount)(_minTokenAmount, uint256(now + 60));    }}

stay remix Up test ethtoDai(), Display error , The reasons for the error are as follows :https://ropsten.etherscan.io/tx/0xe2d3af02a85a1135c88d33d4f94e98dcf1825fa9ffb6b48388d3d970ab380051




Take the answer 1:

msg.value Not for 0






Other answers 1:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032248328801.html

Random recommended