Skip to main content

Built-in Types

Built-in types are available to all contracts for use as contract function inputs and outputs, and are defined by the environment and the Rust SDK.

tip

Custom types like structs, enums, and unions are also supported. See Custom Types.

Primitive Types

The following primitive types are supported:

Unsigned 32-bit Integer (u32)

Signed 32-bit Integer (i32)

Unsigned 64-bit Integer (u64)

Signed 64-bit Integer (i64)

Bool (bool)

Symbol (Symbol)

Symbols are small efficient strings up to 10 characters in length and limited to a-z A-Z 0-9 _ that are encoded into 64-bit integers.

Symbols are primarily used for function names and other identifiers that are exported in the public API of a contract. They can also be used wherever short strings are needed to keep gas costs down.

Bytes, Strings (Bytes, BytesN)

Byte arrays and strings can be passed to contracts and stores using the Bytes type.

For byte arrays of fixed length, BytesN can be used. For example, contract IDs are fixed 32-byte byte arrays, and are represented as BytesN<32>.

Vec (Vec)

Vec is a sequential and indexable growable collection type.

Values are stored in the environment and are available to contract through the functions defined on Vec. Values stored in the Vec are transmitted to the environment as RawVals, and when retrieved from the Vec are transmitted back and converted from RawVal back into their type.

The values in a Vec are not guaranteed to be of any specific type and conversion will fail if they are not of the expected type. Most functions on Vec return a Result due to this.

Map (Map)

Map is a ordered key-value dictionary.

The map is ordered by its keys. Iterating a map is stable and always returns the keys and values in order of the keys.

The map is stored in the Host and available to the Guest through the functions defined on Map. Values stored in the Map are transmitted to the Host as RawVals, and when retrieved from the Map are transmitted back and converted from RawVal back into their type.

The keys and values in a Map are not guaranteed to be of type K/V and conversion will fail if they are not. Most functions on Map return a Result due to this.

Maps have at most one entry per key. Setting a value for a key in the map that already has a value for that key replaces the value.

BigInt (BigInt)

BigInt is an arbitrary sized signed integer.

The value is stored in the Host and available to the Guest through functions on the type. Operations between BigInts are performed inside the Host and do not consume Guest resources such as memory.

Address (Address)

Address is union of all the types that can be the invoker of a contract.

Address may be an account ID (AccountId) or a contract ID (BytesN<32>).

The Address type is implemented like an enum custom type and is stored as a two element Vec.

Account ID (AccountId)

Account ID is an identifier for an account.

Most of the time contracts should use the Address type, which is a

In contracts the ID is opaque and does not expose the identifier to the contract, but the value can be used as a key in maps, or compared with other account identifiers.