Skip to content

Actor

Defined in: packages/core/src/agent/actor.ts:183

An actor base class. An actor is an object containing only functions that will return a promise. These functions are derived from the IDL definition.

protected new Actor(metadata): Actor

Defined in: packages/core/src/agent/actor.ts:350

ActorMetadata

Actor

static agentOf(actor): Agent | undefined

Defined in: packages/core/src/agent/actor.ts:189

Get the Agent class this Actor would call, or undefined if the Actor would use the default agent (global.ic.agent).

Actor

The actor to get the agent of.

Agent | undefined


static canisterIdOf(actor): Principal

Defined in: packages/core/src/agent/actor.ts:201

Actor

Principal


static createActor<T>(interfaceFactory, configuration): ActorSubclass<T>

Defined in: packages/core/src/agent/actor.ts:302

Creates an actor with the given interface factory and configuration.

The @icp-sdk/bindgen package can be used to generate the interface factory for your canister.

T = Record<string, ActorMethod<unknown[], unknown>>

InterfaceFactory

the interface factory for the actor, typically generated by the @icp-sdk/bindgen package

ActorConfig

the configuration for the actor

ActorSubclass<T>

an actor with the given interface factory and configuration

The Canister Environment Guide for more details on how to configure an actor using the canister environment.

Using the interface factory generated by the @icp-sdk/bindgen package:

import { Actor, HttpAgent } from '@icp-sdk/core/agent';
import { Principal } from '@icp-sdk/core/principal';
import { idlFactory } from './api/declarations/hello-world.did';
// For a convenient way to get the canister ID,
// see the https://js.icp.build/core/latest/canister-environment/ guide.
const canisterId = Principal.fromText('rrkah-fqaaa-aaaaa-aaaaq-cai');
const agent = await HttpAgent.create({
host: 'https://icp-api.io',
});
const actor = Actor.createActor(idlFactory, {
agent,
canisterId,
});
const response = await actor.greet('world');
console.log(response);

Using the createActor wrapper function generated by the @icp-sdk/bindgen package:

import { HttpAgent } from '@icp-sdk/core/agent';
import { Principal } from '@icp-sdk/core/principal';
import { createActor } from './api/hello-world';
// For a convenient way to get the canister ID,
// see the https://js.icp.build/core/latest/canister-environment/ guide.
const canisterId = Principal.fromText('rrkah-fqaaa-aaaaa-aaaaq-cai');
const agent = await HttpAgent.create({
host: 'https://icp-api.io',
});
const actor = createActor(canisterId, {
agent,
});
const response = await actor.greet('world');
console.log(response);

static createActorClass(interfaceFactory, options?): ActorConstructor

Defined in: packages/core/src/agent/actor.ts:205

InterfaceFactory

CreateActorClassOpts

ActorConstructor


static createActorWithExtendedDetails<T>(interfaceFactory, configuration, actorClassOptions?): ActorSubclass<ActorMethodMappedExtended<T>>

Defined in: packages/core/src/agent/actor.ts:335

Returns an actor with methods that return the http response details along with the result

T = Record<string, ActorMethod<unknown[], unknown>>

InterfaceFactory

the interface factory for the actor

ActorConfig

the configuration for the actor

CreateActorClassOpts = ...

options for the actor class extended details to return with the result

ActorSubclass<ActorMethodMappedExtended<T>>


static createActorWithHttpDetails<T>(interfaceFactory, configuration): ActorSubclass<ActorMethodMappedWithHttpDetails<T>>

Defined in: packages/core/src/agent/actor.ts:320

Returns an actor with methods that return the http response details along with the result

T = Record<string, ActorMethod<unknown[], unknown>>

InterfaceFactory

the interface factory for the actor

ActorConfig

the configuration for the actor

ActorSubclass<ActorMethodMappedWithHttpDetails<T>>

  • use createActor with actorClassOptions instead

static interfaceOf(actor): ServiceClass

Defined in: packages/core/src/agent/actor.ts:197

Get the interface of an actor, in the form of an instance of a Service.

Actor

The actor to get the interface of.

ServiceClass