Skip to main content

Class: Contract<T>

Multi-chain contract abstraction. Each Cubist contract encapsulates (for now) an ethers.js Contract) that runs on a native target chain and zero or more shim contracts running on other chains.

A contract deployed with ContractFactory is deployed to the chain specified in the cubist-config.json configuration file; this is the native target chain. If this contract is called on another chain, we also deploy a shim for this contract on that chain (either automatically when you use deploy or manually when you use deployShims).

This class exposes the contract on the native target chains (via inner), and several methods for getting the contract target chain, its address on the native target chain, and its shims' addresses on other chains.

Example

ERC20 bridged from Avalanche to Polygon and Ethereum has a native contract on Avalanche and corresponding shims on the other two chains.

// ...
const cubist = new Cubist();
// get contract
const e20Bridged = cubist.getContract('ERC20Bridged');
// print its address on native chain
console.log(`address on ${e20Bridged.target()}: ${e20Bridged.address()}`);
// print its shims' addresses
console.log(`address on Polygon: ${e20Bridged.addressOn(Target.Polygon)}`);
console.log(`address on Ethereum: ${e20Bridged.addressOn(Target.Ethereum)}`);

Type parameters

NameType
Textends Contract

Exports

Properties

Methods

Properties

fqn

Readonly fqn: ContractFQN

Fully qualified contract name.

Defined in

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


inner

Readonly inner: T

The underlying (for now ethers.js) native contract. This is ultimately the contract you will invoke methods on, listen for events on, etc.

Defined in

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


project

Readonly project: TargetProject

The single-chain target project corresponding to the target chain this contract was deployed to. In general you don't need to access the project itself.

Defined in

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

Methods

address

address(): string

Get contract address on the native target chain.

Returns

string

The contract address.

Defined in

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


addressOn

addressOn(target): string

Get contract address of this contract on a particular target chain.

Parameters

NameTypeDescription
targetTargetThe target chain.

Returns

string

The contract address.

Defined in

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


target

target(): Target

Returns

Target

  • The target chain the contract was deployed to.

Defined in

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


whenBridged

whenBridged(retries?, delayMs?): Promise<boolean>

Returns a promise that completes once the bridge between this contract and its shims has been established. In general, you don't need to call this yourself; the top-level whenBridged does this for all contracts.

Parameters

NameTypeDefault valueDescription
retriesnumber100how many times to check if the bridge has been established.
delayMsnumber100delay in milliseconds between retries.

Returns

Promise<boolean>

  • whether a bridge has been established within the given time parameters.

Defined in

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