# Class ConnectedProject

Abstraction for connecting @truffle/db to a Truffle project

This class affords an interface between Truffle and @truffle/db, specifically for the purposes of ingesting @truffle/workflow-compile results and contract instance information from @truffle/contract-schema artifact files.

Unless you are building tools that work with Truffle's various packages directly, you probably don't need to use this class.

#### Example

To instantiate this abstraction:

    import { connect, Project } from "@truffle/db";

    const db = connect({
      // ...
    });

    const project = await Project.initialize({
      db,
      project: {
        directory: "/path/to/project/dir"
      }
    });

#### Hierarchy

- Project.Project
  - ConnectedProject

- Defined in packages/db/src/project/index.ts:222

#####
Index

### Constructor

connect

### Truffle-specific

loadCompile
loadMigrate

### Other

id
assignNames
populateNetworks

### Processor

run

## Constructor

### connect

- connect(options): ConnectedProject

- Accept a provider to enable workflows that require communicating with the underlying blockchain network.

  #### Parameters

  - ##### options: {
    provider: Provider;
    }

    - ##### provider: Provider

  #### Returns ConnectedProject

  Inherited from Project.connect

  - Defined in packages/db/src/project/index.ts:163

## Truffle-specific

### loadCompile

- loadCompile(options): Promise<{
  compilations: Project.LoadCompile.Compilation[];
  contracts: Project.LoadCompile.Contract[];
  }>

- Accept a compilation result and process it to save all relevant resources ([[DataModel.Source | Source]], [[DataModel.Bytecode | Bytecode]], [[DataModel.Compilation | Compilation]], [[DataModel.Contract | Contract]])

  This returns the same WorkflowCompileResult but with additional references to each of the added resources.

  #### Parameters

  - ##### options: {
    result: WorkflowCompileResult;
    }

    - ##### result: WorkflowCompileResult

  #### Returns Promise<{
  compilations: Project.LoadCompile.Compilation[];
  contracts: Project.LoadCompile.Contract[];
  }>

  Inherited from Project.loadCompile

  - Defined in packages/db/src/project/index.ts:92

### loadMigrate

- loadMigrate(options): Promise<{
  artifacts: Project.LoadMigrate.Artifact[];
  network: Resources.IdObject<"networks">;
  }>

- Process artifacts after a migration. Uses provider to determine most relevant network information directly, but still requires project-specific information about the network (i.e., name)

  This adds potentially multiple [[DataModel.Network | Network]] resources to @truffle/db, creating individual networks for the historic blocks in which each [[DataModel.ContractInstance | ContractInstance]] was first created on-chain.

  This saves [[DataModel.Network | Network]] and [[DataModel.ContractInstance | ContractInstance]] resources to @truffle/db.

  Returns `artifacts` with network objects populated with IDs for each [[DataModel.ContractInstance | ContractInstance]], along with a `network` object containing the ID of whichever [[DataModel.Network | Network]] was added with the highest block height.

  #### Parameters

  - ##### options: {
    artifacts: (ContractObject & {
    db: {
    callBytecode: Resources.IdObject<"bytecodes">;
    contract: Resources.IdObject<"contracts">;
    createBytecode: Resources.IdObject<"bytecodes">;
    };
    })[];
    network: Pick<NetworkInput, "name">;
    }

    - ##### artifacts: (ContractObject & {
      db: {
      callBytecode: Resources.IdObject<"bytecodes">;
      contract: Resources.IdObject<"contracts">;
      createBytecode: Resources.IdObject<"bytecodes">;
      };
      })[]

    - ##### network: Pick<NetworkInput, "name">

  #### Returns Promise<{
  artifacts: Project.LoadMigrate.Artifact[];
  network: Resources.IdObject<"networks">;
  }>

  - Defined in packages/db/src/project/index.ts:243

## Other

### id

- get id(): string

- #### Returns string

  Inherited from Project.id

  - Defined in packages/db/src/project/index.ts:77

### assignNames

- assignNames<N>(options): Promise<{
  assignments: {
  [K in Resources.NamedCollectionName]: Resources.IdObject<"nameRecords">[]
  };
  }>

- Update name pointers for this project. Currently affords name-keeping for [[DataModel.Network | Network]] and [[DataModel.Contract | Contract]] resources (e.g., naming [[DataModel.ContractInstance | ContractInstance]] resources is not supported directly)

  This saves [[DataModel.NameRecord | NameRecord]] and [[DataModel.ProjectName | ProjectName]] resources to @truffle/db.

  Returns a list of NameRecord resources for completeness, although these may be regarded as an internal concern. ProjectName resources are not returned because they are mutable; returned representations would be impermanent.

  #### Type Parameters

  - #### N extends Resources.NamedCollectionName

    Either `"contracts"`, `"networks"`, or `"contracts" | "networks"`.

  #### Parameters

  - ##### options: {
    assignments: {
    [K in Resources.NamedCollectionName]: Resources.IdObject<K>[]
    };
    }

    - ##### assignments: {
      [K in Resources.NamedCollectionName]: Resources.IdObject<K>[]
      }

      Object whose keys belong to the set of named collection names and whose values are [[IdObject | IdObjects]] for resources of that collection.

  #### Returns Promise<{
  assignments: {
  [K in Resources.NamedCollectionName]: Resources.IdObject<"nameRecords">[]
  };
  }>

  #### Example

      await project.assignNames({
        assignments: {
          contracts: [
            { id: "<contract1-id>" },
            { id: "<contract2-id>" },
            // ...
          }
        }
      });

  Inherited from Project.assignNames

  - Defined in packages/db/src/project/index.ts:135

### `Private` populateNetworks

- populateNetworks<Artifact>(options): (Artifact & {
  networks?: {
  [networkId: string]: {
  db?: {
  network?: Resources.IdObject<"networks">;
  };
  };
  };
  })[]

- #### Type Parameters

  - #### Artifact extends ContractObject & {
    db: {
    callBytecode: Resources.IdObject<"bytecodes">;
    contract: Resources.IdObject<"contracts">;
    createBytecode: Resources.IdObject<"bytecodes">;
    };
    }

  #### Parameters

  - ##### options: {
    artifacts: Artifact[];
    knownLatest: Pick<DataModel.Network, "id" | "networkId">;
    networks: (undefined | Resources.IdObject<"networks">)[];
    }

    - ##### artifacts: Artifact[]

    - ##### knownLatest: Pick<DataModel.Network, "id" | "networkId">

    - ##### networks: (undefined | Resources.IdObject<"networks">)[]

  #### Returns (Artifact & {
  networks?: {
  [networkId: string]: {
  db?: {
  network?: Resources.IdObject<"networks">;
  };
  };
  };
  })[]

  - Defined in packages/db/src/project/index.ts:292

## Processor

### run

- run<A, T, R>(processor, ...args): Promise<T>

- Run a given [[Process.Processor | Processor]] with specified arguments.

  This method is a [[Meta.Process.ProcessorRunner | ProcessorRunner]] and can be used to `await` (e.g.) the processors defined by [[Process.resources | Process's `resources`]].

  #### Type Parameters

  - #### A extends unknown[]

  - #### T = any

  - #### R extends undefined | RequestType = undefined

  #### Parameters

  - ##### processor: Processor<A, T, R>

  - ##### `Rest` ...args: A

  #### Returns Promise<T>

  Inherited from Project.run

  - Defined in packages/db/src/project/index.ts:181

Generated using TypeDoc