Description:
Smart contract deployed on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
interface IUniswapV2Router02 {
function getAmountsOut(uint amountIn, address[] calldata path)
external view returns (uint[] memory amounts);
}
contract TokenPrice {
address public constant UNISWAP_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
function getExpectedETH(address token, uint256 amount) external view returns (uint256) {
if (token == WETH) return amount;
address[] memory path = new address[](2);
path[0] = token;
path[1] = WETH;
try IUniswapV2Router02(UNISWAP_ROUTER).getAmountsOut(amount, path) returns (uint[] memory amounts) {
return amounts[1];
} catch {
return 0;
}
}
}
Submitted on: 2025-10-25 15:06:46
Comments
Log in to comment.
No comments yet.