Module: BlockGiven::Chains
- Defined in:
- lib/block_given/chain.rb
Constant Summary collapse
- MAINNET =
Chain.new( id: 1, name: "Ethereum", network: "mainnet", rpc_urls: ["https://eth.merkle.io"], block_explorer_url: "https://etherscan.io", alchemy_network: "eth-mainnet" )
- SEPOLIA =
Chain.new( id: 11_155_111, name: "Sepolia", network: "sepolia", rpc_urls: ["https://sepolia.drpc.org"], block_explorer_url: "https://sepolia.etherscan.io", alchemy_network: "eth-sepolia", testnet: true )
- BASE =
Chain.new( id: 8453, name: "Base", network: "base", rpc_urls: ["https://mainnet.base.org"], block_explorer_url: "https://basescan.org", alchemy_network: "base-mainnet" )
- BASE_SEPOLIA =
Chain.new( id: 84_532, name: "Base Sepolia", network: "base-sepolia", rpc_urls: ["https://sepolia.base.org"], block_explorer_url: "https://sepolia.basescan.org", alchemy_network: "base-sepolia", testnet: true )
- POLYGON =
Chain.new( id: 137, name: "Polygon", network: "polygon", native_currency: { name: "POL", symbol: "POL", decimals: 18 }, rpc_urls: ["https://polygon-rpc.com"], block_explorer_url: "https://polygonscan.com", alchemy_network: "polygon-mainnet" )
- POLYGON_AMOY =
Chain.new( id: 80_002, name: "Polygon Amoy", network: "polygon-amoy", native_currency: { name: "POL", symbol: "POL", decimals: 18 }, rpc_urls: ["https://rpc-amoy.polygon.technology"], block_explorer_url: "https://amoy.polygonscan.com", alchemy_network: "polygon-amoy", testnet: true )
- ARBITRUM =
Chain.new( id: 42_161, name: "Arbitrum One", network: "arbitrum", rpc_urls: ["https://arb1.arbitrum.io/rpc"], block_explorer_url: "https://arbiscan.io", alchemy_network: "arb-mainnet" )
- ARBITRUM_SEPOLIA =
Chain.new( id: 421_614, name: "Arbitrum Sepolia", network: "arbitrum-sepolia", rpc_urls: ["https://sepolia-rollup.arbitrum.io/rpc"], block_explorer_url: "https://sepolia.arbiscan.io", alchemy_network: "arb-sepolia", testnet: true )
- OPTIMISM =
Chain.new( id: 10, name: "OP Mainnet", network: "optimism", rpc_urls: ["https://mainnet.optimism.io"], block_explorer_url: "https://optimistic.etherscan.io", alchemy_network: "opt-mainnet" )
- OPTIMISM_SEPOLIA =
Chain.new( id: 11_155_420, name: "OP Sepolia", network: "optimism-sepolia", rpc_urls: ["https://sepolia.optimism.io"], block_explorer_url: "https://sepolia-optimism.etherscan.io", alchemy_network: "opt-sepolia", testnet: true )
- LOCALHOST =
Hardhat / Anvil / Ganache default chain, handy with a local fork.
Chain.new( id: 31_337, name: "Localhost", network: "localhost", rpc_urls: ["http://127.0.0.1:8545"], testnet: true )
- ALL =
[MAINNET, SEPOLIA, BASE, BASE_SEPOLIA, POLYGON, POLYGON_AMOY, ARBITRUM, ARBITRUM_SEPOLIA, OPTIMISM, OPTIMISM_SEPOLIA, LOCALHOST].freeze
Class Method Summary collapse
- .[](value) ⇒ Object
- .find_by_id(id) ⇒ Object
-
.resolve(value) ⇒ Object
Chains.resolve(:base) / Chains.resolve("base-sepolia") / Chains.resolve(8453) / Chains.resolve(chain).
Class Method Details
.[](value) ⇒ Object
110 |
# File 'lib/block_given/chain.rb', line 110 def [](value) = resolve(value) |
.find_by_id(id) ⇒ Object
109 |
# File 'lib/block_given/chain.rb', line 109 def find_by_id(id) = ALL.find { |c| c.id == id } |
.resolve(value) ⇒ Object
Chains.resolve(:base) / Chains.resolve("base-sepolia") / Chains.resolve(8453) / Chains.resolve(chain)
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/block_given/chain.rb', line 98 def resolve(value) case value when Chain then value when Integer then find_by_id(value) || raise(ConfigurationError, "unknown chain id #{value}") when Symbol, String key = value.to_s.downcase.tr("_", "-") ALL.find { |c| c.network == key } || raise(ConfigurationError, "unknown chain #{value.inspect}") else raise ConfigurationError, "cannot resolve chain from #{value.inspect}" end end |