|
| 1 | +# IC-CDK |
| 2 | + |
| 3 | +import IcCdk from "../components/ic-cdk.md"; |
| 4 | + |
| 5 | +<IcCdk /> |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +These features are made available through a layer that acts as a proxy between the Rust-based IC-CDK and JavaScript. |
| 10 | + |
| 11 | +:::note[📦 Library] |
| 12 | + |
| 13 | +The IC-CDK for JS/TS is provided by the [@junobuild/functions](https://www.npmjs.com/package/@junobuild/functions) library. |
| 14 | + |
| 15 | +To add it to your project: |
| 16 | + |
| 17 | +import { Bash } from "../../../components/bash.mdx"; |
| 18 | + |
| 19 | +<Bash |
| 20 | + npm="npm i @junobuild/functions" |
| 21 | + yarn="yarn add @junobuild/functions" |
| 22 | + pnpm="pnpm add @junobuild/functions" |
| 23 | +/> |
| 24 | + |
| 25 | +You have to follow the pace of the Juno release to ensure compatibility. Refer to the [maintenance guide](../../../build/functions/development/typescript.mdx#maintenance) for instructions. |
| 26 | + |
| 27 | +::: |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## id |
| 32 | + |
| 33 | +Retrieves the Principal ID of the current Satellite. |
| 34 | + |
| 35 | +This is useful when you want to use functions such as [setDocStore](./sdk.mdx#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. |
| 36 | + |
| 37 | +```typescript |
| 38 | +function id(): Principal; |
| 39 | +``` |
| 40 | + |
| 41 | +📦 Import from `@junobuild/functions/ic-cdk` |
| 42 | + |
| 43 | +#### Returns: |
| 44 | + |
| 45 | +- `Principal`: The Principal ID of the currently executing Satellite. |
| 46 | + |
| 47 | +#### Notes: |
| 48 | + |
| 49 | +- This function is a JavaScript binding for the Rust function [ic_cdk::id()](https://docs.rs/ic-cdk/latest/ic_cdk/fn.id.html). |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## call |
| 54 | + |
| 55 | +Makes an asynchronous call to a canister on the Internet Computer. |
| 56 | + |
| 57 | +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. |
| 58 | + |
| 59 | +```typescript |
| 60 | +function call<T>(params: CallParams): Promise<T | undefined>; |
| 61 | +``` |
| 62 | + |
| 63 | +📦 Import from `@junobuild/functions/ic-cdk` |
| 64 | + |
| 65 | +#### Parameters: |
| 66 | + |
| 67 | +- `params`: The parameters required to make the canister call. |
| 68 | + - `canisterId`: The target canister's ID. |
| 69 | + - `method`: The name of the method to call. Must be at least one character long. |
| 70 | + - `args` (optional): An array of tuples containing each argument’s Candid type and its corresponding value. |
| 71 | + - `result` (optional): The expected result type used for decoding the response. |
| 72 | + |
| 73 | +#### Returns: |
| 74 | + |
| 75 | +- A promise resolving to the decoded result of the call. If the canister returns no value, `undefined` is returned. |
| 76 | + |
| 77 | +#### Notes: |
| 78 | + |
| 79 | +- This function is a JavaScript binding for the Rust function [ic_cdk::call()](https://docs.rs/ic-cdk/latest/ic_cdk/api/call/fn.call.html). |
0 commit comments