37 releases (9 breaking)

0.14.0 May 17, 2024
0.13.2 Apr 8, 2024
0.13.1 Mar 1, 2024
0.12.0 Nov 23, 2023
0.1.1 Oct 4, 2020

#1436 in Magic Beans

Download history 15213/week @ 2024-02-27 15593/week @ 2024-03-05 12049/week @ 2024-03-12 14993/week @ 2024-03-19 13674/week @ 2024-03-26 14461/week @ 2024-04-02 14899/week @ 2024-04-09 22620/week @ 2024-04-16 23489/week @ 2024-04-23 14208/week @ 2024-04-30 13384/week @ 2024-05-07 15070/week @ 2024-05-14 14350/week @ 2024-05-21 17051/week @ 2024-05-28 18216/week @ 2024-06-04 12386/week @ 2024-06-11

64,247 downloads per month
Used in 117 crates (103 directly)

Apache-2.0

160KB
2.5K 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.12"
# Only necessary if you want to define Candid data types
candid = "0.10" 

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.2–2.1MB
~43K SLoC