35 releases (12 breaking)

new 0.17.1 Dec 19, 2024
0.17.0 Nov 5, 2024
0.16.0 Aug 27, 2024
0.15.0 Jul 1, 2024
0.1.1 Oct 4, 2020

#4 in #dfinity

Download history 21643/week @ 2024-08-29 21491/week @ 2024-09-05 19366/week @ 2024-09-12 16997/week @ 2024-09-19 22107/week @ 2024-09-26 20696/week @ 2024-10-03 23183/week @ 2024-10-10 25686/week @ 2024-10-17 25334/week @ 2024-10-24 25271/week @ 2024-10-31 22449/week @ 2024-11-07 27467/week @ 2024-11-14 32883/week @ 2024-11-21 32555/week @ 2024-11-28 31052/week @ 2024-12-05 25289/week @ 2024-12-12

127,102 downloads per month
Used in 141 crates (123 directly)

Apache-2.0

170KB
3K SLoC

Documentation Crates.io License Downloads CI

ic-cdk

Canister Developer Kit for the Internet Computer.

Background

On the Internet Computer, smart contracts come in the form of canisters which are WebAssembly modules.

Canisters expose entry points which can be called both by other canisters and by parties external to the IC.

This library aims to provide a Rust-ergonomic abstraction to implement Canister entry points.

Using ic-cdk

In Cargo.toml:

[lib]
crate-type = ["cdylib"]

[dependencies]
ic-cdk = "0.15"
candid = "0.10" # required if you want to define Candid data types

Then in Rust source code:

#[ic_cdk::query]
fn hello() -> String {
    "world".to_string()
}

This will register a query entry point named hello.

Macros

This library re-exports macros defined in ic-cdk-macros crate.

The macros fall into two categories:

  • To register functions as canister entry points
  • To export Candid definitions

Register functions as canister entry points

These macros are directly related to the Internet Computer Specification.

Export Candid definitions

Check Generating Candid files for Rust canisters for more details.

More examples

Manage Data Structure in Stable Memory

Using the ic_cdk::storage::{stable_save, stable_restore} API is easy but it doesn't scale well.

ic-stable-structures is recommended when you are dealing with multiple data structures with larger datasets.

Dependencies

~1–8MB
~72K SLoC