The Cairo Book
Foreword
Introduction
The Cairo Programming Language
1.
Getting Started
❱
1.1.
Installation
1.2.
Hello, World!
2.
Common Programming Concepts
❱
2.1.
Variables and Mutability
2.2.
Data Types
2.3.
Functions
2.4.
Comments
2.5.
Control Flow
3.
Common Collections
❱
3.1.
Arrays
3.2.
Dictionaries
4.
Understanding Ownership
❱
4.1.
What is Ownership?
4.2.
References and Snapshots
5.
Using Structs to Structure Related Data
❱
5.1.
Defining and Instantiating Structs
5.2.
An Example Program Using Structs
5.3.
Method Syntax
6.
Enums and Pattern Matching
❱
6.1.
Enums
6.2.
The Match Control Flow Construct
6.3.
Concise Control Flow with if let and while let
7.
Managing Cairo Projects with Packages, Crates and Modules
❱
7.1.
Packages and Crates
7.2.
Defining Modules to Control Scope
7.3.
Paths for Referring to an Item in the Module Tree
7.4.
Bringing Paths into Scope with the use Keyword
7.5.
Separating Modules into Different Files
8.
Generic Types and Traits
❱
8.1.
Generic Data Types
8.2.
Traits in Cairo
9.
Error Handling
❱
9.1.
Unrecoverable Errors with panic
9.2.
Recoverable Errors with Result
10.
Testing Cairo Programs
❱
10.1.
How To Write Tests
10.2.
Testing Organization
11.
Advanced Cairo Features
❱
11.1.
Custom Data Structures
11.2.
Using Arrays inside Dictionaries
11.3.
Smart Pointers
11.4.
Operator Overloading
11.5.
Working with Hashes
11.6.
Macros
11.7.
Inlining in Cairo
11.8.
Gas Optimisation
11.9.
Printing
12.
Appendix (Cairo)
❱
12.1.
A - Keywords
12.2.
B - Operators and Symbols
12.3.
C - Derivable Traits
12.4.
D - Common Types & Traits and the Cairo Prelude
12.5.
E - Common Error Messages
12.6.
F - Useful Development Tools
12.7.
G - Installing Cairo binaries
Smart Contracts in Cairo
13.
Introduction to Starknet Smart Contracts
❱
13.1.
General Introduction to Smart Contracts
13.2.
Anatomy of a Simple Contract
14.
Building Starknet Smart Contracts
❱
14.1.
Contract Storage
14.2.
Contract Functions
14.3.
Contract Events
15.
Starknet Cross-Contract Interactions
❱
15.1.
ABIs and Contract Interfaces
15.2.
Contract Dispatchers, Library Dispatchers and System Calls
16.
Building Advanced Starknet Smart Contracts
❱
16.1.
Optimizing Storage Costs
16.2.
Composability and Components
❱
16.2.1.
Under the Hood
16.2.2.
Component Dependencies
16.2.3.
Testing Components
16.3.
Upgradeability
16.4.
L1 <> L2 Messaging
16.5.
Oracle Interactions
❱
16.5.1.
Price Feeds
16.5.2.
Randomness
16.6.
Other Examples
❱
16.6.1.
Deploying and Interacting with a Voting Contract
17.
Starknet Smart Contracts Security
❱
17.1.
General Recommendations
17.2.
Testing Smart Contracts
17.3.
Static Analysis Tools
17.4.
Formal Verification
18.
Appendix (Starknet)
❱
18.1.
A - System Calls
Light
Rust
Coal
Navy
Ayu
The Cairo Programming Language
English
Español
Français
简体中文
Indonesian
Turkçe
Advanced Features
Now, let's learn about more advanced features offered by Cairo.