Function createReactorCore

  • The Core module is the main entry point for the library. Create a new actor manager with the given options. Its create a new agent manager if not provided.

    Example


    import { createReactorCore } from "@ic-reactor/core"
    import { candid, canisterId, idlFactory } from "./declarations/candid"

    type Candid = typeof candid

    const { queryCall, updateCall, getPrincipal, login } =
    createReactorCore<Candid>({
    canisterId,
    idlFactory,
    withProcessEnv: true, // will use process.env.DFX_NETWORK
    })

    You can find All available methods are returned from the createReactorCore function here.

    // later in your code
    await login({
    onSuccess: () => {
    console.log("Logged in successfully")
    },
    onError: (error) => {
    console.error("Failed to login:", error)
    },
    })

    // queryCall, will automatically call and return a promise with the result
    const { dataPromise, call } = queryCall({
    functionName: "icrc1_balance_of",
    args: [{ owner: getPrincipal(), subaccount: [] }],
    })

    console.log(await dataPromise)

    // updateCall
    const { call, subscribe } = updateCall({
    functionName: "icrc1_transfer",
    args: [
    {
    to: { owner: getPrincipal(), subaccount: [] },
    amount: BigInt(10000000000),
    fee: [],
    memo: [],
    created_at_time: [],
    from_subaccount: [],
    },
    ],
    })
    // subscribe to the update call
    subscribe(({ loading, error, data }) => {
    console.log({ loading, error, data })
    })

    const result = await call()
    console.log(result)

    Type Parameters

    Returns types.CreateReactorCoreReturnType<A>