Class: BlockGiven::Chain
- Inherits:
-
Struct
- Object
- Struct
- BlockGiven::Chain
- Defined in:
- lib/block_given/chain.rb
Overview
Static description of an EVM network, similar to viem/chains.
Instance Attribute Summary collapse
-
#alchemy_network ⇒ Object
Returns the value of attribute alchemy_network.
-
#block_explorer_url ⇒ Object
Returns the value of attribute block_explorer_url.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#native_currency ⇒ Object
Returns the value of attribute native_currency.
-
#network ⇒ Object
Returns the value of attribute network.
-
#rpc_urls ⇒ Object
Returns the value of attribute rpc_urls.
-
#testnet ⇒ Object
Returns the value of attribute testnet.
Instance Method Summary collapse
- #explorer_address_url(address) ⇒ Object
- #explorer_tx_url(hash) ⇒ Object
-
#initialize(id:, name:, network: nil, native_currency: nil, rpc_urls: [], block_explorer_url: nil, alchemy_network: nil, testnet: false) ⇒ Chain
constructor
A new instance of Chain.
- #inspect ⇒ Object
- #testnet? ⇒ Boolean
- #to_s ⇒ Object
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_network ⇒ Object
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_url ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id
5 6 7 |
# File 'lib/block_given/chain.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute 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
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
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
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
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
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})" |