Developer Resources
What is Candid?
This guide explains what Candid is and shows you how to utilize it for developing Internet Computer dApps
Introduction to Candid
Candid’s purpose and key features
In the context of the Internet Computer, Candid describes the public interface of a program running as a deployed canister smart contract. Candid enables the inter-operation between front-ends and services that are written in different programming languages, such as Motoko, Rust, and JavaScript.
Typical Interface Description in Candid
Let’s have a look how a typical description of what an interface might look like in Candid:
The example above illustrates how every method of the interface description consists of a sequence of arguments as well as result types. Annotations that are specific to the IC can also be included in a method, such as the query
notation. The service counter
described above consists of these public methods:
add
andsubtract
methods for changing the counter’s valueget
method for reading the counter’s current valuesubscribe
method for invoking another function such as a notification callback method
Candid’s Features
The Candid interface description language provides developers unique features that other technologies such as JSON, Protobuf, or XML are not able to offer. These features include the following:
- Candid describes the services as a whole instead of only mapping individual values to bytes/characters
- The focus lies on the methods that use the data types instead of focusing on the data types
- The Candid value is mapped directly to the host language’s types and values
- Candid allows developers to avoid having to construct or deconstruct abstract
Candid
values - Rules are defined on upgrading services and interfaces in a compositional way
- Candid is a higher-order language, i.e. more than plain data can be passed
- Built-in support for features specific to the Internet Computer, such as
query
annotations
Candid Types and Values
As a strongly typed system, Candid offers developers a typeset that canonically covers most use cases:
- Unbounded integral number (
nat
,int
) Bounded integral number types (
nat8
,nat16
,nat32
,nat64
,int8
,int16
,int32
,int64
).- Boolean type (
bool
). - Floating point types (
float32
,float64
). - Container types, which include variants (
opt
,vec
,record
,variant
). - Types for binary (
blob
) and textual (text
) data. Reference types (such as
service
,func
, andprincipal
).- Special types, such as
null
,reserved
andempty
.
For a detailed description of all types, have a look at the Internet Computer’s Reference section.
The aforementioned set of type is designed to describe the structure of the data, allowing information to be encoded, passed around, and decoded. However, semantic constraints are intentionally not described – beyond what’s required to describe the representation.