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
MoralisData
EvmChainable
Table of contents
Accessors
- ARBITRUM
- AVALANCHE
- BSC
- BSC_TESTNET
- CRONOS
- CRONOS_TESTNET
- ETHEREUM
- FANTOM
- FUJI
- GOERLI
- MUMBAI
- PALM
- POLYGON
- SEPOLIA
- apiHex
- currency
- decimal
- explorer
- hex
- name
- rpcUrls
Methods
Accessors
ARBITRUM
• Static
get
ARBITRUM(): EvmChain
Returns ARBITRUM chain
Example
EvmChain.ARBITRUM
Returns
AVALANCHE
• Static
get
AVALANCHE(): EvmChain
Returns AVALANCHE chain
Example
EvmChain.AVALANCHE
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
CRONOS
• Static
get
CRONOS(): EvmChain
Returns CRONOS chain
Example
EvmChain.CRONOS
Returns
CRONOS_TESTNET
• Static
get
CRONOS_TESTNET(): EvmChain
Returns CRONOS_TESTNET chain
Example
EvmChain.CRONOS_TESTNET
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
FUJI
• Static
get
FUJI(): EvmChain
Returns FUJI chain
Example
EvmChain.FUJI
Returns
GOERLI
• Static
get
GOERLI(): EvmChain
Returns GOERLI chain
Example
EvmChain.GOERLI
Returns
MUMBAI
• Static
get
MUMBAI(): EvmChain
Returns MUMBAI chain
Example
EvmChain.MUMBAI
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
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"
| "0x19"
| "0x152"
| "0x2a15c308d"
| "0xa4B1"
Validate and cast to api compatible hex
Example
chain.apiHex // "0x1"
Returns
"0x1"
| "0x5"
| "0xaa36a7"
| "0x89"
| "0x13881"
| "0x38"
| "0x61"
| "0xa86a"
| "0xa869"
| "0xfa"
| "0x19"
| "0x152"
| "0x2a15c308d"
| "0xa4B1"
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
, 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
Name | Type |
---|---|
chain | EvmChainish |
core? | Core |
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
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
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
Name | Type | Description |
---|---|---|
_formatStyle? | EvmChainIdFormat | The output format to use |
Returns
string
| number
The formatted chain
Implementation of
MoralisData.format
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