Skip to main content

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

Methods

Accessors

ARBITRUM

Static get ARBITRUM(): EvmChain

Returns ARBITRUM chain

Example

EvmChain.ARBITRUM

Returns

EvmChain


ARBITRUM_TESTNET

Static get ARBITRUM_TESTNET(): EvmChain

Returns ARBITRUM_TESTNET chain

Example

EvmChain.ARBITRUM_TESTNET

Returns

EvmChain


AVALANCHE

Static get AVALANCHE(): EvmChain

Returns AVALANCHE chain

Example

EvmChain.AVALANCHE

Returns

EvmChain


AVALANCHE_TESTNET

Static get AVALANCHE_TESTNET(): EvmChain

Returns AVALANCHE_TESTNET chain

Example

EvmChain.AVALANCHE_TESTNET

Returns

EvmChain


BASE

Static get BASE(): EvmChain

Returns BASE chain

Example

EvmChain.BASE

Returns

EvmChain


BASE_TESTNET

Static get BASE_TESTNET(): EvmChain

Returns BASE_TESTNET chain

Example

EvmChain.BASE_TESTNET

Returns

EvmChain


BSC

Static get BSC(): EvmChain

Returns BSC chain

Example

EvmChain.BSC

Returns

EvmChain


BSC_TESTNET

Static get BSC_TESTNET(): EvmChain

Returns BSC_TESTNET chain

Example

EvmChain.BSC_TESTNET

Returns

EvmChain


CHILIZ

Static get CHILIZ(): EvmChain

Returns CHILIZ chain

Example

EvmChain.CHILIZ

Returns

EvmChain


CHILIZ_TESTNET

Static get CHILIZ_TESTNET(): EvmChain

Returns CHILIZ_TESTNET chain

Example

EvmChain.CHILIZ_TESTNET

Returns

EvmChain


CRONOS

Static get CRONOS(): EvmChain

Returns CRONOS chain

Example

EvmChain.CRONOS

Returns

EvmChain


ETHEREUM

Static get ETHEREUM(): EvmChain

Returns ETHEREUM chain

Example

EvmChain.ETHEREUM

Returns

EvmChain


FANTOM

Static get FANTOM(): EvmChain

Returns FANTOM chain

Example

EvmChain.FANTOM

Returns

EvmChain


FANTOM_TESTNET

Static get FANTOM_TESTNET(): EvmChain

Returns FANTOM_TESTNET chain

Example

EvmChain.FANTOM_TESTNET

Returns

EvmChain


GNOSIS

Static get GNOSIS(): EvmChain

Returns GNOSIS chain

Example

EvmChain.GNOSIS

Returns

EvmChain


GNOSIS_TESTNET

Static get GNOSIS_TESTNET(): EvmChain

Returns GNOSIS_TESTNET chain

Example

EvmChain.GNOSIS_TESTNET

Returns

EvmChain


GOERLI

Static get GOERLI(): EvmChain

Returns GOERLI chain

Example

EvmChain.GOERLI

Returns

EvmChain


MUMBAI

Static get MUMBAI(): EvmChain

Returns MUMBAI chain

Example

EvmChain.MUMBAI

Returns

EvmChain


OPTIMISM

Static get OPTIMISM(): EvmChain

Returns OPTIMISM chain

Example

EvmChain.OPTIMISM

Returns

EvmChain


PALM

Static get PALM(): EvmChain

Returns PALM chain

Example

EvmChain.PALM

Returns

EvmChain


POLYGON

Static get POLYGON(): EvmChain

Returns POLYGON chain

Example

EvmChain.POLYGON

Returns

EvmChain


RONIN

Static get RONIN(): EvmChain

Returns RONIN chain

Example

EvmChain.RONIN

Returns

EvmChain


SEPOLIA

Static get SEPOLIA(): EvmChain

Returns SEPOLIA chain

Example

EvmChain.SEPOLIA

Returns

EvmChain


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"

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"

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

NameType
chainEvmChainish

Returns

EvmChain


equals

Static equals(chainA, chainB): boolean

Compares if 2 chains are equal, based on the chainId

Example

EvmChain.equals("1", "0x1")

Parameters

NameTypeDescription
chainAEvmChainishThe first chain to compare
chainBEvmChainishThe 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

NameTypeDescription
chainEvmChainishThe 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

NameTypeDescription
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.