ic-cdk

Crates.ioic-cdk
lib.rsic-cdk
version0.15.0
sourcesrc
created_at2020-10-02 18:24:01.329506
updated_at2024-07-01 17:17:00.993525
descriptionCanister Developer Kit for the Internet Computer.
homepagehttps://docs.rs/ic-cdk
repositoryhttps://github.com/dfinity/cdk-rs
max_upload_size
id295503
size151,411
Adam Spofford (adamspofford-dfinity)

documentation

https://docs.rs/ic-cdk

README

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"
# 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.

Commit count: 318

cargo fmt