Class: EvmChain

moralis-monorepo / @moralisweb3/evm-utils / EvmChain

Class: EvmChain

@moralisweb3/evm-utils.EvmChain

The EvmChain class is a MoralisData that references to a EVM chain

Implements

  • MoralisData
  • EvmChainable

Table of contents

Accessors

Methods

Accessors

ETHEREUM

Static get ETHEREUM(): EvmChain

Returns ETHEREUM chain

Example

EvmChain.ETHEREUM

Returns

EvmChain


ROPSTEN

Static get ROPSTEN(): EvmChain

Returns ROPSTEN chain

Example

EvmChain.ROPSTEN

Returns

EvmChain


RINKEBY

Static get RINKEBY(): EvmChain

Returns RINKEBY chain

Example

EvmChain.RINKEBY

Returns

EvmChain


GOERLI

Static get GOERLI(): EvmChain

Returns GOERLI chain

Example

EvmChain.GOERLI

Returns

EvmChain


KOVAN

Static get KOVAN(): EvmChain

Returns KOVAN chain

Example

EvmChain.KOVAN

Returns

EvmChain


POLYGON

Static get POLYGON(): EvmChain

Returns POLYGON chain

Example

EvmChain.POLYGON

Returns

EvmChain


MUMBAI

Static get MUMBAI(): EvmChain

Returns MUMBAI chain

Example

EvmChain.MUMBAI

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


AVALANCHE

Static get AVALANCHE(): EvmChain

Returns AVALANCHE chain

Example

EvmChain.AVALANCHE

Returns

EvmChain


FUJI

Static get FUJI(): EvmChain

Returns FUJI chain

Example

EvmChain.FUJI

Returns

EvmChain


FANTOM

Static get FANTOM(): EvmChain

Returns FANTOM chain

Example

EvmChain.FANTOM

Returns

EvmChain


CRONOS

Static get CRONOS(): EvmChain

Returns CRONOS chain

Example

EvmChain.CRONOS

Returns

EvmChain


CRONOS_TESTNET

Static get CRONOS_TESTNET(): EvmChain

Returns CRONOS_TESTNET chain

Example

EvmChain.CRONOS_TESTNET

Returns

EvmChain


decimal

get decimal(): number

Returns the decimal representation of the chain

Example

chain.decimal // 1

Returns

number

Implementation of

EvmChainable.decimal


hex

get hex(): string

Returns the hex-string representation of the chain

Example

chain.hex // "0x1"

Returns

string

Implementation of

EvmChainable.hex


apiHex

get apiHex(): "0x1" | "0x3" | "0x4" | "0x5" | "0x2a" | "0x89" | "0x13881" | "0x38" | "0x61" | "0xa86a" | "0xa869" | "0xfa" | "cronos" | "0x19"

Validate and cast to api compatible hex

Example

chain.apiHex // "0x1"

Returns

"0x1" | "0x3" | "0x4" | "0x5" | "0x2a" | "0x89" | "0x13881" | "0x38" | "0x61" | "0xa86a" | "0xa869" | "0xfa" | "cronos" | "0x19"

Implementation of

EvmChainable.apiHex


apiId

get apiId(): "1" | "3" | "4" | "5" | "25" | "42" | "56" | "97" | "137" | "250" | "338" | "1337" | "43113" | "43114" | "80001"

Validate and cast to api compatible id

Example

chain.apiId // 1

Returns

"1" | "3" | "4" | "5" | "25" | "42" | "56" | "97" | "137" | "250" | "338" | "1337" | "43113" | "43114" | "80001"


name

get name(): undefined | string

Returns the name of the chain

Example

chain.name // "Ethereum"

Returns

undefined | string


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


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[]


explorer

get explorer(): null | { name: string ; url: string ; standard: "EIP3091" | "none" ; icon?: string }

Returns the explorer Urls of the chain

Example

chain.explorerUrls // ["https://etherscan.io/"]

Returns

null | { name: string ; url: string ; standard: "EIP3091" | "none" ; icon?: string }

Methods

create

Static create(chain, core?): 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
core?MoralisCore

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


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

Implementation of

MoralisData.equals


format

format(_formatStyle?): string | number

Formats the chain to the given output; in decimal value or as hex-string.
The default formatting can be set in MoralisConfig

Example

chain.format() // 1

Example

chain.format('hex') // "0x1"

Example

chain.format('decimal') // 1

Parameters

NameTypeDescription
_formatStyle?EvmChainIdFormatThe output format to use

Returns

string | number

The formatted chain

Implementation of

MoralisData.format


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


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


Did this page help you?