diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 85a76907..b19c0822 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -6,23 +6,24 @@ Summary # Getting Started - [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) diff --git a/src/ch00/basics/storage.md b/src/ch00/basics/storage.md new file mode 100644 index 00000000..95dab63a --- /dev/null +++ b/src/ch00/basics/storage.md @@ -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) diff --git a/src/ch00/basics/variables.md b/src/ch00/basics/variables.md index 6c7ba4ad..cdfbfb68 100644 --- a/src/ch00/basics/variables.md +++ b/src/ch00/basics/variables.md @@ -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 diff --git a/src/ch01/constant-product-amm.md b/src/ch01/constant-product-amm.md index fffa3c9d..7d7dba51 100644 --- a/src/ch01/constant-product-amm.md +++ b/src/ch01/constant-product-amm.md @@ -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). \ No newline at end of file