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.
Test Organization
11.
Advanced Cairo Features
❱
11.1.
Custom Data Structures
11.2.
Smart Pointers
11.3.
Deref Coercion
11.4.
Associated Items
11.5.
Operator Overloading
11.6.
Working with Hashes
11.7.
Macros
11.8.
Procedural Macros
11.9.
Inlining in Cairo
11.10.
Printing
11.11.
Arithmetic Circuits
12.
Appendix (Cairo)
❱
12.1.
A - Keywords
12.2.
B - Operators and Symbols
12.3.
C - Derivable Traits
12.4.
D - The Cairo Prelude
12.5.
E - Common Error Messages
12.6.
F - Useful Development Tools
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.1.1.
Storage Mappings
14.1.2.
Storage Vecs
14.2.
Contract Functions
14.3.
Contract Events
15.
Starknet Contract Interactions
❱
15.1.
Contract Class ABI
15.2.
Interacting with Another Contract
15.3.
Executing Code from Another Class
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
18.
Appendix (Starknet)
❱
18.1.
A - System Calls
Cairo VM
19.
Introduction
20.
Architecture
21.
Memory
❱
21.1.
Non-Deterministic Read-only Memory
21.2.
Segments
21.3.
Segment Value
21.4.
Relocation
21.5.
Layout
22.
Execution Model
❱
22.1.
Registers
22.2.
Instructions
22.3.
Cairo Assembly (CASM)
22.4.
State transition
23.
Builtins
❱
23.1.
How Builtins Work
23.2.
Builtins List
❱
23.2.1.
Output
23.2.2.
Pedersen
23.2.3.
Range Check
23.2.4.
ECDSA
23.2.5.
Bitwise
23.2.6.
EC OP
23.2.7.
Keccak
23.2.8.
Poseidon
23.2.9.
Range Check96
23.2.10.
AddMod
23.2.11.
MulMod
23.2.12.
Segment Arena
23.2.13.
Gas
23.2.14.
System
24.
Hints
❱
24.1.
Structure
24.2.
Hint runner
24.3.
List of hints
25.
Runner
❱
25.1.
Program
❱
25.1.1.
Program Artifacts
25.1.2.
Program Parsing
25.2.
Runner Mode
❱
25.2.1.
Execution Mode
25.2.2.
Proof Mode
25.3.
Output
❱
25.3.1.
Cairo PIE
25.3.2.
Memory File
25.3.3.
Trace file
25.3.4.
AIR public input
25.3.5.
AIR private input
26.
Tracer
27.
Implementations
28.
Resources
Light
Rust
Coal
Navy
Ayu
The Cairo Programming Language
Cairo Home
English
Español
Français
简体中文
Indonesian
Turkçe
Building Advanced Starknet Smart Contracts