Skip to content

Commit 03825d7

Browse files
feat: start documenting ic-cdk references (#374)
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent d027d08 commit 03825d7

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The [Canister Development Kit](https://github.com/dfinity/cdk-rs) (`ic-cdk` or `ic_cdk`) provides core functionality for interacting with the Internet Computer in Rust.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# IC-CDK
2+
3+
import IcCdk from "../components/ic-cdk.md";
4+
5+
<IcCdk />
6+
7+
In the context of Juno, it enables your Satellite to perform low-level operations such as logging, accessing your Satellite identities, or communicating with other canisters — all essential when writing advanced serverless functions.
8+
9+
**All features** of the IC CDK are supported in Juno Satellites.
10+
11+
Because of this compatibility, we do not list them individually here and encourage you to consult the official documentation instead.
12+
13+
📦 See full documentation on [docs.rs/ic-cdk](https://docs.rs/ic-cdk/latest/ic_cdk/)
14+
15+
:::note
16+
17+
For compatibility, always use the `ic_cdk` version specified in Juno’s release notes. This ensures proper integration and avoids version mismatch issues.
18+
19+
:::
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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).

sidebars.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ const sidebars: SidebarsConfig = {
218218
},
219219
items: [
220220
"reference/functions/rust/sdk",
221-
"reference/functions/rust/utils"
221+
"reference/functions/rust/utils",
222+
"reference/functions/rust/ic-cdk"
222223
]
223224
},
224225
{
@@ -232,7 +233,8 @@ const sidebars: SidebarsConfig = {
232233
},
233234
items: [
234235
"reference/functions/typescript/sdk",
235-
"reference/functions/typescript/utils"
236+
"reference/functions/typescript/utils",
237+
"reference/functions/typescript/ic-cdk"
236238
]
237239
}
238240
]

0 commit comments

Comments
 (0)