# Class Network

#### Hierarchy

- Network

- Defined in packages/db/src/network/index.ts:153

#####
Index

### Methods

includeBlocks
includeLatest
includeTransactions

### Resource accessors

genesis
knownLatest

## Methods

### includeBlocks

- includeBlocks<Block>(options): Promise<(undefined | Resources.IdObject<"networks">)[]>

- Load relevant resources into @truffle/db for a given set of blocks for the connected blockchain. Provide either height or height and hash for each block; this method will fetch hashes for block heights for any blocks provided without hash.

  This method queries @truffle/db for existing resources to build a sparse model of the relationships between blockchain networks. This mechanism identifies blockchain networks as [[DataModel.Network | Network]] resources and utilizes a system of [[DataModel.NetworkGenealogy | NetworkGenealogy]] resources to identify blocks as being ancestor or descendant to one another. This allows @truffle/db to maintain a continuous view of any particular blockchain while respecting that networks may hard-fork or re-organize in the future.

  To complete these linkages, this method alternately queries @truffle/db for candidate ancestors/descendants and fetches actual records from the connected blockchain itself until it finds an optimal match. This process operates in logarithmic time and logarithmic space based on the number of existing known blocks in the system and the number of blocks provided as input.

  Note: Despite optimizing for speed and memory usage, this process can nonetheless still perform a significant number of network requests and internal database reads. Although this system has been tested to perform satisfactorily against tens of thousands of blocks with multiple hardfork scenarios, this abstraction provides a few [[IncludeSettings]] to migitate unforeseen issues.

  This returns an [[IdObject]] for each [[DataModel.Network]] resource added in the process. Return values are ordered so that indexes of returned IDs correspond to indexes of provided blocks; any blocks that fail to load successfully will correspond to values of `null` or `undefined` in the resulting array.

  #### Type Parameters

  - #### Block extends Block | Omit<Block, "hash">

  #### Parameters

  - ##### options: {
    blocks: (undefined | Block)[];
    settings?: IncludeSettings;
    }

    - ##### blocks: (undefined | Block)[]

    - ##### `Optional` settings?: IncludeSettings

  #### Returns Promise<(undefined | Resources.IdObject<"networks">)[]>

  - Defined in packages/db/src/network/index.ts:278

### includeLatest

- includeLatest(options?): Promise<undefined | Resources.IdObject<"networks">>

- Fetch the latest block for the connected blockchain and load relevant resources into @truffle/db in order to link with existing records.

  See [[includeBlocks]] for more detail.

  #### Parameters

  - ##### options: {
    settings?: IncludeSettings;
    } = {}

    - ##### `Optional` settings?: IncludeSettings

  #### Returns Promise<undefined | Resources.IdObject<"networks">>

  - Defined in packages/db/src/network/index.ts:189

### includeTransactions

- includeTransactions(options): Promise<(undefined | Resources.IdObject<"networks">)[]>

- Fetch blocks for given transaction hashes for the connected blockchain and load relevant resources into @truffle/db in order to link with existing records.

  See [[includeBlocks]] for more detail.

  #### Parameters

  - ##### options: {
    settings?: IncludeSettings;
    transactionHashes: (undefined | string)[];
    }

    - ##### `Optional` settings?: IncludeSettings

    - ##### transactionHashes: (undefined | string)[]

  #### Returns Promise<(undefined | Resources.IdObject<"networks">)[]>

  - Defined in packages/db/src/network/index.ts:218

## Resource accessors

### genesis

- get genesis(): NetworkResource

- Network resource ([[DataModel.Network | Resources.Resource<"networks">]]) representing the genesis block for the connected blockchain.

  #### Returns NetworkResource

  - Defined in packages/db/src/network/index.ts:160

### knownLatest

- get knownLatest(): NetworkResource

- Network resource ([[DataModel.Network | Resources.Resource<"networks">]]) representing the latest known block for the connected blockchain.

  After [[initialize | `Network.initialize()`]], [[`includeLatest`]], [[`includeBlocks`]], and [[`includeTransactions`]], by default this value will be computed (or re-computed) based on inputs as well as queried records in @truffle/db already. Use `skipKnownLatest` option in [[IncludeSettings]] to update based only on existing known latest and additional inputs.

  #### Returns NetworkResource

  - Defined in packages/db/src/network/index.ts:177

Generated using TypeDoc