-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Storage minimal + fixes (#118)
- Loading branch information
Showing
4 changed files
with
27 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters