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

Returns a new instance of 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_network ⇒ Object

Returns the value of attribute alchemy_network

Returns:

  • (Object) —

    the current value of alchemy_network



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

def alchemy_network
  @alchemy_network
end

#block_explorer_url ⇒ Object

Returns the value of attribute block_explorer_url

Returns:

  • (Object) —

    the current value of block_explorer_url



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

def block_explorer_url
  @block_explorer_url
end

#id ⇒ Object

Returns the value of attribute id

Returns:

  • (Object) —

    the current value of id



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

def id
  @id
end

#name ⇒ Object

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



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

def name
  @name
end

#native_currency ⇒ Object

Returns the value of attribute native_currency

Returns:

  • (Object) —

    the current value of native_currency



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

def native_currency
  @native_currency
end

#network ⇒ Object

Returns the value of attribute network

Returns:

  • (Object) —

    the current value of network



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

def network
  @network
end

#rpc_urls ⇒ Object

Returns the value of attribute rpc_urls

Returns:

  • (Object) —

    the current value of rpc_urls



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

def rpc_urls
  @rpc_urls
end

#testnet ⇒ Object

Returns the value of attribute testnet

Returns:

  • (Object) —

    the current value of 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

#inspect ⇒ Object



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

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

#testnet? ⇒ Boolean

Returns:

  • (Boolean)


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

def testnet? = !!testnet

#to_s ⇒ Object



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

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