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]. [Custom Types]: custom-types.mdx

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)

Unsigned 128-bit Integer (u128)

Signed 128-bit Integer (i128)

Bool (bool)

Symbol (Symbol)

Symbols are small efficient strings up to 32 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 resource 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.

Address (Address)

Address is a universal opaque identifier to use in contracts. It may represent a 'classic' Stellar account, a custom account implemented in Soroban or just an arbitrary contract.

Address can be used as a contract function input argument (for example, to identify the payment recipient), as a data key (for example, to store the balance), as the authentication & authorization source (for example, to authorize a token transfer) etc.

See authorization documentation for more details on how to use the Address type.