Class: Coinbase::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/network.rb

Overview

A blockchain network.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(network_id:, display_name:, protocol_family:, is_testnet:, native_asset_id:, chain_id:) ⇒ Network

Returns a new Network object. Do not use this method directly. Instead, use the Network constants defined in the Coinbase module.

Parameters:

  • network_id (Symbol)

    The Network ID

  • display_name (String)

    The Network’s display name

  • protocol_family (String)

    The protocol family to which the Network belongs (e.g., “evm”)

  • is_testnet (Boolean)

    Whether the Network is a testnet

  • native_asset_id (String)

    The ID of the Network’s native Asset

  • chain_id (Integer)

    The Chain ID of the Network



17
18
19
20
21
22
23
24
# File 'lib/coinbase/network.rb', line 17

def initialize(network_id:, display_name:, protocol_family:, is_testnet:, native_asset_id:, chain_id:)
  @network_id = network_id
  @display_name = display_name
  @protocol_family = protocol_family
  @is_testnet = is_testnet
  @native_asset_id = native_asset_id
  @chain_id = chain_id
end

Instance Attribute Details

#chain_idObject (readonly)

Returns the value of attribute chain_id.



6
7
8
# File 'lib/coinbase/network.rb', line 6

def chain_id
  @chain_id
end

Instance Method Details

#get_asset(asset_id) ⇒ Asset

Gets the Asset with the given ID.

Parameters:

  • asset_id (Symbol)

    The ID of the Asset

Returns:

  • (Asset)

    The Asset with the given ID



30
31
32
# File 'lib/coinbase/network.rb', line 30

def get_asset(asset_id)
  Asset.fetch(@network_id, asset_id)
end

#native_assetAsset

Gets the native Asset of the Network.

Returns:

  • (Asset)

    The native Asset of the Network



37
38
39
# File 'lib/coinbase/network.rb', line 37

def native_asset
  @native_asset ||= get_asset(@native_asset_id)
end