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

Constructor

Truffle-specific

Other

Processor

Constructor

Truffle-specific

  • 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">;
      }

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

Other

  • 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

    Parameters

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

    Example

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

    Parameters

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

Processor

  • 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>

Generated using TypeDoc