Skip to content

Defined in: reactor.ts:44

Reactor class for interacting with IC canisters.

This class provides core functionality for:

  • Direct agent calls using agent.call() and agent.query()
  • Query caching with TanStack Query integration
  • Method calls with result unwrapping

A = BaseActor

The actor service type

T extends TransformKey = "candid"

The type transformation to apply (default: candid = raw Candid types)

new Reactor<A, T>(config): Reactor<A, T>

Defined in: reactor.ts:54

ReactorParameters

Reactor<A, T>

readonly _actor: A

Defined in: reactor.ts:46

Phantom type brand for inference - never assigned at runtime


readonly transform: keyof TransformArgsRegistry<unknown> = "candid"

Defined in: reactor.ts:47


clientManager: ClientManager

Defined in: reactor.ts:48


name: string

Defined in: reactor.ts:49


canisterId: Principal

Defined in: reactor.ts:50


service: ServiceClass

Defined in: reactor.ts:51


pollingOptions: PollingOptions

Defined in: reactor.ts:52

get queryClient(): QueryClient

Defined in: reactor.ts:476

Get the query client from clientManager. This is the recommended way to access the query client for direct queries.

QueryClient


get agent(): HttpAgent

Defined in: reactor.ts:484

Get the agent from clientManager. This is the recommended way to access the agent for direct calls.

HttpAgent

setCanisterId(canisterId): void

Defined in: reactor.ts:105

Set the canister ID for this reactor. Useful for dynamically switching between canisters of the same type (e.g., multiple ICRC tokens).

CanisterId

The new canister ID (as string or Principal)

void

// Switch to a different ledger canister
ledgerReactor.setCanisterId("ryjl3-tyaaa-aaaaa-aaaba-cai")
// Then use queries/mutations as normal
const { data } = icrc1NameQuery.useQuery()

setCanisterName(name): void

Defined in: reactor.ts:126

Set the canister name for this reactor. Useful for dynamically switching between canisters of the same type (e.g., multiple ICRC tokens).

string

The new canister name

void

// Switch to a different ledger canister
ledgerReactor.setCanisterName("icrc1")
// Then use queries/mutations as normal
const { data } = icrc1NameQuery.useQuery()

getServiceInterface(): ServiceClass

Defined in: reactor.ts:139

Get the service interface (IDL.ServiceClass) for this reactor. Useful for introspection and codec generation.

ServiceClass

The service interface


isQueryMethod<M>(methodName): boolean

Defined in: reactor.ts:158

Check if a method is a query method (query or composite_query).

M extends string

M

boolean


generateQueryKey<M>(params, callConfig?): readonly unknown[]

Defined in: reactor.ts:200

M extends string

ReactorQueryParams<A, M, T>

CallConfig

readonly unknown[]


getQueryOptions<M>(params): FetchQueryOptions<ReactorReturnOk<A, M, T>>

Defined in: reactor.ts:233

M extends string

ReactorCallParams<A, M, T>

FetchQueryOptions<ReactorReturnOk<A, M, T>>


invalidateQueries<M>(params?, callConfig?): void

Defined in: reactor.ts:260

Invalidate cached queries for this canister. This will mark matching queries as stale and trigger a refetch for any active queries.

M extends string

Partial<ReactorQueryParams<A, M, T>>

Optional parameters to filter the invalidation

CallConfig

void

// Invalidate all queries for this canister
reactor.invalidateQueries()
// Invalidate only 'getUser' queries
reactor.invalidateQueries({ functionName: 'getUser' })
// Invalidate 'getUser' query for specific user
reactor.invalidateQueries({ functionName: 'getUser', args: ['user-1'] })

callMethod<M>(params): Promise<ReactorReturnOk<A, M, T>>

Defined in: reactor.ts:304

Call a canister method directly using agent.call() or agent.query(). This is the recommended approach for interacting with canisters.

M extends string

Omit<ReactorCallParams<A, M, T>, "queryKey">

Promise<ReactorReturnOk<A, M, T>>

// Query method
const result = await reactor.callMethod({
functionName: 'greet',
args: ['world'],
});
// Update method with options
const result = await reactor.callMethod({
functionName: 'transfer',
args: [{ to: principal, amount: 100n }],
callConfig: { effectiveCanisterId: principal },
});

fetchQuery<M>(params): Promise<ReactorReturnOk<A, M, T>>

Defined in: reactor.ts:377

Fetch data from the canister and cache it using React Query. This method ensures the data is in the cache and returns it.

M extends string

ReactorCallParams<A, M, T>

Promise<ReactorReturnOk<A, M, T>>


getQueryData<M>(params, callConfig?): ReactorReturnOk<A, M, T> | undefined

Defined in: reactor.ts:387

Get the current data from the cache without fetching.

M extends string

ReactorQueryParams<A, M, T>

CallConfig

ReactorReturnOk<A, M, T> | undefined


subnetId(): Promise<Principal>

Defined in: reactor.ts:456

Get the subnet ID for this canister.

Promise<Principal>


subnetState(options): Promise<ReadStateResponse>

Defined in: reactor.ts:463

Get the subnet state for this canister.

ReadStateOptions

Promise<ReadStateResponse>