Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 3890c7b

Browse files
authored
feat: Storage minimal + fixes (#118)
1 parent 362359f commit 3890c7b

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/SUMMARY.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ Summary
66
# Getting Started
77
<!-- - [Local environnement setup](./ch00/env_setup.md) -->
88
- [Basics of a Starknet contract](./ch00/basics/introduction.md)
9-
- [Variables](./ch00/basics/variables.md)
9+
- [Storage](./ch00/basics/storage.md)
1010
- [Constructor](./ch00/basics/constructor.md)
11+
- [Variables](./ch00/basics/variables.md)
1112
- [Visibility and Mutability](./ch00/basics/visibility-mutability.md)
12-
- [Counter contract example](./ch00/basics/counter.md)
13+
- [Counter Example](./ch00/basics/counter.md)
1314
- [Mappings](./ch00/basics/mappings.md)
1415
- [Errors](./ch00/basics/errors.md)
1516
- [Events](./ch00/basics/events.md)
1617
- [Storing Custom Types](./ch00/basics/storing-custom-types.md)
1718
- [Custom types in entrypoints](./ch00/basics/custom-types-in-entrypoints.md)
1819
- [Deploy and interact with contracts](./ch00/interacting/interacting.md)
19-
- [Factory pattern](./ch00/interacting/factory.md)
2020
- [Contract interfaces and Traits generation](./ch00/interacting/interfaces-traits.md)
2121
- [Calling other contracts](./ch00/interacting/calling_other_contracts.md)
22+
- [Factory pattern](./ch00/interacting/factory.md)
2223
- [Testing contracts](./ch00/testing/contract-testing.md)
2324
- [Cairo cheatsheet](./ch00/cairo_cheatsheet/cairo_cheatsheet.md)
2425
- [Felt](./ch00/cairo_cheatsheet/felt.md)
25-
- [Mapping](./ch00/cairo_cheatsheet/mapping.md)
26+
- [LegacyMap](./ch00/cairo_cheatsheet/mapping.md)
2627
- [Arrays](./ch00/cairo_cheatsheet/arrays.md)
2728
- [Loop](./ch00/cairo_cheatsheet/loop.md)
2829
- [Match](./ch00/cairo_cheatsheet/match.md)

src/ch00/basics/storage.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Storage
2+
3+
Here's the most minimal contract you can write in Cairo:
4+
5+
```rust
6+
{{#include ../../../listings/ch00-getting-started/storage/src/minimal_contract.cairo}}
7+
```
8+
9+
Storage is a struct annoted with `#[storage]`. Every contract must have one and only one storage.
10+
It's a key-value store, where each key will be mapped to a storage address of the contract's storage space.
11+
12+
You can define [storage variables](./variables.md#storage-variables) in your contract, and then use them to store and retrieve data.
13+
```rust
14+
{{#include ../../../listings/ch00-getting-started/storage/src/contract.cairo}}
15+
```
16+
17+
> Actually these two contracts have the same underlying sierra program.
18+
> From the compiler's perspective, the storage variables don't exist until they are used.
19+
20+
You can also read about [storing custom types](./storing-custom-types.md)

src/ch00/basics/variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ There are 3 types of variables in Cairo contracts:
66
- declared inside a function
77
- not stored on the blockchain
88
- Storage
9-
- declared in the `Storage` struct of a contract
9+
- declared in the [Storage](./storage.md) of a contract
1010
- can be accessed from one execution to another
1111
- Global
1212
- provides information about the blockchain

src/ch01/constant-product-amm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This is the Cairo adaptation of the [Solidity by example Constant Product AMM](https://solidity-by-example.org/defi/constant-product-amm/).
44

55
```rust
6-
{{#include ../listings/ch01-applications/constant_product_amm/src/constant_product_amm.cairo:ConstantProductAmmContract}}
6+
{{#include ../../listings/ch01-applications/constant_product_amm/src/contracts.cairo:ConstantProductAmmContract}}
77
```
88

99
Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch01-applications/constant_product_amm/src/constant_product_amm.cairo).

0 commit comments

Comments
 (0)