Skip to main content

Smart Contract Data Types

When developing smart contracts on Massa, it is essential to understand the data types available in AssemblyScript, as they directly influence how you handle and manipulate data within the contract. AssemblyScript offers a range of data types that align closely with WebAssembly's capabilities, providing efficient and predictable performance.

AssemblyScript native types

Data TypeDescription
i8 / u88-bit signed/unsigned integers
i16 / u1616-bit signed/unsigned integers
i32 / u3232-bit signed/unsigned integers
i64 / u6464-bit signed/unsigned integers
f32 / f6432-bit and 64-bit floating-point numbers
boolRepresents a Boolean value (true or false)
stringRepresents UTF-16 encoded text

Array:

Array<T>: Represents a dynamically-sized collection of elements of type T. Arrays are suitable for storing lists of data, such as user addresses or transaction histories. You can define arrays with specific types, such as Array<i32> or Array<string>, to ensure data consistency.

Byte array:

Massa use AssemblyScript StaticArray<u8> native type to represent data bytes. This type is used internally in storage and is also used to serialize public function parameters and returned data.

Handling Large Numbers in Massa Smart Contracts

In some smart contracts, you may need to work with numbers that exceed the size limitations of standard 64-bit integers. For example, financial applications involving token balances or computations with very large numbers require higher precision and larger ranges that i64 or u64 can't provide. To handle such cases, Massa smart contracts can use the as-bignum library, which supports fixed length big number arithmetic.

Data TypeDescription
i128 / u128128-bit signed/unsigned integers
i256 / u256256-bit signed/unsigned integers

Example Import Statement

import { u256 } from "as-bignum/assembly"