Pair Addresses


The best way to get the address for a pair is to call get_pair on the Factory. If the pair exists, this function will return its address else 0
  • The "canonical" way to determine whether or not a pair exists.
  • Requires an on-chain lookup.


Python Example:
from starkware.starknet.core.os.contract_address.contract_address import calculate_contract_address_from_hash
from starkware.cairo.lang.vm.crypto import pedersen_hash
def get_create2_address(token0: int, token1: int, class_hash: int) -> int:
salt = pedersen_hash(token0, token1)
constructor_calldata = [token0,
create2_pair_address = calculate_contract_address_from_hash(
salt=salt, class_hash=class_hash, deployer_address=factory, constructor_calldata=constructor_calldata)
return create2_pair_address
  • token0 must be strictly less than token1 by sort order.
  • Can be computed offline.
  • Requires the ability to perform pedersen_hash.