In this video, we walk through the process of creating a basic smart contract using Rust on the Internet Computer Protocol (ICP), introducing core concepts like canister setup, query vs. update functions, and how the frontend communicates with the backend through Candid.
Start by creating a new canister project with Rust as the backend:
dfx new example --type rust
cd example
This command sets up the initial project structure for a Rust-based canister. Once inside the project directory, open it using an IDE like Visual Studio Code for easier navigation and editing.
Within the project, you'll find the following:
Inside example_backend, another Cargo.toml is present because it represents a separate Rust project. The lib.rs file in the src directory is where we define our smart contract logic.
In lib.rs, a simple query function is defined using the ic_cdk dependency:
#[ic_cdk::query]
fn greet(name: String) -> String {
format!("Hello, {}!", name)
}
To enable frontend interaction, you use a Candid interface file. The .did file defines how external applications can communicate with the canister:
service : {
"greet": (text) -> (text) query;
}
In this lesson, we:
Swap insights and ask questions about “Build on Internet Computer with ICP Rust CDK”.
Ask a question or share your thoughts about this lesson.