Skip to main content

WasmLib Data Types

You will need to manipulate data when creating smart contracts. The WasmLib provides direct support for the following value data types:

Basic Value Data Types

  • Bool - boolean value (0 or 1).
  • Int8 - 8-bit signed integer value.
  • Int16 - 16-bit signed integer value.
  • Int32 - 32-bit signed integer value.
  • Int64 - 64-bit signed integer value.
  • Bytes - An arbitrary-length byte array.
  • String - An UTF-8 encoded string value.
  • Uint8 - 8-bit unsigned integer value.
  • Uint16 - 16-bit unsigned integer value.
  • Uint32 - 32-bit unsigned integer value.
  • Uint64 - 64-bit unsigned integer value.

IOTA Smart Contracts-specific Value Data Types

  • Address - A 33-byte Tangle address.
  • AgentID - A 37-byte IOTA Smart Contracts Agent ID.
  • ChainID - A 33-byte IOTA Smart Contracts Chain ID.
  • Color - A 32-byte token color ID.
  • ContractID - A 37-byte IOTA Smart Contracts smart contract ID.
  • Hash - A 32-byte hash value.
  • Hname - A 4-byte unsigned integer hash value derived from a name string.
  • RequestID - A 34-byte transaction request ID.

The first group consists of the basic value data types that are found in all programming languages, whereas the second group consists of WasmLib versions of IOTA Smart Contracts-specific value data types. More detailed explanations about their specific uses can be found in the IOTA Smart Contracts documentation . WasmLib provides its own implementations for each of the IOTA Smart Contracts value data types. They can all be serialized into and deserialized from a byte array. Each value data type can also be used as a key in key/value maps.

WasmLib implements value proxies for each value type, as well as a set of container proxies, map proxies that allow the value types to be used as key and/or stored value and array proxies for arrays of each of these value types, and for arrays of maps.

Another thing to consider is that some data provided by the host is mutable, whereas other data may be immutable. To facilitate this distinction, each proxy type comes in two flavors that reflect this, and makes sure that the data can only be used as intended. The rule is that from an immutable container proxy you can only derive immutable container and value proxies. The referenced data can never be changed through immutable proxies. Separating these constraints for types into separate proxy types allows the use of compile-time type-checking to enforce these constraints. To guard against client code that tries to bypass them, the IOTA Smart Contracts sandbox will also check these constraints at runtime on the host.

Full Matrix of WasmLib Types (excluding array proxies)

ISCP typeWasmLib typeMutable proxyImmutable proxy
BoolbooleanScMutableBoolScImmutableBool
Bytesbyte arrayScMutableBytesScImmutableBytes
Int88-bit signedScMutableInt8ScImmutableInt8
Int1616-bit signedScMutableInt16ScImmutableInt16
Int3232-bit signedScMutableInt32ScImmutableInt32
Int6464-bit signedScMutableInt64ScImmutableInt64
StringUTF-8 stringScMutableStringScImmutableString
Uint88-bit unsignedScMutableUint8ScImmutableUint8
Uint1616-bit unsignedScMutableUint16ScImmutableUint16
Uint3232-bit unsignedScMutableUint32ScImmutableUint32
Uint6464-bit unsignedScMutableUint64ScImmutableUint64
AddressScAddressScMutableAddressScImmutableAddress
AgentIdScAgentIdScMutableAgentIdScImmutableAgentId
ChainIdScChainIdScMutableChainIdScImmutableChainId
ColorScColorScMutableColorScImmutableColor
HnameScHnameScMutableHnameScImmutableHname
HashScHashScMutableHashScImmutableHash
MapScMapScMutableMapScImmutableMap
RequestIdScRequestIdScMutableRequestIdScImmutableRequestId

The consistent naming makes it easy to remember the type names. Bool, Bytes, String, and the integer types are the odd ones out. They are implemented in WasmLib by the closest equivalents in the chosen implementation programming language.

Full Matrix of WasmLib Types for Array Proxies

ISCP typeMutable array proxyImmutable array proxy
BoolScMutableBoolArrayScImmutableBoolArray
BytesScMutableBytesArrayScImmutableBytesArray
Int8ScMutableInt8ArrayScImmutableInt8Array
Int16ScMutableInt16ArrayScImmutableInt16Array
Int32ScMutableInt32ArrayScImmutableInt32Array
Int64ScMutableInt64ArrayScImmutableInt64Array
StringScMutableStringArrayScImmutableStringArray
Uint8ScMutableUint8ArrayScImmutableUint8Array
Uint16ScMutableUint16ArrayScImmutableUint16Array
Uint32ScMutableUint32ArrayScImmutableUint32Array
Uint64ScMutableUint64ArrayScImmutableUint64Array
AddressScMutableAddressArrayScImmutableAddressArray
AgentIdScMutableAgentIdArrayScImmutableAgentIdArray
ChainIdScMutableChainIdArrayScImmutableChainIdArray
ColorScMutableColorArrayScImmutableColorArray
HnameScMutableHnameArrayScImmutableHnameArray
HashScMutableHashArrayScImmutableHashArray
MapScMutableMapArrayScImmutableMapArray
RequestIdScMutableRequestIdArrayScImmutableRequestIdArray

Again, consistency in naming makes them easy to remember.

In the next section we will show how the smart contract function call context is structured in WasmLib-compatible smart contract code.