TokenPrice

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;
        }
    }
}

Tags:
addr:0xec144043e8a57da1fcc98038b700ed8b88d2fec8|verified:true|block:23654487|tx:0x6c98b570be9e83aa0bc3f3bf2d99fc834f81f791c5c6910b3b1b382ea21b0130|first_check:1761397605

Submitted on: 2025-10-25 15:06:46

Comments

Log in to comment.

No comments yet.