36 releases (8 breaking)

new 0.13.2 Apr 8, 2024
0.13.1 Mar 1, 2024
0.12.1 Jan 12, 2024
0.12.0 Nov 23, 2023
0.1.1 Oct 4, 2020

#1430 in Magic Beans

Download history 5133/week @ 2023-12-23 5546/week @ 2023-12-30 11499/week @ 2024-01-06 12934/week @ 2024-01-13 12332/week @ 2024-01-20 25054/week @ 2024-01-27 20221/week @ 2024-02-03 21129/week @ 2024-02-10 17758/week @ 2024-02-17 15268/week @ 2024-02-24 14812/week @ 2024-03-02 13319/week @ 2024-03-09 13979/week @ 2024-03-16 15707/week @ 2024-03-23 13296/week @ 2024-03-30 11892/week @ 2024-04-06

56,958 downloads per month
Used in 110 crates (96 directly)

Apache-2.0

155KB
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.9–2.7MB
~57K SLoC