IC-CDK
The Canister Development Kit (ic-cdk
or ic_cdk
) provides core functionality for interacting with the Internet Computer in Rust.
Juno exposes a growing set of these features for TypeScript, allowing you to build serverless functions that interact with the IC using a familiar developer experience.
These features are made available through a layer that acts as a proxy between the Rust-based IC-CDK and JavaScript.
The IC-CDK for JS/TS is provided by the @junobuild/functions library.
To add it to your project:
- npm
- yarn
- pnpm
npm i @junobuild/functions
yarn add @junobuild/functions
pnpm add @junobuild/functions
You have to follow the pace of the Juno release to ensure compatibility. Refer to the maintenance guide for instructions.
idβ
Retrieves the Principal ID of the current Satellite.
This is useful when you want to use functions such as setDocStore with the caller set as the administrator. Since the code is running on the backend side (inside the container), the Satellite itself is considered the caller and has admin-level permissions.
function id(): Principal;
π¦ Import from @junobuild/functions/ic-cdk
Returns:β
Principal
: The Principal ID of the currently executing Satellite.
Notes:β
- This function is a JavaScript binding for the Rust function ic_cdk::id().
callβ
Makes an asynchronous call to a canister on the Internet Computer.
Use this function inside your serverless functions to interact with other canisters. It encodes arguments using Candid, performs the call, and decodes the response based on the expected result type.
function call<T>(params: CallParams): Promise<T | undefined>;
π¦ Import from @junobuild/functions/ic-cdk
Parameters:β
params
: The parameters required to make the canister call.canisterId
: The target canister's ID.method
: The name of the method to call. Must be at least one character long.args
(optional): An array of tuples containing each argumentβs Candid type and its corresponding value.result
(optional): The expected result type used for decoding the response.
Returns:β
- A promise resolving to the decoded result of the call. If the canister returns no value,
undefined
is returned.
Notes:β
- This function is a JavaScript binding for the Rust function ic_cdk::call().
timeβ
Returns the current timestamp in nanoseconds since the Unix epoch.
This is useful when generating timestamps that match the Internet Computer's consensus state.
function time(): bigint;
π¦ Import from @junobuild/functions/ic-cdk
Returns:β
bigint
: The current timestamp in nanoseconds.
Notes:β
- This function is a JavaScript binding for the Rust function ic_cdk::time().