ChainId#

tradingstrategy.chain.ChainId Python class in Trading Strategy framework.

class ChainId[source]#

Bases: IntEnum

Chain ids and chain metadata helper.

This class is intended to present primary key for a blockchain in datasets, not its native chain id. This id may differ from what blockchain assumes its own id natively.

Chain id is an integer that defines the identity of a blockchain, all running on same or different EVM implementations. For non-EVM blockchains we have some special logic to handle them so we can present chain ids or all blockchains through this enum.

Chain id is a 32-bit integer.

For non-EVM chains like ones on Cosmos or Solana we use negative values, so that they are not confused with chain.network database. Cosmos natively uses string ids for chains instead of integers.

This class also provides various other metadata attributes besides ChainId.value, like ChainId.get_slug(). Some of this data is handcoded, some is pulled from chains submodule.

For the full chain id list see:

= `Cosmos chain registry <https://github.com/cosmos/chain-registry

__init__()#

Methods

get_name()

Get full human readab name for this blockchain

get_slug()

Get URL slug for this chain

get_homepage()

Get homepage link for this blockchain

get_svg_icon_link()

Get an absolute SVG image link to a chain icon, transparent background

get_explorer()

Get explorer landing page for this blockchain

get_address_link(address)

Get one address link.

get_tx_link(tx)

Get one tx link

get_by_slug(slug)

Map a slug back to the chain.

Attributes

ethereum

Ethereum mainnet chain id

bsc

Binance Smarrt Chain mainnet chain id

binance

Alias for Binance Smart Chain

polygon

Polygon chain id

avalanche

Avalanche C-chain id

arbitrum

Arbitrum One id

ethereum_classic

Ethereum Classic chain id.

ganache

Ganache test chain.

anvil

Anvil test chain.

unknown

Chain id not known

osmosis

Osmosis on Cosmos Does not have chain registry entry, beacuse Cosmos maintains its own registry

ethereum_tester

Python EVM test backend

data

Get chain data entry for this chain.

ethereum = 1#

Ethereum mainnet chain id

bsc = 56#

Binance Smarrt Chain mainnet chain id

binance = 56#

Alias for Binance Smart Chain

polygon = 137#

Polygon chain id

avalanche = 43114#

Avalanche C-chain id

arbitrum = 42161#

Arbitrum One id

ethereum_classic = 61#

Ethereum Classic chain id.

This is also the value used by EthereumTester in unit tests. https://github.com/ethereum/eth-tester

ganache = 1337#

Ganache test chain.

This is the chain id for Ganache local tester / mainnet forks.

anvil = 31337#

Anvil test chain.

Standalone Anvil chain launch.

See Foundry commit.

unknown = 0#

Chain id not known

osmosis = -100#

Osmosis on Cosmos Does not have chain registry entry, beacuse Cosmos maintains its own registry

ethereum_tester = 131277322940537#

Python EVM test backend

See https://github.com/ethereum/eth-tester/blob/84378ee7eb714633fbb3169378812ccfcbbd495a/eth_tester/backends/pyevm/main.py#L197

property data: dict#

Get chain data entry for this chain.

get_name()[source]#

Get full human readab name for this blockchain

Return type:

str

get_slug()[source]#

Get URL slug for this chain

Return type:

str

get_homepage()[source]#

Get homepage link for this blockchain

Return type:

str

Get an absolute SVG image link to a chain icon, transparent background

Return type:

str

get_explorer()[source]#

Get explorer landing page for this blockchain

Return type:

str

Get one address link.

Use EIP3091 format.

https://eips.ethereum.org/EIPS/eip-3091

Return type:

str

Get one tx link

Return type:

str

static get_by_slug(slug)[source]#

Map a slug back to the chain.

Most useful for resolving URLs.

Parameters:

slug (str) –

Return type:

Optional[ChainId]