Built-in Types
Sway is a statically typed language therefore every value must be known at compile time. This means that each value must have a type and the compiler can usually infer the type without the user being required to specify it.
Sway provides a number of out-of-the-box (primitive) types which can be used to construct more complex data structures and programs.
Primitive Types
Sway has the following primitive types:
- Numerics
u8
(8-bit unsigned integer)u16
(16-bit unsigned integer)u32
(32-bit unsigned integer)u64
(64-bit unsigned integer)u256
(256-bit unsigned integer)hexadecimal
,binary
&base-10
syntax
- Boolean
bool
(true or false)
- Strings
str
(string slice)str[n]
(fixed-length string of size n)
- Bytes
b256
(256 bits / 32 bytes, i.e. a hash)
- Slices
The default numeric type is u64
. The FuelVM's word size is 64 bits, and the cases where using a smaller numeric type to save space are minimal.
All other types in Sway are built up of these primitive types, or references to these primitive types.
Compound Types
Compound types are types that group multiple values into one type.
Sway has the following compound types: