Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Networks: ChainId

Bleaker edited this page Feb 22, 2022 · 5 revisions

The ChainId enum provides constants of Chain IDs for blockchains supported by the SDK.

All Chain IDs defined in this namespace are of the standard JS number type. This is to enable simple interoperability of these values between various codebases.

Import

ChainId can be imported like so:

import { ChainId } from "@synapseprotocol/sdk";

// or, for potentially better tree shaking:
import { ChainId } from "@synapseprotocol/sdk/common/chainid";

Example Usage

import { ChainId } from "@synapseprotocol/sdk";
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";

// Check a normal `number` argument against a known Chain ID.
function example(chainId: number) {
  if (chainId === ChainId.BSC) {
    console.log(`${chainId} is the Chain ID of the Binance Smart Chain!`);
  }
}

// Check a BigNumberish (which could be a whole host of types)
// against a known Chain ID.
function example2(chainId: BigNumberish) {
  let paramAsNum = BigNumber.from(chainId).toNumber();
  
  if (paramAsNum === ChainId.FANTOM) {
    console.log(`${paramAsNum} is the Chain ID of the Fantom network!`);
  }
}

Supported Chain IDs

All of the below are standard NodeJS numbers, exported as members of the ChainId enum. All of these Chain IDs are supported and useable on the Synapse Protocol.

  • ETH (Ethereum mainnet)

    • Value: 1
  • OPTIMISM (Optimism mainnet)

    • Value: 10
  • CRONOS (Cronos mainnet)

    • Value: 25
  • BSC (Binance Smart Chain mainnet)

    • Value: 56
  • POLYGON (Polygon Mainnet)

    • Value: 137
  • FANTOM (Fantom mainnet)

    • Value: 250
  • BOBA (Boba mainnet)

    • Value: 288
  • METIS (Metis Mainnet)

    • Value: 1088
  • MOONBEAM (Moonbeam mainnet)

    • Value: 1284
  • MOONRIVER (Moonriver mainnet)

    • Value: 1285
  • ARBITRUM (Arbitrum mainnet)

    • Value: 42161
  • AVALANCHE (Avalanche C-Chain mainnet)

    • Value: 43114
  • AURORA (Aurora mainnet)

    • Value: 1313161554
  • HARMONY (Harmony mainnet)

    • Value: 1666600000

Functions

  • supportedChainIds
    • Returns an array of numbers corresponding to the chain ids of all networks supported by the Synapse Protocol.
    • Returns:
      • number[]
        • Array which contains the pre-defined chain id enum members ETH, OPTIMISM, CRONOS, BSC, POLYGON, FANTOM, BOBA, METIS, MOONBEAM, MOONRIVER, ARBITRUM, AVALANCHE, AURORA, and HARMONY.