--- layout: smart description: "Clarity: Language Reference" permalink: /:collection/:path.html --- # Clarity This file contains the reference for the Clarity language. * TOC {:toc} ## Supported types This section lists the types available to smart contracts. The only atomic types supported by the Clarity are booleans, integers, fixed length buffers, and principals. ### Int type The integer type in the Clarity language is a 16-byte signed integer, which allows it to specify the maximum amount of microstacks spendable in a single Stacks transfer. The special `BlockHeightInt` you can obtain with the `get-block-info` function. ### Uint type The unsigned integer type (`uint`) in the Clarity language is a 16-byte unsigned integer. Using the unsigned type can ensure that any value underflows (negative numbers) will cause a transaction to be aborted. Anywhere a developer wishes to use a literal unsigned integer (for example, incrementing or decrementing an input by a constant) the integer literal should use the `u` prefix, e.g., `u123`. ### Bool type Supports values of `true` or `false`. ### Buffer type Buffer types represent fixed-length byte buffers. A Buffer can either be constructed using: - String literals, for example `"alice.id"` or `hash160("bob.id")`, - Hexadecimals literals, for example `0xABCDEF`. All of the hash functions return buffers: `hash160` `sha256` `keccak256` The block properties `header-hash`, `burnchain-header-hash`, and `vrf-seed` are all buffers. ### List type Clarity supports lists of the atomic types. However, the only variable length lists in the language appear as function inputs. ### Principal type Clarity provides this primitive for checking whether or not the smart contract transaction was signed by a particular principal. Principals represent a spending entity and are roughly equivalent to a Stacks address. The principal's signature is not checked by the smart contract, but by the virtual machine. A smart contract function can use the globally defined `tx-sender` variable to obtain the current principal. Smart contracts may also be principals (represented by the smart contract's identifier). However, there is no private key associated with the smart contract, and it cannot broadcast a signed transaction on the blockchain. A smart contract uses the special variable `contract-name` to refer to its own principal. [//]: # You can use the `is-contract?` to determine whether a given principal corresponds to a smart contract. ### Tuple type To support the use of named fields in keys and values, Clarity allows the construction of named tuples using a function `(tuple ...)`, for example ```cl (define-constant imaginary-number-a (tuple (real 1) (i 2))) (define-constant imaginary-number-b (tuple (real 2) (i 3))) ``` This allows for creating named tuples on the fly, which is useful for data maps where the keys and values are themselves named tuples. Values in a given mapping are set or fetched using:
Function | Description |
---|---|
(map-get map-name key-tuple) |
Fetches the value associated with a given key in the map, or returns none if there is no such value. |
(map-set! map-name key-tuple value-tuple) |
Sets the value of key-tuple in the data map |
(map-insert! map-name key-tuple value-tuple) |
Sets the value of key-tuple in the data map if and only if an entry does not already exist. |
(map-delete! map-name key-tuple) |
Deletes key-tuple from the data map. |
{{keyword_vals[1] | lstrip | rstrip }}
{{keyword_vals[2]}}
**Example**
```cl
{{keyword_vals[3] | lstrip | rstrip }}
```
{{function_vals[2] | lstrip | rstrip }}
{{function_vals[3] | lstrip | rstrip }}
{{function_vals[4]}}
**Example**
```cl
{{function_vals[5] | lstrip | rstrip }}
```