Fetch contract address for uniswap v2 pairs
August 9th, 2023

You can run this in REMIX IDE to get deterministic value of contract used for uniswap v2 pair

pragma solidity ^0.8.17;

contract UniswapV2Helper {


function findPair() external returns (address){
    address factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
    address token0 = 0x2aC3c1d3e24b45c6C310534Bc2Dd84B5ed576335; // change me!
    address token1 = 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6; // change me!

    address pair = address(uint160(uint256(keccak256(abi.encodePacked(
        hex'ff',
        factory,
        keccak256(abi.encodePacked(token0, token1)),
        hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
    )))));

    return pair;
}

}


You just need to change token0 and token1 info. Bear in mind that ordering of token0 and token1 needs to be correct, meaning token0 needs to be smaller then token1 when using comparison “less then”.

Also you can go to ETHERSCAN link of the factory contract of UNI v2 like the one below on Goerli

and input pairs into getPair field and just get the contract output there. Ordering of them here doesn’t matter as code in contract will output proper value each time.

Subscribe to N00b21337
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from N00b21337

Skeleton

Skeleton

Skeleton