Standard Library
The Ursus Standard Library provides essential types, functions, and operators for smart contract development. It includes primitives, data structures, and platform-specific functionality.
Overview
The standard library is organized into several modules:
- Primitives - Basic types (integers, booleans, addresses, strings)
- Functions - Standard functions (math, crypto, conversions)
- Operators - Arithmetic, logical, bitwise, comparison operators
- TVM Functions - TON Virtual Machine specific functions
Library Structure
ursus-standard-library/
├── src/
│ ├── Solidity/ # Solidity-compatible library
│ ├── Rust/ # Rust-compatible library
│ └── _Cpp/ # C++ (TON) compatible library
Each target language has its own standard library variant with platform-specific implementations.
Importing the Standard Library
Basic Import
Require Import UrsusEnvironment.Solidity.current.Environment.
Require Import UrsusEnvironment.Solidity.current.LocalGenerator.
Specific Modules
Require Import Ursus.Stdlib.Primitives.
Require Import Ursus.Stdlib.Functions.
Require Import Ursus.Stdlib.Operators.
TVM-Specific
Require Import UrsusEnvironment.Cpp.current.Environment.
Require Import Ursus.TVM.Functions.
Primitive Types
Integer Types
Unsigned integers:
uint8,uint16,uint32,uint64,uint128,uint256
Signed integers:
int8,int16,int32,int64,int128,int256
Example:
::// var 'balance : uint256 := {1000} .
::// var 'delta : int256 := {-50} .
Boolean Type
boolean (* true or false *)
Example:
::// var 'isActive : boolean := @true .
::// var 'hasPermission : boolean := @false .
Address Type
address (* Blockchain address *)
Example:
::// var 'owner : address := msg->sender .
::// var 'recipient : address := {0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb} .
String Type
string (* UTF-8 string *)
Example:
::// var 'name : string := "MyToken" .
::// var 'symbol : string := "MTK" .
Complex Types
Mapping
Syntax:
mapping KeyType ValueType
Examples:
balances : mapping address uint256
allowances : mapping address (mapping address uint256)
Usage:
::// var 'balance : uint256 := balances[[addr]] .
::// balances[[addr]] := {1000} .
Optional
Syntax:
optional T
Example:
::// var 'maybeValue : optional uint256 := Some {42} .
::// var 'nothing : optional uint256 := None .
Arrays
Syntax:
array T
Example:
::// var 'items : array uint256 := [] .
::// items := items ++ [{1}, {2}, {3}] .
Common Functions
Mathematical Functions
min(a, b) (* Minimum of two values *)
max(a, b) (* Maximum of two values *)
abs(x) (* Absolute value *)
Example:
::// var 'smaller : uint256 := min(x, y) .
::// var 'larger : uint256 := max(x, y) .
Cryptographic Functions
keccak256(data) (* Keccak-256 hash *)
sha256(data) (* SHA-256 hash *)
ripemd160(data) (* RIPEMD-160 hash *)
Example:
::// var 'hash : uint256 := keccak256(data) .
Conversion Functions
uint256(x) (* Convert to uint256 *)
int256(x) (* Convert to int256 *)
address(x) (* Convert to address *)
Example:
::// var 'addr : address := address(uint256Value) .
Operators
Arithmetic
a + b (* Addition *)
a - b (* Subtraction *)
a * b (* Multiplication *)
a / b (* Division *)
a % b (* Modulo *)
Comparison
a == b (* Equal *)
a != b (* Not equal *)
a < b (* Less than *)
a > b (* Greater than *)
a <= b (* Less or equal *)
a >= b (* Greater or equal *)
Logical
a && b (* Logical AND *)
a || b (* Logical OR *)
!a (* Logical NOT *)
Bitwise
a & b (* Bitwise AND *)
a | b (* Bitwise OR *)
a ^ b (* Bitwise XOR *)
~a (* Bitwise NOT *)
a << n (* Left shift *)
a >> n (* Right shift *)
Message Context
Access transaction information:
msg->sender (* Sender address *)
msg->value (* Sent value *)
msg->data (* Message data *)
Example:
::// var 'caller : address := msg->sender .
::// var 'payment : uint256 := msg->value .
Contract Context
Access contract information:
this->address (* Contract address *)
this->balance (* Contract balance *)
Example:
::// var 'contractAddr : address := this->address .
::// var 'funds : uint256 := this->balance .
Platform-Specific Libraries
Solidity Standard Library
Located in ursus-standard-library/src/Solidity/:
- EVM-compatible types
- Solidity-style functions
- Gas-optimized operations
C++ (TON) Standard Library
Located in ursus-standard-library/src/_Cpp/:
- TVM-compatible types
- TON-specific functions
- Cell operations
Rust Standard Library
Located in ursus-standard-library/src/Rust/:
- Rust-compatible types
- Safe operations
- Modern syntax
Next Steps
- Primitives - Detailed primitive types
- Functions - All standard functions
- Operators - Complete operator reference
- TVM Functions - TON-specific functionality
See Also
- Ursus Language - Language reference
- Writing Functions - Function development
- ursus-patterns repository - Usage examples