Skip to main content

Class: ContractFactory<T>

Contract factories are used to create Contracts that span multiple chains. Specifically, with a factory you can use:

  • deploy to deploy a Contract to its native target chain and automatically deploy its shims to the chains where this contract gets called.
  • deployShims to deploy only the shims of the contract on all the chains the contract is called.
  • deployWithShims to deploy the contract to its native target chain (given its already deployed shims). Together, deployShims and deployWithShims, make it possible to deploy shims before the native contract.
  • attach to attach to an already deployed contract. This is the same as getContract. We expose attach because the well-typed Cubist interface we generate at build time (with cubist build)---CubistORM---exports the project factories as properties on the object, eliding the need to use getContractFactory and getContract.

Example

Get factory and deploy contract and its shims with Cubist.

const StorageReceiver = cubist.getContractFactory('StorageReceiver');
const receiver = await StorageReceiver.deploy(33);

Example

Get factory and attach to existing deployed contract.

import { CubistORM, } from '../build/orm/index.js';
// ...
const StorageReceiver = cubist.StorageReceiver;
const receiver = StorageReceiver.attach();

Type parameters

NameType
Textends Contract

Exports

Properties

Methods

Properties

project

Readonly project: TargetProject

Underlying target project.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:402

Methods

attach

attach(addr): Promise<Contract<T>>

Get the already-deployed contract at particular address.

Parameters

NameTypeDescription
addrstringContract address.

Returns

Promise<Contract<T>>

The deployed contract.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:532


deploy

deploy(...args): Promise<Contract<T>>

Deploy contract and its shims. This function deploys the contract to its target chain, and the shims to their corresponding chains. We return a contract that encapsulates an inner ethers.js Contract and exposes some additional methods for interacting with the shims.

note

For now, you can only deploy a single instance of a contract. The next release of cubist will have support for multiple instances (Issue #580).

Parameters

NameTypeDescription
...argsany[]Arguments to call contract constructor with.

Returns

Promise<Contract<T>>

The deployed contract.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:441


deployShims

deployShims(): Promise<Map<Target, T>>

Deploy shims for this contract. In some cases you need to deploy the contract shims before the contract itself (see our TokenBridge for an example). This method is used to do deploy the shims, which you can then use when deploying the contract itself with deployWithShims.

Example

In our TokenBridge template (cubist new --template TokenBridge) we set up a two way bridge across two chains and need to deploy shims on one end to handle the circular dependency---the two contracts mutually depend on each other.

// deploy ERC20Bridged shims
const erc20bShims = await ERC20Bridged.deployShims();
// get the shim contract on the token sender chain
const erc20BridgedShim = erc20bShims.get(TokenSender.target());
// deploy the token sender contract and its shim
const tokenSender = await TokenSender.deploy(erc20BridgedShim.address);
// Deploy ERC20Bridged with the TokenSender address.
const erc20Bridged = await ERC20Bridged.deployWithShims(erc20bShims,

Returns

Promise<Map<Target, T>>

The deployed shims.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:511


deployWithShims

deployWithShims(shims, ...args): Promise<Contract<T>>

Deploy contract given the already-deployed shims. This function deploys the Contract to its native target chain. The first argument is the return value from the deployShims function. The rest of the arguments are the constructor arguments.

This function is useful for deploying cross-chain contracts that mutually depend on each other.

Parameters

NameTypeDescription
shimsMap<Target, T>the previously deployed shims.
...argsany[]Arguments to pass to call contract constructor with.

Returns

Promise<Contract<T>>

The deployed contract.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:464


deployed

deployed(): Promise<Contract<T>>

Get the already-deployed contract.

Returns

Promise<Contract<T>>

The deployed contract.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:524


target

target(): Target

Get (native) target chain.

Returns

Target

The target chain.

Defined in

submodules/cubist-node-sdk/src/cubist.ts:554