-
Notifications
You must be signed in to change notification settings - Fork 18
Networks: Networks
The Networks namespace provides constants and functions for working with blockchain networks supported by the SDK.
The Networks namespace can be imported like so:
import { Networks } from "@synapseprotocol/sdk";
// or, for potentially better tree shaking:
import { Networks } from "@synapseprotocol/sdk/common";import { Networks, ChainId } from "@synapseprotocol/sdk";
import { BigNumberish } from "@ethersproject/bignumber";
// Print the name of a network respective to the passed chainId param.
function printNetworkNameFromChainId(chainId: number) {
const n: Networks.Network = Networks.fromChainId(chainId);
console.log(n.name);
}
printNetworkNameFromChainId(ChainId.POLYGON); // outputs "Polygon"
const nativeCurrency: string = Networks.AVALANCHE.chainCurrency;
console.log(`The native currency symbol for the Avalanche network is ${nativeCurrency}`); // nativeCurrency will output as "AVAX"The Network class defined in Networks is primarily used as a "data wrapper", in that each instance of a Network
is useful for retrieving information about the defined network, such as its name, nativee currency symbol, and Chain ID.
For 99.9% of use cases, SDK users should only ever need the provided, pre-defined Network instances.
A network contains the following read-only attributes:
-
name(string) - The primary or official name of the network, for example "Binance Smart Chain" -
chainCurrency(string) - The native currency symbol for this network. Examples: "BNB" on Binance Smart Chain, "AVAX" on Avalanche. -
chainId(number) - The network's Chain ID. For pre-definedNetworkinstances, this will use a constant defined in the ChainId namespace. -
tokens(Token[]) - An array containing Token instances for all tokens which the Synapse Protocol supports on this network. -
tokenAddresses(string[]) - An array of strings containing the actual, on-chain address of all entries intokens.
The Network class also provides the following functions:
-
supportsToken- Returns
trueif theTokenpassed to it is supported by the Synapse Protocol on the given network. - Params:
-
token: Token- A Token instance
-
- Returns:
boolean-
trueiftokenis supported for use on the network by the Synapse Protocol,falseotherwise
- Returns
-
zapIsL2BridgeZap- Returns
trueif the Synapse Bridge Zap contract for this network is aL2BridgeZap, rather than aNerveBridgeZap. Currently, Bridge Zaps for all networks except the Ethereum mainnet areL2BridgeZapcontracts.
- Returns
All of the below are Network instances, exported as constants from the Networks namespace. All of these networks
are supported and useable on the Synapse Protocol.
-
ETH- Constructor params:
name: "Ethereum Mainnet"chainId: ChainId.ETHchainCurrency: "ETH"
- Constructor params:
-
OPTIMISM- Constructor params:
name: "Optimism"chainId: ChainId.OPTIMISMchainCurrency: "ETH"
- Constructor params:
-
BSC- Constructor params:
name: "Binance Smart Chain"chainId: ChainId.BSCchainCurrency: "BNB"
- Constructor params:
-
POLYGON- Constructor params:
name: "Polygon"chainId: ChainId.POLYGONchainCurrency: "MATIC"
- Constructor params:
-
FANTOM- Constructor params:
name: "Fantom"chainId: ChainId.FANTOMchainCurrency: "FTM"
- Constructor params:
-
BOBA- Constructor params:
name: "Boba Network"chainId: ChainId.BOBAchainCurrency: "ETH"
- Constructor params:
-
MOONBEAM- Constructor params:
name: "Moonbeam"chainId: ChainId.MOONBEAMchainCurrency: "GLMR"
- Constructor params:
-
MOONRIVER- Constructor params:
name: "Moonriver"chainId: ChainId.MOONRIVERchainCurrency: "MOVR"
- Constructor params:
-
ARBITRUM- Constructor params:
name: "Arbitrum"chainId: ChainId.ARBITRUMchainCurrency: "ETH"
- Constructor params:
-
AVALANCHE- Constructor params:
name: "Avalanche C-Chain"chainId: ChainId.AVALANCHEchainCurrency: "AVAX"
- Constructor params:
-
AURORA- Constructor params:
name: "Aurora"chainId: ChainId.AURORAchainCurrency: "aETH"
- Constructor params:
-
HARMONY- Constructor params:
name: "Harmony"chainId: ChainId.HARMONYchainCurrency: "ONE"
- Constructor params:
-
networkName:- Returns the canonical name of the passed Chain ID, if supported by the SDK.
- Params:
chainId: number
- Returns:
-
string- Canonical name of the passed Chain, if supported.
-
-
fromChainId- Returns a
Networkinstance based on the passed Chain ID, if it corresponds to a network which is known and supported by the Synapse Protocol. - Params:
chainId: number
- Returns:
-
Network-
Networkinstance if it corresponds to a supported network, or null.
-
-
- Returns a
-
tokensForNetwork- Returns the array of
Tokens which are supported by the Synapse Protocol on a given network, based on the passed Chain ID. - Params:
chainId: number
- Returns:
-
Token[]- Array of Tokens supported for use on the network respective to
chainId(ifchainIdcorresponds to a supported network), or null.
- Array of Tokens supported for use on the network respective to
-
- Returns the array of
-
networkSupportsToken- Returns true if the passed token is supported by the Synapse Protocol on the passed network.
- Params:
-
network: Network | number- This param can be either a Network instance, or the Chain ID of a Synapse Protocol-supported network.
-
token: Token- A Token instance to check network support for.
-
- Returns:
-
boolean-
trueiftokenis supported by the Synapse Protocol onnetwork,falseotherwise.
-
-
-
supportedNetworks- Returns an array of
Networkinstances corresponding to all networks supported by the Synapse Protocol. - Returns:
-
Network[]- Array which contains the pre-defined
NetworkETH,OPTIMISM,CRONOS,BSC,POLYGON,FANTOM,BOBA,METIS,MOONBEAM,MOONRIVER,ARBITRUM,AVALANCHE,AURORA, andHARMONY.
- Array which contains the pre-defined
-
- Returns an array of