Quickswap Documentation
  • πŸ‰What is Quickswap?
  • Overview
    • ♻️Quickswap AMM
    • πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦Ecosystem Participants
    • ✨Key Features
    • πŸ”Swap
    • πŸ’¦Pools
    • πŸ‘¨β€πŸŒΎFarms
    • 🀝Bonds
    • βš–οΈPerps
    • 🐲Dragon's Lair
    • πŸ›οΈGovernance
    • πŸ—ΊοΈRoadmap
    • πŸ“²Social Media
    • πŸ“Contracts & Addresses
  • Tokens
    • πŸͺ™QUICK
    • πŸͺ™DD
  • Networks & Wallets
    • ⛓️Supported Chains
    • πŸ’³Supported Wallets
  • How To Guides
    • πŸ”How To Swap
      • ℹ️dLIMIT Guide
      • ℹ️dTWAP Guide
    • πŸ’§LP (Liquidity Providing)
    • πŸ‘©β€πŸŒΎFarm
    • πŸ₯©Stake
  • πŸ’»Technical Reference
    • πŸ‘©β€πŸ’»API
      • API Overview
      • Entities
      • Queries
    • πŸ“œSmart Contracts
      • 2️⃣V2
        • Factory
        • Pair
        • Pair (ERC-20)
        • Library
        • Router02
        • Router01
        • Common Errors
      • 3️⃣V3
        • Position Manager
        • Factory
        • Pool Deployer
        • Quoter
        • V3 Migrator
        • Farming Center
        • Limit Farming
        • Pool
        • Audits
    • ⌨️SDK
      • Getting Started
      • Token
      • Pair
      • Route
      • Trade
      • Fractions
      • Fetcher
      • Other Exports
    • ❔Guides
      • Interface Integration
        • Using the API
        • Query Parameters
        • Iframe Integration
      • Javascript SDK
        • SDK Quick start
        • Fetching Data
        • Pricing
        • Trading
        • Pair Addresses
      • Smart Contract Integration
        • Smart Contract Quick Start
        • Implement A Swap
        • Providing Liquidity
        • Building An Oracle
        • Flash Swaps
        • V2 Pair Addresses
        • Supporting Meta Transactions
        • V3 Pool Addresses
    • πŸ”ŽSubgraphs
    • ℹ️Glossary
    • πŸ“–Core Concepts
      • Swaps
      • Pools
      • Flash Swaps
      • Oracles
    • βš–οΈAdvanced Topics
      • Fees
      • Pricing
      • Understanding Returns
      • Security
      • Math
      • Research
Powered by GitBook
On this page
  • getPair
  • CREATE2
  • Examples
  1. Technical Reference
  2. Guides
  3. Javascript SDK

Pair Addresses

PreviousTradingNextSmart Contract Integration

getPair

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 address(0) (0x0000000000000000000000000000000000000000).

  • The "canonical" way to determine whether or not a pair exists.

  • Requires an on-chain lookup.

CREATE2

Thanks to some , we can also compute pair addresses without any on-chain lookups because of . The following values are required for this technique:

address

The factory address

salt

keccak256(abi.encodePacked(token0, token1))

keccak256(init_code)

0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f

  • token0 must be strictly less than token1 by sort order.

  • Can be computed offline.

  • Requires the ability to perform keccak256.

Examples

TypeScript

This example makes use of the Uniswap SDK. In reality, the SDK computes pair addresses behind the scenes, obviating the need to compute them manually like this.

import { FACTORY_ADDRESS, INIT_CODE_HASH } from '@uniswap/sdk'
import { pack, keccak256 } from '@ethersproject/solidity'
import { getCreate2Address } from '@ethersproject/address'

const token0 = '0xCAFE000000000000000000000000000000000000' // change me!
const token1 = '0xF00D000000000000000000000000000000000000' // change me!

const pair = getCreate2Address(
  FACTORY_ADDRESS,
  keccak256(['bytes'], [pack(['address', 'address'], [token0, token1])]),
  INIT_CODE_HASH
)
πŸ’»
❔
fancy footwork in the factory
CREATE2