• Discover
  • Partner with us
  • Chapters
  • Blog

Build on Internet Computer with ICP Rust CDK

Course Introduction

Introduction
Overview of the IC ecosystem and core differences
Introduction to the Internet Computer (IC) ecosystem
Overview of the IC architecture and its components
Setting up the development environment for IC

Introduction
Creating Smart Contract
State Management 1
State Management 2
Update and Query Functions
Updating the Candid File
Testing the Contract

Creating Smart Contract for Final Project
Creating Functions 1
Creating Functions 2
Creating Functions 3
Creating Candid File
Testing and Deploying Smart Contract
Overview of the Frontend for Final Project
Explaining Frontend Code

Final Project

Creating Candid Files for Your Rust Smart Contract

In this video, we continue building our decentralized application by creating the Candid file (.did) for the smart contract we completed in lib.rs. This step ensures our front-end knows how to communicate with the back-end logic on the Internet Computer.

1. Purpose of the Candid File

The Candid file defines:

  • Types (structs and enums)
  • Function signatures (queries and updates)

These declarations bridge communication between the Rust-based backend and the Motoko or frontend code.

2. Defining Types

Proposal Type

type Proposal = record {
  description: text;
  approve: nat32;
  reject: nat32;
  pass: nat32;
  is_active: bool;
  voted: vec principal;
  owner: principal;
};

CreateProposal Type

type CreateProposal = record {
  description: text;
  is_active: bool;
};

Result and Error Handling

To mimic Rust’s Result type:

type Result = variant {
  ok: null;
  err: VoteError;
};

VoteError Enum

type VoteError = variant {
  AlreadyVoted;
  ProposalNotActive;
  NoSuchProposal;
  AccessRejected;
};

Choice Enum

type Choice = variant {
  Approve;
  Reject;
  Pass;
};

3. Declaring Service Functions

We then define the public functions that can be called from the frontend:

Query Functions

service : {
  get_proposal: (nat64) -> opt Proposal query;
  get_proposal_count: () -> nat64 query;

Update Functions

 create_proposal: (nat64, CreateProposal) -> opt Proposal;
  edit_proposal: (nat64, CreateProposal) -> Result;
  end_proposal: (nat64) -> Result;
  vote: (nat64, Choice) -> Result;
};

4. Key Notes on Candid Syntax

  • Use nat32, nat64 for Rust’s u32, u64.
  • Use text instead of string.
  • Define records for structs and variants for enums.
  • Types must be defined before being used in function signatures.

5. Conclusion

Your Candid file acts as the contract’s public interface. With the types and function signatures correctly defined, your frontend can now interact seamlessly with the backend. In the next video, we’ll move on to testing the smart contract.

Previous
Next

Lesson discussion

Swap insights and ask questions about “Build on Internet Computer with ICP Rust CDK”.

Enroll to participate
Start the course to unlock the discussion. Enrolling helps us keep conversations relevant to learners.
WebsiteDiscoverPartner with UsBlogEvents
Discover
CoursesCircleRustSoliditySolanaWeb3 FundamentalsBlockchain Basics
CompanyAbout UsBrand GuidelineFAQsTerms of UsePrivacy PolicyGDPR NoticeCookies
Don't miss any update!

Disclaimer: The information, programs, and events provided on https://risein.com is strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice, nor do we make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://risein.com disclaims any responsibility for financial decisions made by users based on the information provided here.

© 2026 Rise In, All rights reserved