Actor
Defined in: packages/agent/src/actor.ts:171
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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”
protectednew Actor(metadata):Actor
Defined in: packages/agent/src/actor.ts:338
Parameters
Section titled “Parameters”metadata
Section titled “metadata”ActorMetadata
Returns
Section titled “Returns”Actor
Methods
Section titled “Methods”agentOf()
Section titled “agentOf()”
staticagentOf(actor):undefined|Agent
Defined in: packages/agent/src/actor.ts:177
Get the Agent class this Actor would call, or undefined if the Actor would use the default agent (global.ic.agent).
Parameters
Section titled “Parameters”Actor
The actor to get the agent of.
Returns
Section titled “Returns”undefined | Agent
canisterIdOf()
Section titled “canisterIdOf()”
staticcanisterIdOf(actor):Principal
Defined in: packages/agent/src/actor.ts:189
Parameters
Section titled “Parameters”Actor
Returns
Section titled “Returns”createActor()
Section titled “createActor()”
staticcreateActor<T>(interfaceFactory,configuration):ActorSubclass<T>
Defined in: packages/agent/src/actor.ts:290
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.
Type Parameters
Section titled “Type Parameters”T = Record<string, ActorMethod<unknown[], unknown>>
Parameters
Section titled “Parameters”interfaceFactory
Section titled “interfaceFactory”the interface factory for the actor, typically generated by the @icp-sdk/bindgen package
configuration
Section titled “configuration”the configuration for the actor
Returns
Section titled “Returns”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.
Examples
Section titled “Examples”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);createActorClass()
Section titled “createActorClass()”
staticcreateActorClass(interfaceFactory,options?):ActorConstructor
Defined in: packages/agent/src/actor.ts:193
Parameters
Section titled “Parameters”interfaceFactory
Section titled “interfaceFactory”options?
Section titled “options?”Returns
Section titled “Returns”createActorWithExtendedDetails()
Section titled “createActorWithExtendedDetails()”
staticcreateActorWithExtendedDetails<T>(interfaceFactory,configuration,actorClassOptions):ActorSubclass<ActorMethodMappedExtended<T>>
Defined in: packages/agent/src/actor.ts:323
Returns an actor with methods that return the http response details along with the result
Type Parameters
Section titled “Type Parameters”T = Record<string, ActorMethod<unknown[], unknown>>
Parameters
Section titled “Parameters”interfaceFactory
Section titled “interfaceFactory”the interface factory for the actor
configuration
Section titled “configuration”the configuration for the actor
actorClassOptions
Section titled “actorClassOptions”CreateActorClassOpts = ...
options for the actor class extended details to return with the result
Returns
Section titled “Returns”ActorSubclass<ActorMethodMappedExtended<T>>
createActorWithHttpDetails()
Section titled “createActorWithHttpDetails()”
staticcreateActorWithHttpDetails<T>(interfaceFactory,configuration):ActorSubclass<ActorMethodMappedWithHttpDetails<T>>
Defined in: packages/agent/src/actor.ts:308
Returns an actor with methods that return the http response details along with the result
Type Parameters
Section titled “Type Parameters”T = Record<string, ActorMethod<unknown[], unknown>>
Parameters
Section titled “Parameters”interfaceFactory
Section titled “interfaceFactory”the interface factory for the actor
configuration
Section titled “configuration”the configuration for the actor
Returns
Section titled “Returns”ActorSubclass<ActorMethodMappedWithHttpDetails<T>>
Deprecated
Section titled “Deprecated”- use createActor with actorClassOptions instead
interfaceOf()
Section titled “interfaceOf()”
staticinterfaceOf(actor):ServiceClass
Defined in: packages/agent/src/actor.ts:185
Get the interface of an actor, in the form of an instance of a Service.
Parameters
Section titled “Parameters”Actor
The actor to get the interface of.