logo

Clarity reference - Part 2 / Data-Space Primitives

Data within a smart contract’s data-space is stored within maps.

maps associate a pair of two values (a, b) (also known as tuple) to another tuple. It works similar to a name-value pair.

To get or set a value in a map you use:

  1. (map-get map-name key-tuple) — This fetches the value associated with a given key in the map, or returns none if there is no such value.
  2. (map-set! map-name key-tuple value-tuple) — This will set the value of key-tuple in the data map
  3. (map-insert! map-name key-tuple value-tuple) — This will set the value of key-tuple in the data map if and only if an entry does not already exist.
  4. (map-delete! map-name key-tuple) — This will delete key-tuple from the data map.

A smart contract defines the data schema of a data map through define-map.

Primitive Types

Clarity is a strongly-typed language. Its type system has the following types:

Next: Clarity “Hello, World!” deployed on Stacks.