0
votes

I'm working on connecting a feature to my dapp to buy a token with ETH. However, I can't figure out how to get the amounts out from uniswaps array after making the swap.

Here is my basic code:

function buyToken() public payable returns (uint[] memory amounts) {
            require(address(_quoteToken) != address(0), "Quote Token should not be zero address");
    
            address [] memory path = new address[](2);
            path[0] = address(_weth);
            path[1] = address(_quoteToken);
    
            uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: msg.value}(
                0,
                path,
                address(this),
                block.timestamp + 1000
            );
            return(amounts);
           emit Swapped(msg.value);
        }

Here is what I tried:

function buyToken() public payable returns (uint[] memory amounts) {
            require(address(_quoteToken) != address(0), "Quote Token should not be zero address");
    
            address [] memory path = new address[](2);
            path[0] = address(_weth);
            path[1] = address(_quoteToken);
    
            uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: msg.value}(
                0,
                path,
                address(this),
                block.timestamp + 1000
            );
            return(amounts);
           emit Swapped(msg.value);
        }
        uint256 tokenOutputAmount = uint256(amounts[amounts.length - 1]);
        finalAmount = tokenOutputAmount;

I also tried:

uint256 tokenOutputAmount = uint256(amounts[2]);
        finalAmount = tokenOutputAmount;

I keep getting the error that type UINT256 is not directly convertible.