-
Notifications
You must be signed in to change notification settings - Fork 88
/
actor.js
25 lines (21 loc) · 953 Bytes
/
actor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Actor, HttpAgent } from '@dfinity/agent';
// Imports and re-exports candid interface
import { idlFactory } from '../../src/declarations/whoami/whoami.did.js';
export { idlFactory } from '../../src/declarations/whoami/whoami.did.js';
// CANISTER_ID is replaced by webpack based on node environment
/**
*
* @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
* @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig}} [options]
* @return {import("@dfinity/agent").ActorSubclass<import("./whoami.did.js")._SERVICE>}
*/
export const createActor = (canisterId, options) => {
const agent = new HttpAgent({ ...options?.agentOptions });
agent.fetchRootKey();
// Creates an actor with using the candid interface and the HttpAgent
return Actor.createActor(idlFactory, {
agent,
canisterId,
...options?.actorOptions,
});
};