Class: BlockGiven::Chain

Inherits:
Struct
  • Object
show all
Defined in:
lib/block_given/chain.rb

Overview

Static description of an EVM network, similar to viem/chains.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, network: nil, native_currency: nil, rpc_urls: [], block_explorer_url: nil, alchemy_network: nil, testnet: false) ⇒ Chain



9
10
11
12
13
14
15
16
17
# File 'lib/block_given/chain.rb', line 9

def initialize(id:, name:, network: nil, native_currency: nil, rpc_urls: [], block_explorer_url: nil,
               alchemy_network: nil, testnet: false)
  super(
    id: id, name: name, network: network || name.to_s.downcase.gsub(/[^a-z0-9]+/, "-"),
    native_currency: native_currency || { name: "Ether", symbol: "ETH", decimals: 18 },
    rpc_urls: Array(rpc_urls), block_explorer_url: block_explorer_url,
    alchemy_network: alchemy_network, testnet: testnet
  )
end

Instance Attribute Details

#alchemy_networkObject

Returns the value of attribute alchemy_network



5
6
7
# File 'lib/block_given/chain.rb', line 5

def alchemy_network
  @alchemy_network
end

#block_explorer_urlObject

Returns the value of attribute block_explorer_url



5
6
7
# File 'lib/block_given/chain.rb', line 5

def block_explorer_url
  @block_explorer_url
end

#idObject

Returns the value of attribute id



5
6
7
# File 'lib/block_given/chain.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name



5
6
7
# File 'lib/block_given/chain.rb', line 5

def name
  @name
end

#native_currencyObject

Returns the value of attribute native_currency



5
6
7
# File 'lib/block_given/chain.rb', line 5

def native_currency
  @native_currency
end

#networkObject

Returns the value of attribute network



5
6
7
# File 'lib/block_given/chain.rb', line 5

def network
  @network
end

#rpc_urlsObject

Returns the value of attribute rpc_urls



5
6
7
# File 'lib/block_given/chain.rb', line 5

def rpc_urls
  @rpc_urls
end

#testnetObject

Returns the value of attribute testnet



5
6
7
# File 'lib/block_given/chain.rb', line 5

def testnet
  @testnet
end

Instance Method Details

#explorer_address_url(address) ⇒ Object



25
26
27
# File 'lib/block_given/chain.rb', line 25

def explorer_address_url(address)
  block_explorer_url && "#{block_explorer_url}/address/#{address}"
end

#explorer_tx_url(hash) ⇒ Object



21
22
23
# File 'lib/block_given/chain.rb', line 21

def explorer_tx_url(hash)
  block_explorer_url && "#{block_explorer_url}/tx/#{hash}"
end

#inspectObject



30
# File 'lib/block_given/chain.rb', line 30

def inspect = "#<BlockGiven::Chain #{self}>"

#testnet?Boolean



19
# File 'lib/block_given/chain.rb', line 19

def testnet? = !!testnet

#to_sObject



29
# File 'lib/block_given/chain.rb', line 29

def to_s = "#{name} (#{id})"