Cairo by Example
Cairo is a modern programming language that lets you write ZK-provable programs without requiring a deep understanding of the underlying ZK concepts. Its Rust-inspired design that makes it easy to build scalable dApps with the power of validity proofs.
Cairo by Example (CBE) is a collection of runnable examples that illustrate various Cairo concepts and standard libraries. To get even more out of these examples, don't forget to install Cairo locally and check out The Cairo Book. Additionally for the curious, you can also check out the source code for this site.
Now let's begin!
-
Hello World - Start with a traditional Hello World program.
-
Primitives - Learn about signed integers, unsigned integers and other primitives.
-
Custom Types -
struct
andenum
. -
Variable Bindings - mutable bindings, scope, shadowing.
-
Types - Learn about changing and defining types.
-
Conversion - Convert between different types, such as strings, integers, and floats.
-
Expressions - Learn about Expressions & how to use them.
-
Flow of Control -
if
/else
,for
, and others. -
Functions - Learn about Methods, Closures and Higher Order Functions.
-
Modules - Organize code using modules
-
Crates - A crate is a compilation unit in Cairo. Learn how it is structured.
-
Scarb - Go through some basic features of the official Cairo package management tool and build system.
-
Attributes - An attribute is metadata applied to some module, crate or item.
-
Generics - Learn about writing a function or data type which can work for multiple types of arguments.
-
Scoping rules - Scopes play an important part in ownership, borrowing, and lifetimes.
-
Traits - A trait is a collection of methods.
-
Error handling - Learn the Cairo way of handling failures.
-
Core library types - Learn about some custom types provided by
core
library. -
Testing - All sorts of testing in Cairo.
-
Meta - Documentation, Benchmarking.