Best way to call a canister multiple times, Re-use agent/actor or Create new agent/actor?

Why not cache them for a season? what’s the point of recreating agent and actor?
I guess we should cache agent for sure, and the actor is just a proxy to use agent using specific interface!

I made a library, that will centralize the whole agent and actor management, for example if you login using agentManager it will update(recreate) all the actor that connected to that agent!

Your code will be look like this:

const agentManager = createAgentManager({
    identity,
})

const { callMethod } = createActorManager({
    agentManager,
    idlFactory,
    canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai",
})

const result = await callMethod("icrc2_approve", approveArg2)

It has strong type system, state management and so much more.

Please take a look at the Doc

1 Like