I want to convert ETH to USDC using my solidity contract I am using the uniswapV2 contract for converting ETH to token I am using this function swapExactETHForTokens
I am not able to get the path that will be used for swapping ETH to USDC.
This address of the WETH and UniswapV2 router is for goerli.
My Code:-
interface IUniswapV2Router {
function swapExactETHForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
}
contract Test{
address UNISWAP_V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address WETH = 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6;
function ConvertEthToUSDC(address _tokenOut) public payable returns(bool) {
address[] memory path;
path = new address[](2);
path[1] = WETH;
path[2] = _tokenOut;
//Deadlimit 10 mins
//minAmount is 0
IUniswapV2Router(UNISWAP_V2_ROUTER).swapExactETHForTokens{value: msg.value}(0, path, msg.sender, block.timestamp + 600);
}
}
If I am not wrong there is some small thing I am missing using which I can get the conversion path.