module Eth::Chain

Overview

Encapsulates Eth::Chain IDs and utilities for EIP-155 compatibility.

Ref: https://eips.ethereum.org/EIPS/eip-155

Extended Modules

Defined in:

eth/chain.cr

Constant Summary

ARBITRUM = 42161

Chain ID for Arbitrum mainnet.

CLASSIC = 61

Chain ID for Ethereum Classic mainnet.

ETHEREUM = 1

Chain ID for Ethereum mainnet.

EXPANSE = 2

Chain ID for Expanse mainnet.

GNOSIS = 100

Chain ID for Gnosis mainnet.

GOERLI = 5

Chain ID for Goerli testnet.

GOERLI_ARBITRUM = 421613

Chain ID for Arbitrum Nitro Goerli testnet.

GOERLI_OPTIMISM = 420

Chain ID for Optimistic Goerli testnet.

HOLESOVICE = 11166111

Chain ID for Holesovice testnet.

KOTTI = 6

Chain ID for Kotti testnet.

KOVAN = 42

Chain ID for Kovan testnet.

KOVAN_OPTIMISM = 69

Chain ID for Optimistik Kovan testnet.

MORDEN = 2

Chain ID for Morden (Ethereum) testnet.

MORDEN_CLASSIC = 62

Chain ID for Morden (Classic) testnet.

MORDOR = 63

Chain ID for Mordor testnet.

MUMBAI = 80001

Chain ID for the Polygon Mumbai testnet.

OPTIMISM = 10

Chain ID for Optimistic Ethereum mainnet.

POA_NET = 99

Chain ID for POA Network mainnet.

POLYGON = 137

Chain ID for the Polygon Matic mainnet.

PRIVATE_GETH = 1337

Chain ID for the geth private network preset.

RINKEBY = 4

Chain ID for Rinkeby testnet.

RINKEBY_ARBITRUM = 421611

Chain ID for Arbitrum Rinkeby testnet.

ROPSTEN = 3

Chain ID for Ropsten testnet.

SEPOLIA = 11155111

Chain ID for Sepolia testnet.

XDAI_ARBITRUM = 200

Chain ID for Arbitrum xDAI testnet.

Instance Method Summary

Instance Method Detail

def ledger?(v : Int32) #

Checks if a provided v belongs to a Ledger wallet signature without EIP-155 replay protection.

Parameters:

  • v (Int32): the signature's v value.
Chain.ledger? 0
# => true

[View source]
def legacy?(v : Int32) #

Checks if a provided v belongs to a legacy signature without EIP-155 replay protection.

Parameters:

  • v (Int32): the signature's v value.
Chain.legacy? 27
# => true

[View source]
def to_chain_id(v : Int32) #

Converts a provided v value to an EIP-155 chain ID. This does not work for legacy signatures with v < 36 and return nil in that case.

Parameters:

  • v (Int32): the signature's v value.
Chain.to_chain_id 38
# => 1

[View source]
def to_recovery_id(v : Int32, chain_id : Int32 = ETHEREUM) #

Converts a provided v value to an ECDSA recovery ID for the given EIP-155 chain ID.

Parameters:

  • v (Int32): the signature's v value.
  • chain_id (Int32): the chain ID the signatrue was generated on (default: ETHEREUM).

Raises an exception if the v value does not match the chain ID.

Chain.to_recovery_id 38
# => 1

[View source]
def to_v(recovery_id : Int32, chain_id : Int32) #

Converts a provided recovery ID to the according v for signatures with EIP-155 replay protection.

Parameters:

  • recovery_id (Int32): the recovery ID.
  • chain_id (Int32): the chain ID the signatrue was generated on.
Chain.to_v(1, Chain::ETHEREUM)
# => 38

[View source]
def to_v(recovery_id : Int32) #

Converts a provided recovery ID to the according v for legacy signatures without EIP-155 replay protection.

Parameters:

  • recovery_id (Int32): the recovery ID.
Chain.to_v 1
# => 28

[View source]