Kinds
A kind is a meta-object that acts as the type definition for other objects.
Descriptor
Kinds are themselves objects: they have their own kind and are minted from a set. The Kind of Kind and the Set of Kind are genesis objects created during protocol initialization.
A kind’s descriptor is initialized with the following values:
| Field | Value | Description |
|---|---|---|
flags | 0 | Reserved flags |
rev | 1 | Initially 1, increments as the kind itself evolves |
krev | latest | Revision of the Kind of Kind at creation (increments over time) |
srev | latest | Revision of the Set of Kind at creation (increments over time) |
kind | 2 | ID of the Kind of Kind |
set | 2 | ID of the Set of Kind |
Elements
Each kind has 7 elements, as defined in the Kind of Kind object's eltys field.
| Index | Element | Type | Mutable | Description |
|---|---|---|---|---|
0 | code | Matter | Yes | Matter Hash of the kind contract |
1 | data | Matter | Yes | Matter Hash of the kind data |
2 | eltys | Info | No | Declares the element types for objects of this kind |
3 | rels[0] | Info | Yes | Supported relations (part 1) |
4 | rels[1] | Info | Yes | Supported relations (part 2) |
5 | rels[2] | Info | Yes | Supported relations (part 3) |
6 | rels[3] | Info | Yes | Supported relations (part 4) |
We devote separate sections below to the code and data fields.
The eltys field defines the element types for objects of this kind. Each type is a uint8 (> 0). The field is stored as a packed uint8[], right-padded with zeros.
The rels[i] fields encode supported relations. Each is a packed uint64[] spread across 4 × bytes32, right-padded with zeros.
Kind Contract
The code field stores the matter hash of the kind contract compiled to Wasm.
Below is a simple example of a kind contract in AssemblyScript:
@kind
class Hat {
image: MatterImage;
bg: MatterImage;
function meta(): Json {
// ...
}
function picture(): Image {
// ...
}
}Kind contracts can be written currently in AssemblyScript and compiled to Wasm using the kasc CLI from kind-as.
A Rust toolkit is planned for future support.
Kind Data
The data field stores a matter hash referencing a piece of data associated with the kind.
This data is available to the kind’s own contract and may also be used by the kind contracts of objects that use this kind. We will explore more in later chapters.
Kind Registry
When a kind is registered in the Kind Registry, it is assigned a kind ID.
A kind is used by specifying its kind ID and kind revision in the object’s descriptor when the object is minted by the set contract.