Class: EvmChain
moralis-monorepo / @moralisweb3/common-evm-utils / EvmChain
Class: EvmChain
@moralisweb3/common-evm-utils.EvmChain
The EvmChain class is a MoralisData that references to a EVM chain
Implements
EvmChainable
Table of contents
Accessors
- ARBITRUM
- ARBITRUM_TESTNET
- AVALANCHE
- AVALANCHE_TESTNET
- BASE
- BASE_SEPOLIA
- BASE_TESTNET
- BSC
- BSC_TESTNET
- CHILIZ
- CHILIZ_TESTNET
- CRONOS
- ETHEREUM
- FANTOM
- FANTOM_TESTNET
- FLOW
- FLOW_TESTNET
- GNOSIS
- GNOSIS_TESTNET
- GOERLI
- HOLESKY
- LINEA
- LINEA_SEPOLIA
- MOONBASE
- MOONBEAM
- MOONRIVER
- MUMBAI
- OPTIMISM
- PALM
- POLYGON
- POLYGON_AMOY
- RONIN
- SEPOLIA
- apiHex
- currency
- decimal
- explorer
- hex
- name
- rpcUrls
Methods
Accessors
ARBITRUM
• Static
get
ARBITRUM(): EvmChain
Returns ARBITRUM chain
Example
EvmChain.ARBITRUM
Returns
ARBITRUM_TESTNET
• Static
get
ARBITRUM_TESTNET(): EvmChain
Returns ARBITRUM_TESTNET chain
Example
EvmChain.ARBITRUM_TESTNET
Returns
AVALANCHE
• Static
get
AVALANCHE(): EvmChain
Returns AVALANCHE chain
Example
EvmChain.AVALANCHE
Returns
AVALANCHE_TESTNET
• Static
get
AVALANCHE_TESTNET(): EvmChain
Returns AVALANCHE_TESTNET chain
Example
EvmChain.AVALANCHE_TESTNET
Returns
BASE
• Static
get
BASE(): EvmChain
Returns BASE chain
Example
EvmChain.BASE
Returns
BASE_SEPOLIA
• Static
get
BASE_SEPOLIA(): EvmChain
Returns BASE_SEPOLIA chain
Example
EvmChain.BASE_SEPOLIA
Returns
BASE_TESTNET
• Static
get
BASE_TESTNET(): EvmChain
Returns BASE_TESTNET chain
Example
EvmChain.BASE_TESTNET
Returns
BSC
• Static
get
BSC(): EvmChain
Returns BSC chain
Example
EvmChain.BSC
Returns
BSC_TESTNET
• Static
get
BSC_TESTNET(): EvmChain
Returns BSC_TESTNET chain
Example
EvmChain.BSC_TESTNET
Returns
CHILIZ
• Static
get
CHILIZ(): EvmChain
Returns CHILIZ chain
Example
EvmChain.CHILIZ
Returns
CHILIZ_TESTNET
• Static
get
CHILIZ_TESTNET(): EvmChain
Returns CHILIZ_TESTNET chain
Example
EvmChain.CHILIZ_TESTNET
Returns
CRONOS
• Static
get
CRONOS(): EvmChain
Returns CRONOS chain
Example
EvmChain.CRONOS
Returns
ETHEREUM
• Static
get
ETHEREUM(): EvmChain
Returns ETHEREUM chain
Example
EvmChain.ETHEREUM
Returns
FANTOM
• Static
get
FANTOM(): EvmChain
Returns FANTOM chain
Example
EvmChain.FANTOM
Returns
FANTOM_TESTNET
• Static
get
FANTOM_TESTNET(): EvmChain
Returns FANTOM_TESTNET chain
Example
EvmChain.FANTOM_TESTNET
Returns
FLOW
• Static
get
FLOW(): EvmChain
Returns FLOW mainnet chain
Example
EvmChain.FLOW
Returns
FLOW_TESTNET
• Static
get
FLOW_TESTNET(): EvmChain
Returns FLOW testnet chain
Example
EvmChain.FLOW_TESTNET
Returns
GNOSIS
• Static
get
GNOSIS(): EvmChain
Returns GNOSIS chain
Example
EvmChain.GNOSIS
Returns
GNOSIS_TESTNET
• Static
get
GNOSIS_TESTNET(): EvmChain
Returns GNOSIS_TESTNET chain
Example
EvmChain.GNOSIS_TESTNET
Returns
GOERLI
• Static
get
GOERLI(): EvmChain
Returns GOERLI chain
Example
EvmChain.GOERLI
Returns
HOLESKY
• Static
get
HOLESKY(): EvmChain
Returns HOLESKY chain
Example
EvmChain.HOLESKY
Returns
LINEA
• Static
get
LINEA(): EvmChain
Returns LINEA chain
Example
EvmChain.LINEA
Returns
LINEA_SEPOLIA
• Static
get
LINEA_SEPOLIA(): EvmChain
Returns LINEA SEPOLIA chain
Example
EvmChain.LINEA_SEPOLIA
Returns
MOONBASE
• Static
get
MOONBASE(): EvmChain
Returns MOONBASE chain
Example
EvmChain.MOONBASE
Returns
MOONBEAM
• Static
get
MOONBEAM(): EvmChain
Returns MOONBEAM chain
Example
EvmChain.MOONBEAM
Returns
MOONRIVER
• Static
get
MOONRIVER(): EvmChain
Returns MOONRIVER chain
Example
EvmChain.MOONRIVER
Returns
MUMBAI
• Static
get
MUMBAI(): EvmChain
Returns MUMBAI chain
Example
EvmChain.MUMBAI
Returns
OPTIMISM
• Static
get
OPTIMISM(): EvmChain
Returns OPTIMISM chain
Example
EvmChain.OPTIMISM
Returns
PALM
• Static
get
PALM(): EvmChain
Returns PALM chain
Example
EvmChain.PALM
Returns
POLYGON
• Static
get
POLYGON(): EvmChain
Returns POLYGON chain
Example
EvmChain.POLYGON
Returns
POLYGON_AMOY
• Static
get
POLYGON_AMOY(): EvmChain
Returns POLYGON_AMOY chain
Example
EvmChain.POLYGON_AMOY
Returns
RONIN
• Static
get
RONIN(): EvmChain
Returns RONIN chain
Example
EvmChain.RONIN
Returns
SEPOLIA
• Static
get
SEPOLIA(): EvmChain
Returns SEPOLIA chain
Example
EvmChain.SEPOLIA
Returns
apiHex
• get
apiHex(): "0x1"
| "0x5"
| "0xaa36a7"
| "0x89"
| "0x13881"
| "0x38"
| "0x61"
| "0xa86a"
| "0xa869"
| "0xfa"
| "0xfa2"
| "0x19"
| "0x152"
| "0x2a15c308d"
| "0xa4b1"
| "0x7e4"
| "0x66eed"
| "0xa"
| "0x15b38"
| "0x15b32"
| "0x64"
| "0x27d8"
| "0x2105"
| "0x14a33"
| "0x4268"
| "0x13882"
| "0xe708"
| "0x504"
| "0x505"
| "0x507"
| "0xe705"
| "0x2eb"
| "0x221"
Validate and cast to api compatible hex
Example
chain.apiHex // "0x1"
Returns
"0x1"
| "0x5"
| "0xaa36a7"
| "0x89"
| "0x13881"
| "0x38"
| "0x61"
| "0xa86a"
| "0xa869"
| "0xfa"
| "0xfa2"
| "0x19"
| "0x152"
| "0x2a15c308d"
| "0xa4b1"
| "0x7e4"
| "0x66eed"
| "0xa"
| "0x15b38"
| "0x15b32"
| "0x64"
| "0x27d8"
| "0x2105"
| "0x14a33"
| "0x4268"
| "0x13882"
| "0xe708"
| "0x504"
| "0x505"
| "0x507"
| "0xe705"
| "0x2eb"
| "0x221"
Implementation of
EvmChainable.apiHex
currency
• get
currency(): undefined
| EvmNativeCurrency
Returns the currency of the chain
Example
chain.currency // EvmNativeCurrency
Returns
undefined
| EvmNativeCurrency
The cuurrency of the chain or undefined if not found
decimal
• get
decimal(): number
Returns the decimal representation of the chain
Example
chain.decimal // 1
Returns
number
Implementation of
EvmChainable.decimal
explorer
• get
explorer(): null
| { icon?
: string
; name
: string
; standard
: "EIP3091"
| "none"
; url
: string
}
Returns the explorer Urls of the chain
Example
chain.explorerUrls // ["https://etherscan.io/"]
Returns
null
| { icon?
: string
; name
: string
; standard
: "EIP3091"
| "none"
; url
: string
}
hex
• get
hex(): string
Returns the hex-string representation of the chain
Example
chain.hex // "0x1"
Returns
string
Implementation of
EvmChainable.hex
name
• get
name(): undefined
| string
Returns the name of the chain
Example
chain.name // "Ethereum"
Returns
undefined
| string
rpcUrls
• get
rpcUrls(): undefined
| string
[]
Returns the rpc Urls of the chain
Example
chain.rpcUrls // ["https://mainnet.infura.io/v3/<infura-key>"]
Returns
undefined
| string
[]
Methods
create
▸ Static
create(chain
): EvmChain
Create a new instance of EvmChain from any valid address input.
Example
const chain = EvmChain.create(1)
const chain = EvmChain.create("0x3")
Parameters
Name | Type |
---|---|
chain | EvmChainish |
Returns
equals
▸ Static
equals(chainA
, chainB
): boolean
Compares if 2 chains are equal, based on the chainId
Example
EvmChain.equals("1", "0x1")
Parameters
Name | Type | Description |
---|---|---|
chainA | EvmChainish | The first chain to compare |
chainB | EvmChainish | The second chain to compare |
Returns
boolean
true if the chains are equal, false otherwise
values
▸ Static
values(): EvmChain
[]
Returns
EvmChain
[]
all the available chains
display
▸ display(): string
Displays the chain hex-string representation of the chain and also the chain name if not null
Example
chain.display() // "Ethereum (0x1)" | "0x1"
Returns
string
equals
▸ equals(chain
): boolean
Compares if the current chain is equal to the provided chain, based on the chainId
Example
chain.equals(EvmChain.ETHEREUM)
Parameters
Name | Type | Description |
---|---|---|
chain | EvmChainish | The chain to compare to |
Returns
boolean
true if the chains are equal, false otherwise
getExplorerPath
▸ getExplorerPath(value
): null
| string
This function returns the explorer url of a block, transaction, account or token.
Example
chain.getExplorerUrl({ block: 'block_here' }) // "https://etherscan.io/block/block_here"
Example
chain.getExplorerUrl({ transaction: 'some_transaction' }) // "https://etherscan.io/tx/some_transaction"
Example
chain.getExplorerUrl({ account: 'accoun_here' }) // "https://etherscan.io/address/accoun_here"
Example
chain.getExplorerUrl({ erc20: 'token_here' }) // "https://etherscan.io/token/token_here"
Parameters
Name | Type | Description |
---|---|---|
value | { block : string } | { transaction : string } | { account : string } | { erc20 : string } | An object containing the block , transaction , account or erc20 to get the explorer url for. |
Returns
null
| string
toJSON
▸ toJSON(): string
Returns the chain as a string.
Returns
string
The chain.