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 type | WasmLib type | Mutable proxy | Immutable proxy |
---|---|---|---|
Bool | boolean | ScMutableBool | ScImmutableBool |
Bytes | byte array | ScMutableBytes | ScImmutableBytes |
Int8 | 8-bit signed | ScMutableInt8 | ScImmutableInt8 |
Int16 | 16-bit signed | ScMutableInt16 | ScImmutableInt16 |
Int32 | 32-bit signed | ScMutableInt32 | ScImmutableInt32 |
Int64 | 64-bit signed | ScMutableInt64 | ScImmutableInt64 |
String | UTF-8 string | ScMutableString | ScImmutableString |
Uint8 | 8-bit unsigned | ScMutableUint8 | ScImmutableUint8 |
Uint16 | 16-bit unsigned | ScMutableUint16 | ScImmutableUint16 |
Uint32 | 32-bit unsigned | ScMutableUint32 | ScImmutableUint32 |
Uint64 | 64-bit unsigned | ScMutableUint64 | ScImmutableUint64 |
Address | ScAddress | ScMutableAddress | ScImmutableAddress |
AgentId | ScAgentId | ScMutableAgentId | ScImmutableAgentId |
ChainId | ScChainId | ScMutableChainId | ScImmutableChainId |
Color | ScColor | ScMutableColor | ScImmutableColor |
Hname | ScHname | ScMutableHname | ScImmutableHname |
Hash | ScHash | ScMutableHash | ScImmutableHash |
Map | ScMap | ScMutableMap | ScImmutableMap |
RequestId | ScRequestId | ScMutableRequestId | ScImmutableRequestId |
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 type | Mutable array proxy | Immutable array proxy |
---|---|---|
Bool | ScMutableBoolArray | ScImmutableBoolArray |
Bytes | ScMutableBytesArray | ScImmutableBytesArray |
Int8 | ScMutableInt8Array | ScImmutableInt8Array |
Int16 | ScMutableInt16Array | ScImmutableInt16Array |
Int32 | ScMutableInt32Array | ScImmutableInt32Array |
Int64 | ScMutableInt64Array | ScImmutableInt64Array |
String | ScMutableStringArray | ScImmutableStringArray |
Uint8 | ScMutableUint8Array | ScImmutableUint8Array |
Uint16 | ScMutableUint16Array | ScImmutableUint16Array |
Uint32 | ScMutableUint32Array | ScImmutableUint32Array |
Uint64 | ScMutableUint64Array | ScImmutableUint64Array |
Address | ScMutableAddressArray | ScImmutableAddressArray |
AgentId | ScMutableAgentIdArray | ScImmutableAgentIdArray |
ChainId | ScMutableChainIdArray | ScImmutableChainIdArray |
Color | ScMutableColorArray | ScImmutableColorArray |
Hname | ScMutableHnameArray | ScImmutableHnameArray |
Hash | ScMutableHashArray | ScImmutableHashArray |
Map | ScMutableMapArray | ScImmutableMapArray |
RequestId | ScMutableRequestIdArray | ScImmutableRequestIdArray |
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.