Data Types
Scrypto is based on Rust which is a statically typed language. All variables are associated with a type, either explicitly specified or inferred by the compiler.
In this section, we describe how different data types are supported.
Primitive Types
Most primitive types are supported. You’re free to use any of the following types:
-
i8
,i16
,i32
,i64
,i128
,isize
-
u8
,u16
,u32
,u64
,u128
,usize
-
String
Floating points are not supported; you may consider using Decimal
data type instead.
|
Struct and Enums
Rust struct
and enum
are also supported, as long as the fields are of the supported types.
At this stage, no generics are supported for custom structs and enums.
To use enums in Scrypto, you have to make them derive TypeId
, Encode
, Decode
and Describe
from the sbor
package:
use sbor::*;
#[derive(TypeId, Encode, Decode, Describe)]
pub enum Color {
White,
Blue,
Black,
Red,
Green,
}
Container Types
In addition to basic types, the following container types are also supported:
-
Option<T>
: optional types -
[T; N]
: array types -
(T, U, P, L, E)
: tuple types -
Vec<T>
: dynamic-length vector type -
BTreeSet<T>
,BTreeMap<K, V>
: B-Tree set and map -
HashSet<T>
,HashMap<K, V>
: Hash set and map
Scrypto Types
Scrypto also introduces a few domain-specific types to enable asset-oriented programming.
Types related to components
Type | Description |
---|---|
|
Represents the system-wide address of a Package. |
|
Represents the system-wide address of a Component. |
|
Represents a lookup table and the data it contains. It uses key-value pairs to store and retrieve data. |
Types related to cryptograpy
Type | Description |
---|---|
|
Represents a 32-byte hash digest. Currently, the only supported hash algorithm is |
|
Represents an ECDSA public key. Currently, the only supported curve is |
|
Represents an ECDSA signature. Currently, the only supported curve is |
Types related to Math
Type | Description |
---|---|
|
Represents a signed, bounded fixed-point decimal, where the precision is |
Expect further math types in upcoming versions that will address safe math, and higher calculation precision. |
Types related to Resources
Type | Description |
---|---|
|
Represents a bucket of resources. Resources in Scrypto can only be moved using Buckets. |
|
Represents a proof of ownership of a resource. |
|
Represents a vault of resources. Resources in Scrypto can only be stored using Vaults. |
|
Represents an Id of an Non-Fungible Resource. |
|
Represents a system-wide address of a Non-Fungible Resource. |
|
Represents a system-wide address of a Resource. |
Scrypto Types Documentation
You can find more technical documentation about Scrypto types (including the bounds of Decimal
) in this doc.