Core Library
The Sway Core Library, like the name suggests contains core operators and logic for the primitive types of the Sway programming language. These traits and methods are an extension of the primitive types u8
, u16
, u32
, u64
, u256
, str[]
, str
, bool
and , b256
and can be used where appropriate.
The latest core library documentation can be found here. If the latest version is not compatible please refer to the appropriate tagged release.
Using the Core Library
Core library functionalities do not need to be explicitly imported and will work out of the box after creating any new Sway project with forc new
. The use
keyword is simply not required.
Consider this example of using the modulo function for two like value types:
let val_1 = 10;
let val_2 = 2;
let result = val_1 % val_2;
Core Library Prelude
The prelude contains a list of operations essential to all Sway programs. The latest version of the prelude can be found here.