Skip to main content

Types

Custom-defined types allow teams to express their dApp in any form they require. A CIDL can define all the required types to fulfill the needs; other CIDLs can import these types.

tip

You can define any number of data structures and fields required for your use case.

caution

We cannot specify another custom type in a field’s type

Definition

types is a key-value object. Where the key of the object is the name of the type, and the value is an object through which we define the type structure.

types:
Gem:
summary: Gem are collected by players when they complete a dungeon
fields:
- name: name
type: string
attributes: [ sol:cap=36 ]
description: The name of the Gem
- name: quality
type: u8
description: A value between 1-100 that determines the quality of the Gem
KeywordTypeOptionalityDescription
typesMap<TypeKey, TypeBody>Optional

Type Key

Type name <type-name> must comply with the targeted programming language. The Type name is, the key to the type object map, is used to identify the data structure within the method definition. This identifier will also become the name for the smart contract data structure to be referenced within the code.

Type Body

The type body object defines additional keywords to describe the data structure

KeywordTypeOptionalityDescription
summarystringRecommendedDocumentation summary of the data structure. Supports markdown
fieldsArray<FieldBody>RequiredAn array of fields through which we can define the properties of the data structure. At least 1 field is required.
Field Body

The Field array field is required even if it has a single entry. Future reviews may include simple Type Definitions for single entry types

KeywordTypeOptionalityDescription
namestringRequiredThe name of the property, it must follows the targeted programming naming convention
typenative | extendedRequiredThe data type of this property
formatstringOptionalRepresents the internal format of the field. For example a String can represent a date, an email address or a url. Extended types can also be used to represent Blockchain Accounts, PublicKeys, etc.
attributesArray<string>OptionalAttributes to modify/extend the type
descriptionstringRecommendedDocumentation of the field. Supports markdown

Web-based documentation

The types object can be visualized in the CIDL web-based doc. The documentation is automatically generated from our vscode-codigo extension.

CIDL Web-based doc

Next steps

At this point we should have the basis of defining custom-types and the supported native and extended data types, read about native and extended data type here. If you have already read it, continue your learning path in the following links:

Join the Código community 💚

Código is a growing community of developers. Join us on Discord and GitHub