The most obvious way to get the address for a pair is to call getPair on the factory. If the pair exists, this function will return its address, else
- The "canonical" way to determine whether or not a pair exists.
- Requires an on-chain lookup.
Thanks to some fancy footwork in the factory, we can also compute pair addresses without any on-chain lookups because of CREATE2. The following values are required for this technique:
|The factory address|
token0must be strictly less than
token1by sort order.
- Can be computed offline.
- Requires the ability to perform
address factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
address token0 = 0xCAFE000000000000000000000000000000000000; // change me!
address token1 = 0xF00D000000000000000000000000000000000000; // change me!
address pair = address(uint(keccak256(abi.encodePacked(