Skip to content

Commit

Permalink
feat: Storage minimal + fixes (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 authored Nov 20, 2023
1 parent 362359f commit 3890c7b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ Summary
# Getting Started
<!-- - [Local environnement setup](./ch00/env_setup.md) -->
- [Basics of a Starknet contract](./ch00/basics/introduction.md)
- [Variables](./ch00/basics/variables.md)
- [Storage](./ch00/basics/storage.md)
- [Constructor](./ch00/basics/constructor.md)
- [Variables](./ch00/basics/variables.md)
- [Visibility and Mutability](./ch00/basics/visibility-mutability.md)
- [Counter contract example](./ch00/basics/counter.md)
- [Counter Example](./ch00/basics/counter.md)
- [Mappings](./ch00/basics/mappings.md)
- [Errors](./ch00/basics/errors.md)
- [Events](./ch00/basics/events.md)
- [Storing Custom Types](./ch00/basics/storing-custom-types.md)
- [Custom types in entrypoints](./ch00/basics/custom-types-in-entrypoints.md)
- [Deploy and interact with contracts](./ch00/interacting/interacting.md)
- [Factory pattern](./ch00/interacting/factory.md)
- [Contract interfaces and Traits generation](./ch00/interacting/interfaces-traits.md)
- [Calling other contracts](./ch00/interacting/calling_other_contracts.md)
- [Factory pattern](./ch00/interacting/factory.md)
- [Testing contracts](./ch00/testing/contract-testing.md)
- [Cairo cheatsheet](./ch00/cairo_cheatsheet/cairo_cheatsheet.md)
- [Felt](./ch00/cairo_cheatsheet/felt.md)
- [Mapping](./ch00/cairo_cheatsheet/mapping.md)
- [LegacyMap](./ch00/cairo_cheatsheet/mapping.md)
- [Arrays](./ch00/cairo_cheatsheet/arrays.md)
- [Loop](./ch00/cairo_cheatsheet/loop.md)
- [Match](./ch00/cairo_cheatsheet/match.md)
Expand Down
20 changes: 20 additions & 0 deletions src/ch00/basics/storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Storage

Here's the most minimal contract you can write in Cairo:

```rust
{{#include ../../../listings/ch00-getting-started/storage/src/minimal_contract.cairo}}
```

Storage is a struct annoted with `#[storage]`. Every contract must have one and only one storage.
It's a key-value store, where each key will be mapped to a storage address of the contract's storage space.

You can define [storage variables](./variables.md#storage-variables) in your contract, and then use them to store and retrieve data.
```rust
{{#include ../../../listings/ch00-getting-started/storage/src/contract.cairo}}
```

> Actually these two contracts have the same underlying sierra program.
> From the compiler's perspective, the storage variables don't exist until they are used.
You can also read about [storing custom types](./storing-custom-types.md)
2 changes: 1 addition & 1 deletion src/ch00/basics/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ There are 3 types of variables in Cairo contracts:
- declared inside a function
- not stored on the blockchain
- Storage
- declared in the `Storage` struct of a contract
- declared in the [Storage](./storage.md) of a contract
- can be accessed from one execution to another
- Global
- provides information about the blockchain
Expand Down
2 changes: 1 addition & 1 deletion src/ch01/constant-product-amm.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is the Cairo adaptation of the [Solidity by example Constant Product AMM](https://solidity-by-example.org/defi/constant-product-amm/).

```rust
{{#include ../listings/ch01-applications/constant_product_amm/src/constant_product_amm.cairo:ConstantProductAmmContract}}
{{#include ../../listings/ch01-applications/constant_product_amm/src/contracts.cairo:ConstantProductAmmContract}}
```

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 comments on commit 3890c7b

Please sign in to comment.