From e3ae137e1a5444646f3278271ad4271084a5471d Mon Sep 17 00:00:00 2001 From: julio4 Date: Wed, 11 Oct 2023 13:49:47 +0900 Subject: [PATCH] feat: revised book structure --- book.toml | 9 +-- .../calling_other_contracts/.gitignore | 0 .../calling_other_contracts/Scarb.toml | 0 .../calling_other_contracts/src/callee.cairo | 0 .../calling_other_contracts/src/caller.cairo | 0 .../calling_other_contracts/src/lib.cairo | 0 .../calling_other_contracts/src/tests.cairo | 0 .../constructor/.gitignore | 0 .../constructor/Scarb.toml | 0 .../constructor/src/constructor.cairo | 0 .../constructor/src/lib.cairo | 0 .../constructor/src/tests.cairo | 0 .../counter/.gitignore | 0 .../counter/Scarb.toml | 0 .../counter/src/counter.cairo | 0 .../counter/src/lib.cairo | 0 .../counter/src/tests.cairo | 0 .../custom_type_serde/.gitignore | 0 .../custom_type_serde/Scarb.toml | 0 .../custom_type_serde/src/contract.cairo | 0 .../custom_type_serde/src/lib.cairo | 0 .../custom_type_serde/src/tests.cairo | 0 .../errors/.gitignore | 0 .../errors/Scarb.toml | 0 .../errors/src/custom_errors.cairo | 0 .../errors/src/lib.cairo | 0 .../errors/src/simple_errors.cairo | 0 .../errors/src/tests.cairo | 0 .../errors/src/vault_errors.cairo | 0 .../events/.gitignore | 0 .../events/Scarb.toml | 0 .../events/src/counter.cairo | 0 .../events/src/lib.cairo | 0 .../events/src/tests.cairo | 0 .../interfaces_traits/.gitignore | 0 .../interfaces_traits/Scarb.toml | 0 .../interfaces_traits/src/explicit.cairo | 0 .../interfaces_traits/src/implicit.cairo | 0 .../src/implicit_internal.cairo | 0 .../interfaces_traits/src/lib.cairo | 0 .../interfaces_traits/src/tests.cairo | 0 .../mappings/.gitignore | 0 .../mappings/Scarb.toml | 0 .../mappings/src/lib.cairo | 0 .../mappings/src/mappings.cairo | 0 .../mappings/src/tests.cairo | 0 .../storing_custom_types/.gitignore | 0 .../storing_custom_types/Scarb.toml | 0 .../storing_custom_types/src/contract.cairo | 0 .../storing_custom_types/src/lib.cairo | 0 .../storing_custom_types/src/tests.cairo | 0 .../testing/.gitignore | 0 .../testing/Scarb.toml | 0 .../testing/src/contract.cairo | 0 .../testing/src/lib.cairo | 0 .../testing/src/tests.cairo | 0 .../variables/.gitignore | 0 .../variables/Scarb.toml | 0 .../variables/src/global_variables.cairo | 0 .../variables/src/lib.cairo | 0 .../variables/src/local_variables.cairo | 0 .../variables/src/storage_variables.cairo | 0 .../variables/src/tests.cairo | 0 .../visibility/.gitignore | 0 .../visibility/Scarb.toml | 0 .../visibility/src/lib.cairo | 0 .../visibility/src/tests.cairo | 0 .../visibility/src/visibility.cairo | 0 .../simple_vault}/.gitignore | 0 .../simple_vault/Scarb.toml | 0 .../simple_vault/src/lib.cairo | 0 .../simple_vault/src/simple_vault.cairo | 0 .../simple_vault/src/tests.cairo | 0 .../upgradeable_contract}/.gitignore | 0 .../upgradeable_contract/Scarb.toml | 0 .../upgradeable_contract/src/lib.cairo | 0 .../upgradeable_contract/src/tests.cairo | 0 .../src/upgradeable_contract_v0.cairo | 0 .../src/upgradeable_contract_v1.cairo | 0 .../store_using_packing}/.gitignore | 0 .../store_using_packing/Scarb.toml | 0 .../store_using_packing/src/contract.cairo | 0 .../store_using_packing}/src/lib.cairo | 0 .../store_using_packing/src/tests.cairo | 0 .../storing_arrays}/.gitignore | 0 .../storing_arrays/Scarb.toml | 0 .../storing_arrays/src/contract.cairo | 0 .../storing_arrays}/src/lib.cairo | 0 .../storing_arrays/src/tests.cairo | 0 .../struct_as_mapping_key/.gitignore | 0 .../struct_as_mapping_key/Scarb.toml | 0 .../struct_as_mapping_key/src/contract.cairo | 0 .../struct_as_mapping_key/src/lib.cairo | 0 .../struct_as_mapping_key/src/test.cairo | 0 .../write_to_any_slot}/.gitignore | 0 .../write_to_any_slot/Scarb.toml | 0 .../write_to_any_slot/src/contract.cairo | 0 .../write_to_any_slot}/src/lib.cairo | 0 .../write_to_any_slot/src/tests.cairo | 0 src/SUMMARY.md | 63 ++++++++++--------- src/ch00/{ => basics}/constructor.md | 4 +- src/ch00/{ => basics}/counter.md | 4 +- .../custom-types-in-entrypoints.md | 4 +- src/ch00/{ => basics}/errors.md | 12 ++-- src/ch00/{ => basics}/events.md | 4 +- src/ch00/{ => basics}/introduction.md | 0 src/ch00/{ => basics}/mappings.md | 4 +- src/ch00/{ => basics}/storing-custom-types.md | 4 +- src/ch00/{ => basics}/variables.md | 12 ++-- .../{ => basics}/visibility-mutability.md | 4 +- src/ch00/env_setup.md | 5 ++ .../calling_other_contracts.md | 8 +-- src/ch00/interacting/interacting.md | 3 + .../{ => interacting}/interfaces-traits.md | 12 ++-- src/ch00/{ => testing}/contract-testing.md | 6 +- src/ch01/advanced-concepts.md | 3 - src/{ch02 => ch01}/simple_vault.md | 4 +- src/{ch02 => ch01}/upgradeable_contract.md | 8 +-- src/ch02/applications.md | 3 - .../optimisations}/optimisations.md | 0 .../optimisations}/store_using_packing.md | 4 +- src/{ch01 => ch02}/storing_arrays.md | 6 +- src/{ch01 => ch02}/struct-mapping-key.md | 4 +- src/{ch01 => ch02}/write_to_any_slot.md | 4 +- src/starknet-by-example.md | 20 +++++- 125 files changed, 118 insertions(+), 96 deletions(-) rename listings/{ch00-introduction => ch00-getting-started}/calling_other_contracts/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/calling_other_contracts/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/calling_other_contracts/src/callee.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/calling_other_contracts/src/caller.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/calling_other_contracts/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/calling_other_contracts/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/constructor/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/constructor/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/constructor/src/constructor.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/constructor/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/constructor/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/counter/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/counter/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/counter/src/counter.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/counter/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/counter/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/custom_type_serde/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/custom_type_serde/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/custom_type_serde/src/contract.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/custom_type_serde/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/custom_type_serde/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/errors/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/errors/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/errors/src/custom_errors.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/errors/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/errors/src/simple_errors.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/errors/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/errors/src/vault_errors.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/events/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/events/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/events/src/counter.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/events/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/events/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/interfaces_traits/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/interfaces_traits/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/interfaces_traits/src/explicit.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/interfaces_traits/src/implicit.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/interfaces_traits/src/implicit_internal.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/interfaces_traits/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/interfaces_traits/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/mappings/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/mappings/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/mappings/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/mappings/src/mappings.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/mappings/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/storing_custom_types/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/storing_custom_types/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/storing_custom_types/src/contract.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/storing_custom_types/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/storing_custom_types/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/testing/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/testing/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/testing/src/contract.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/testing/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/testing/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/variables/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/variables/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/variables/src/global_variables.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/variables/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/variables/src/local_variables.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/variables/src/storage_variables.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/variables/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/visibility/.gitignore (100%) rename listings/{ch00-introduction => ch00-getting-started}/visibility/Scarb.toml (100%) rename listings/{ch00-introduction => ch00-getting-started}/visibility/src/lib.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/visibility/src/tests.cairo (100%) rename listings/{ch00-introduction => ch00-getting-started}/visibility/src/visibility.cairo (100%) rename listings/{ch01-advanced-concepts/storing_arrays => ch01-applications/simple_vault}/.gitignore (100%) rename listings/{ch02-applications => ch01-applications}/simple_vault/Scarb.toml (100%) rename listings/{ch02-applications => ch01-applications}/simple_vault/src/lib.cairo (100%) rename listings/{ch02-applications => ch01-applications}/simple_vault/src/simple_vault.cairo (100%) rename listings/{ch02-applications => ch01-applications}/simple_vault/src/tests.cairo (100%) rename listings/{ch01-advanced-concepts/write_to_any_slot => ch01-applications/upgradeable_contract}/.gitignore (100%) rename listings/{ch02-applications => ch01-applications}/upgradeable_contract/Scarb.toml (100%) rename listings/{ch02-applications => ch01-applications}/upgradeable_contract/src/lib.cairo (100%) rename listings/{ch02-applications => ch01-applications}/upgradeable_contract/src/tests.cairo (100%) rename listings/{ch02-applications => ch01-applications}/upgradeable_contract/src/upgradeable_contract_v0.cairo (100%) rename listings/{ch02-applications => ch01-applications}/upgradeable_contract/src/upgradeable_contract_v1.cairo (100%) rename listings/{ch02-applications/simple_vault => ch02-advanced-concepts/store_using_packing}/.gitignore (100%) rename listings/{ch03-optimisations => ch02-advanced-concepts}/store_using_packing/Scarb.toml (100%) rename listings/{ch03-optimisations => ch02-advanced-concepts}/store_using_packing/src/contract.cairo (100%) rename listings/{ch01-advanced-concepts/storing_arrays => ch02-advanced-concepts/store_using_packing}/src/lib.cairo (100%) rename listings/{ch03-optimisations => ch02-advanced-concepts}/store_using_packing/src/tests.cairo (100%) rename listings/{ch02-applications/upgradeable_contract => ch02-advanced-concepts/storing_arrays}/.gitignore (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/storing_arrays/Scarb.toml (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/storing_arrays/src/contract.cairo (100%) rename listings/{ch01-advanced-concepts/write_to_any_slot => ch02-advanced-concepts/storing_arrays}/src/lib.cairo (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/storing_arrays/src/tests.cairo (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/struct_as_mapping_key/.gitignore (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/struct_as_mapping_key/Scarb.toml (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/struct_as_mapping_key/src/contract.cairo (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/struct_as_mapping_key/src/lib.cairo (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/struct_as_mapping_key/src/test.cairo (100%) rename listings/{ch03-optimisations/store_using_packing => ch02-advanced-concepts/write_to_any_slot}/.gitignore (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/write_to_any_slot/Scarb.toml (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/write_to_any_slot/src/contract.cairo (100%) rename listings/{ch03-optimisations/store_using_packing => ch02-advanced-concepts/write_to_any_slot}/src/lib.cairo (100%) rename listings/{ch01-advanced-concepts => ch02-advanced-concepts}/write_to_any_slot/src/tests.cairo (100%) rename src/ch00/{ => basics}/constructor.md (82%) rename src/ch00/{ => basics}/counter.md (78%) rename src/ch00/{ => basics}/custom-types-in-entrypoints.md (77%) rename src/ch00/{ => basics}/errors.md (79%) rename src/ch00/{ => basics}/events.md (85%) rename src/ch00/{ => basics}/introduction.md (100%) rename src/ch00/{ => basics}/mappings.md (90%) rename src/ch00/{ => basics}/storing-custom-types.md (75%) rename src/ch00/{ => basics}/variables.md (84%) rename src/ch00/{ => basics}/visibility-mutability.md (93%) create mode 100644 src/ch00/env_setup.md rename src/ch00/{ => interacting}/calling_other_contracts.md (78%) create mode 100644 src/ch00/interacting/interacting.md rename src/ch00/{ => interacting}/interfaces-traits.md (80%) rename src/ch00/{ => testing}/contract-testing.md (93%) delete mode 100644 src/ch01/advanced-concepts.md rename src/{ch02 => ch01}/simple_vault.md (81%) rename src/{ch02 => ch01}/upgradeable_contract.md (90%) delete mode 100644 src/ch02/applications.md rename src/{ch03 => ch02/optimisations}/optimisations.md (100%) rename src/{ch03 => ch02/optimisations}/store_using_packing.md (89%) rename src/{ch01 => ch02}/storing_arrays.md (89%) rename src/{ch01 => ch02}/struct-mapping-key.md (84%) rename src/{ch01 => ch02}/write_to_any_slot.md (91%) diff --git a/book.toml b/book.toml index 07dca7d7..cd648812 100644 --- a/book.toml +++ b/book.toml @@ -1,13 +1,12 @@ [book] -authors = ["msaug"] +authors = ["msaug", "julio4"] language = "en" multilingual = false src = "src" title = "Starknet by Example" [build] -# Eventual translations -# extra-watch-dirs = ["po"] +extra-watch-dirs = ["listings"] [preprocessor.gettext] after = ["links"] @@ -15,4 +14,6 @@ after = ["links"] [output.html] git-repository-url = "https://github.com/NethermindEth/StarknetByExample/" edit-url-template = "https://github.com/NethermindEth/StarknetByExample/edit/main/{path}" -playground.runnable = false \ No newline at end of file +playground.runnable = false +fold.enable = true +fold.level = 2 \ No newline at end of file diff --git a/listings/ch00-introduction/calling_other_contracts/.gitignore b/listings/ch00-getting-started/calling_other_contracts/.gitignore similarity index 100% rename from listings/ch00-introduction/calling_other_contracts/.gitignore rename to listings/ch00-getting-started/calling_other_contracts/.gitignore diff --git a/listings/ch00-introduction/calling_other_contracts/Scarb.toml b/listings/ch00-getting-started/calling_other_contracts/Scarb.toml similarity index 100% rename from listings/ch00-introduction/calling_other_contracts/Scarb.toml rename to listings/ch00-getting-started/calling_other_contracts/Scarb.toml diff --git a/listings/ch00-introduction/calling_other_contracts/src/callee.cairo b/listings/ch00-getting-started/calling_other_contracts/src/callee.cairo similarity index 100% rename from listings/ch00-introduction/calling_other_contracts/src/callee.cairo rename to listings/ch00-getting-started/calling_other_contracts/src/callee.cairo diff --git a/listings/ch00-introduction/calling_other_contracts/src/caller.cairo b/listings/ch00-getting-started/calling_other_contracts/src/caller.cairo similarity index 100% rename from listings/ch00-introduction/calling_other_contracts/src/caller.cairo rename to listings/ch00-getting-started/calling_other_contracts/src/caller.cairo diff --git a/listings/ch00-introduction/calling_other_contracts/src/lib.cairo b/listings/ch00-getting-started/calling_other_contracts/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/calling_other_contracts/src/lib.cairo rename to listings/ch00-getting-started/calling_other_contracts/src/lib.cairo diff --git a/listings/ch00-introduction/calling_other_contracts/src/tests.cairo b/listings/ch00-getting-started/calling_other_contracts/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/calling_other_contracts/src/tests.cairo rename to listings/ch00-getting-started/calling_other_contracts/src/tests.cairo diff --git a/listings/ch00-introduction/constructor/.gitignore b/listings/ch00-getting-started/constructor/.gitignore similarity index 100% rename from listings/ch00-introduction/constructor/.gitignore rename to listings/ch00-getting-started/constructor/.gitignore diff --git a/listings/ch00-introduction/constructor/Scarb.toml b/listings/ch00-getting-started/constructor/Scarb.toml similarity index 100% rename from listings/ch00-introduction/constructor/Scarb.toml rename to listings/ch00-getting-started/constructor/Scarb.toml diff --git a/listings/ch00-introduction/constructor/src/constructor.cairo b/listings/ch00-getting-started/constructor/src/constructor.cairo similarity index 100% rename from listings/ch00-introduction/constructor/src/constructor.cairo rename to listings/ch00-getting-started/constructor/src/constructor.cairo diff --git a/listings/ch00-introduction/constructor/src/lib.cairo b/listings/ch00-getting-started/constructor/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/constructor/src/lib.cairo rename to listings/ch00-getting-started/constructor/src/lib.cairo diff --git a/listings/ch00-introduction/constructor/src/tests.cairo b/listings/ch00-getting-started/constructor/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/constructor/src/tests.cairo rename to listings/ch00-getting-started/constructor/src/tests.cairo diff --git a/listings/ch00-introduction/counter/.gitignore b/listings/ch00-getting-started/counter/.gitignore similarity index 100% rename from listings/ch00-introduction/counter/.gitignore rename to listings/ch00-getting-started/counter/.gitignore diff --git a/listings/ch00-introduction/counter/Scarb.toml b/listings/ch00-getting-started/counter/Scarb.toml similarity index 100% rename from listings/ch00-introduction/counter/Scarb.toml rename to listings/ch00-getting-started/counter/Scarb.toml diff --git a/listings/ch00-introduction/counter/src/counter.cairo b/listings/ch00-getting-started/counter/src/counter.cairo similarity index 100% rename from listings/ch00-introduction/counter/src/counter.cairo rename to listings/ch00-getting-started/counter/src/counter.cairo diff --git a/listings/ch00-introduction/counter/src/lib.cairo b/listings/ch00-getting-started/counter/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/counter/src/lib.cairo rename to listings/ch00-getting-started/counter/src/lib.cairo diff --git a/listings/ch00-introduction/counter/src/tests.cairo b/listings/ch00-getting-started/counter/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/counter/src/tests.cairo rename to listings/ch00-getting-started/counter/src/tests.cairo diff --git a/listings/ch00-introduction/custom_type_serde/.gitignore b/listings/ch00-getting-started/custom_type_serde/.gitignore similarity index 100% rename from listings/ch00-introduction/custom_type_serde/.gitignore rename to listings/ch00-getting-started/custom_type_serde/.gitignore diff --git a/listings/ch00-introduction/custom_type_serde/Scarb.toml b/listings/ch00-getting-started/custom_type_serde/Scarb.toml similarity index 100% rename from listings/ch00-introduction/custom_type_serde/Scarb.toml rename to listings/ch00-getting-started/custom_type_serde/Scarb.toml diff --git a/listings/ch00-introduction/custom_type_serde/src/contract.cairo b/listings/ch00-getting-started/custom_type_serde/src/contract.cairo similarity index 100% rename from listings/ch00-introduction/custom_type_serde/src/contract.cairo rename to listings/ch00-getting-started/custom_type_serde/src/contract.cairo diff --git a/listings/ch00-introduction/custom_type_serde/src/lib.cairo b/listings/ch00-getting-started/custom_type_serde/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/custom_type_serde/src/lib.cairo rename to listings/ch00-getting-started/custom_type_serde/src/lib.cairo diff --git a/listings/ch00-introduction/custom_type_serde/src/tests.cairo b/listings/ch00-getting-started/custom_type_serde/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/custom_type_serde/src/tests.cairo rename to listings/ch00-getting-started/custom_type_serde/src/tests.cairo diff --git a/listings/ch00-introduction/errors/.gitignore b/listings/ch00-getting-started/errors/.gitignore similarity index 100% rename from listings/ch00-introduction/errors/.gitignore rename to listings/ch00-getting-started/errors/.gitignore diff --git a/listings/ch00-introduction/errors/Scarb.toml b/listings/ch00-getting-started/errors/Scarb.toml similarity index 100% rename from listings/ch00-introduction/errors/Scarb.toml rename to listings/ch00-getting-started/errors/Scarb.toml diff --git a/listings/ch00-introduction/errors/src/custom_errors.cairo b/listings/ch00-getting-started/errors/src/custom_errors.cairo similarity index 100% rename from listings/ch00-introduction/errors/src/custom_errors.cairo rename to listings/ch00-getting-started/errors/src/custom_errors.cairo diff --git a/listings/ch00-introduction/errors/src/lib.cairo b/listings/ch00-getting-started/errors/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/errors/src/lib.cairo rename to listings/ch00-getting-started/errors/src/lib.cairo diff --git a/listings/ch00-introduction/errors/src/simple_errors.cairo b/listings/ch00-getting-started/errors/src/simple_errors.cairo similarity index 100% rename from listings/ch00-introduction/errors/src/simple_errors.cairo rename to listings/ch00-getting-started/errors/src/simple_errors.cairo diff --git a/listings/ch00-introduction/errors/src/tests.cairo b/listings/ch00-getting-started/errors/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/errors/src/tests.cairo rename to listings/ch00-getting-started/errors/src/tests.cairo diff --git a/listings/ch00-introduction/errors/src/vault_errors.cairo b/listings/ch00-getting-started/errors/src/vault_errors.cairo similarity index 100% rename from listings/ch00-introduction/errors/src/vault_errors.cairo rename to listings/ch00-getting-started/errors/src/vault_errors.cairo diff --git a/listings/ch00-introduction/events/.gitignore b/listings/ch00-getting-started/events/.gitignore similarity index 100% rename from listings/ch00-introduction/events/.gitignore rename to listings/ch00-getting-started/events/.gitignore diff --git a/listings/ch00-introduction/events/Scarb.toml b/listings/ch00-getting-started/events/Scarb.toml similarity index 100% rename from listings/ch00-introduction/events/Scarb.toml rename to listings/ch00-getting-started/events/Scarb.toml diff --git a/listings/ch00-introduction/events/src/counter.cairo b/listings/ch00-getting-started/events/src/counter.cairo similarity index 100% rename from listings/ch00-introduction/events/src/counter.cairo rename to listings/ch00-getting-started/events/src/counter.cairo diff --git a/listings/ch00-introduction/events/src/lib.cairo b/listings/ch00-getting-started/events/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/events/src/lib.cairo rename to listings/ch00-getting-started/events/src/lib.cairo diff --git a/listings/ch00-introduction/events/src/tests.cairo b/listings/ch00-getting-started/events/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/events/src/tests.cairo rename to listings/ch00-getting-started/events/src/tests.cairo diff --git a/listings/ch00-introduction/interfaces_traits/.gitignore b/listings/ch00-getting-started/interfaces_traits/.gitignore similarity index 100% rename from listings/ch00-introduction/interfaces_traits/.gitignore rename to listings/ch00-getting-started/interfaces_traits/.gitignore diff --git a/listings/ch00-introduction/interfaces_traits/Scarb.toml b/listings/ch00-getting-started/interfaces_traits/Scarb.toml similarity index 100% rename from listings/ch00-introduction/interfaces_traits/Scarb.toml rename to listings/ch00-getting-started/interfaces_traits/Scarb.toml diff --git a/listings/ch00-introduction/interfaces_traits/src/explicit.cairo b/listings/ch00-getting-started/interfaces_traits/src/explicit.cairo similarity index 100% rename from listings/ch00-introduction/interfaces_traits/src/explicit.cairo rename to listings/ch00-getting-started/interfaces_traits/src/explicit.cairo diff --git a/listings/ch00-introduction/interfaces_traits/src/implicit.cairo b/listings/ch00-getting-started/interfaces_traits/src/implicit.cairo similarity index 100% rename from listings/ch00-introduction/interfaces_traits/src/implicit.cairo rename to listings/ch00-getting-started/interfaces_traits/src/implicit.cairo diff --git a/listings/ch00-introduction/interfaces_traits/src/implicit_internal.cairo b/listings/ch00-getting-started/interfaces_traits/src/implicit_internal.cairo similarity index 100% rename from listings/ch00-introduction/interfaces_traits/src/implicit_internal.cairo rename to listings/ch00-getting-started/interfaces_traits/src/implicit_internal.cairo diff --git a/listings/ch00-introduction/interfaces_traits/src/lib.cairo b/listings/ch00-getting-started/interfaces_traits/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/interfaces_traits/src/lib.cairo rename to listings/ch00-getting-started/interfaces_traits/src/lib.cairo diff --git a/listings/ch00-introduction/interfaces_traits/src/tests.cairo b/listings/ch00-getting-started/interfaces_traits/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/interfaces_traits/src/tests.cairo rename to listings/ch00-getting-started/interfaces_traits/src/tests.cairo diff --git a/listings/ch00-introduction/mappings/.gitignore b/listings/ch00-getting-started/mappings/.gitignore similarity index 100% rename from listings/ch00-introduction/mappings/.gitignore rename to listings/ch00-getting-started/mappings/.gitignore diff --git a/listings/ch00-introduction/mappings/Scarb.toml b/listings/ch00-getting-started/mappings/Scarb.toml similarity index 100% rename from listings/ch00-introduction/mappings/Scarb.toml rename to listings/ch00-getting-started/mappings/Scarb.toml diff --git a/listings/ch00-introduction/mappings/src/lib.cairo b/listings/ch00-getting-started/mappings/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/mappings/src/lib.cairo rename to listings/ch00-getting-started/mappings/src/lib.cairo diff --git a/listings/ch00-introduction/mappings/src/mappings.cairo b/listings/ch00-getting-started/mappings/src/mappings.cairo similarity index 100% rename from listings/ch00-introduction/mappings/src/mappings.cairo rename to listings/ch00-getting-started/mappings/src/mappings.cairo diff --git a/listings/ch00-introduction/mappings/src/tests.cairo b/listings/ch00-getting-started/mappings/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/mappings/src/tests.cairo rename to listings/ch00-getting-started/mappings/src/tests.cairo diff --git a/listings/ch00-introduction/storing_custom_types/.gitignore b/listings/ch00-getting-started/storing_custom_types/.gitignore similarity index 100% rename from listings/ch00-introduction/storing_custom_types/.gitignore rename to listings/ch00-getting-started/storing_custom_types/.gitignore diff --git a/listings/ch00-introduction/storing_custom_types/Scarb.toml b/listings/ch00-getting-started/storing_custom_types/Scarb.toml similarity index 100% rename from listings/ch00-introduction/storing_custom_types/Scarb.toml rename to listings/ch00-getting-started/storing_custom_types/Scarb.toml diff --git a/listings/ch00-introduction/storing_custom_types/src/contract.cairo b/listings/ch00-getting-started/storing_custom_types/src/contract.cairo similarity index 100% rename from listings/ch00-introduction/storing_custom_types/src/contract.cairo rename to listings/ch00-getting-started/storing_custom_types/src/contract.cairo diff --git a/listings/ch00-introduction/storing_custom_types/src/lib.cairo b/listings/ch00-getting-started/storing_custom_types/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/storing_custom_types/src/lib.cairo rename to listings/ch00-getting-started/storing_custom_types/src/lib.cairo diff --git a/listings/ch00-introduction/storing_custom_types/src/tests.cairo b/listings/ch00-getting-started/storing_custom_types/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/storing_custom_types/src/tests.cairo rename to listings/ch00-getting-started/storing_custom_types/src/tests.cairo diff --git a/listings/ch00-introduction/testing/.gitignore b/listings/ch00-getting-started/testing/.gitignore similarity index 100% rename from listings/ch00-introduction/testing/.gitignore rename to listings/ch00-getting-started/testing/.gitignore diff --git a/listings/ch00-introduction/testing/Scarb.toml b/listings/ch00-getting-started/testing/Scarb.toml similarity index 100% rename from listings/ch00-introduction/testing/Scarb.toml rename to listings/ch00-getting-started/testing/Scarb.toml diff --git a/listings/ch00-introduction/testing/src/contract.cairo b/listings/ch00-getting-started/testing/src/contract.cairo similarity index 100% rename from listings/ch00-introduction/testing/src/contract.cairo rename to listings/ch00-getting-started/testing/src/contract.cairo diff --git a/listings/ch00-introduction/testing/src/lib.cairo b/listings/ch00-getting-started/testing/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/testing/src/lib.cairo rename to listings/ch00-getting-started/testing/src/lib.cairo diff --git a/listings/ch00-introduction/testing/src/tests.cairo b/listings/ch00-getting-started/testing/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/testing/src/tests.cairo rename to listings/ch00-getting-started/testing/src/tests.cairo diff --git a/listings/ch00-introduction/variables/.gitignore b/listings/ch00-getting-started/variables/.gitignore similarity index 100% rename from listings/ch00-introduction/variables/.gitignore rename to listings/ch00-getting-started/variables/.gitignore diff --git a/listings/ch00-introduction/variables/Scarb.toml b/listings/ch00-getting-started/variables/Scarb.toml similarity index 100% rename from listings/ch00-introduction/variables/Scarb.toml rename to listings/ch00-getting-started/variables/Scarb.toml diff --git a/listings/ch00-introduction/variables/src/global_variables.cairo b/listings/ch00-getting-started/variables/src/global_variables.cairo similarity index 100% rename from listings/ch00-introduction/variables/src/global_variables.cairo rename to listings/ch00-getting-started/variables/src/global_variables.cairo diff --git a/listings/ch00-introduction/variables/src/lib.cairo b/listings/ch00-getting-started/variables/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/variables/src/lib.cairo rename to listings/ch00-getting-started/variables/src/lib.cairo diff --git a/listings/ch00-introduction/variables/src/local_variables.cairo b/listings/ch00-getting-started/variables/src/local_variables.cairo similarity index 100% rename from listings/ch00-introduction/variables/src/local_variables.cairo rename to listings/ch00-getting-started/variables/src/local_variables.cairo diff --git a/listings/ch00-introduction/variables/src/storage_variables.cairo b/listings/ch00-getting-started/variables/src/storage_variables.cairo similarity index 100% rename from listings/ch00-introduction/variables/src/storage_variables.cairo rename to listings/ch00-getting-started/variables/src/storage_variables.cairo diff --git a/listings/ch00-introduction/variables/src/tests.cairo b/listings/ch00-getting-started/variables/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/variables/src/tests.cairo rename to listings/ch00-getting-started/variables/src/tests.cairo diff --git a/listings/ch00-introduction/visibility/.gitignore b/listings/ch00-getting-started/visibility/.gitignore similarity index 100% rename from listings/ch00-introduction/visibility/.gitignore rename to listings/ch00-getting-started/visibility/.gitignore diff --git a/listings/ch00-introduction/visibility/Scarb.toml b/listings/ch00-getting-started/visibility/Scarb.toml similarity index 100% rename from listings/ch00-introduction/visibility/Scarb.toml rename to listings/ch00-getting-started/visibility/Scarb.toml diff --git a/listings/ch00-introduction/visibility/src/lib.cairo b/listings/ch00-getting-started/visibility/src/lib.cairo similarity index 100% rename from listings/ch00-introduction/visibility/src/lib.cairo rename to listings/ch00-getting-started/visibility/src/lib.cairo diff --git a/listings/ch00-introduction/visibility/src/tests.cairo b/listings/ch00-getting-started/visibility/src/tests.cairo similarity index 100% rename from listings/ch00-introduction/visibility/src/tests.cairo rename to listings/ch00-getting-started/visibility/src/tests.cairo diff --git a/listings/ch00-introduction/visibility/src/visibility.cairo b/listings/ch00-getting-started/visibility/src/visibility.cairo similarity index 100% rename from listings/ch00-introduction/visibility/src/visibility.cairo rename to listings/ch00-getting-started/visibility/src/visibility.cairo diff --git a/listings/ch01-advanced-concepts/storing_arrays/.gitignore b/listings/ch01-applications/simple_vault/.gitignore similarity index 100% rename from listings/ch01-advanced-concepts/storing_arrays/.gitignore rename to listings/ch01-applications/simple_vault/.gitignore diff --git a/listings/ch02-applications/simple_vault/Scarb.toml b/listings/ch01-applications/simple_vault/Scarb.toml similarity index 100% rename from listings/ch02-applications/simple_vault/Scarb.toml rename to listings/ch01-applications/simple_vault/Scarb.toml diff --git a/listings/ch02-applications/simple_vault/src/lib.cairo b/listings/ch01-applications/simple_vault/src/lib.cairo similarity index 100% rename from listings/ch02-applications/simple_vault/src/lib.cairo rename to listings/ch01-applications/simple_vault/src/lib.cairo diff --git a/listings/ch02-applications/simple_vault/src/simple_vault.cairo b/listings/ch01-applications/simple_vault/src/simple_vault.cairo similarity index 100% rename from listings/ch02-applications/simple_vault/src/simple_vault.cairo rename to listings/ch01-applications/simple_vault/src/simple_vault.cairo diff --git a/listings/ch02-applications/simple_vault/src/tests.cairo b/listings/ch01-applications/simple_vault/src/tests.cairo similarity index 100% rename from listings/ch02-applications/simple_vault/src/tests.cairo rename to listings/ch01-applications/simple_vault/src/tests.cairo diff --git a/listings/ch01-advanced-concepts/write_to_any_slot/.gitignore b/listings/ch01-applications/upgradeable_contract/.gitignore similarity index 100% rename from listings/ch01-advanced-concepts/write_to_any_slot/.gitignore rename to listings/ch01-applications/upgradeable_contract/.gitignore diff --git a/listings/ch02-applications/upgradeable_contract/Scarb.toml b/listings/ch01-applications/upgradeable_contract/Scarb.toml similarity index 100% rename from listings/ch02-applications/upgradeable_contract/Scarb.toml rename to listings/ch01-applications/upgradeable_contract/Scarb.toml diff --git a/listings/ch02-applications/upgradeable_contract/src/lib.cairo b/listings/ch01-applications/upgradeable_contract/src/lib.cairo similarity index 100% rename from listings/ch02-applications/upgradeable_contract/src/lib.cairo rename to listings/ch01-applications/upgradeable_contract/src/lib.cairo diff --git a/listings/ch02-applications/upgradeable_contract/src/tests.cairo b/listings/ch01-applications/upgradeable_contract/src/tests.cairo similarity index 100% rename from listings/ch02-applications/upgradeable_contract/src/tests.cairo rename to listings/ch01-applications/upgradeable_contract/src/tests.cairo diff --git a/listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo b/listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo similarity index 100% rename from listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo rename to listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo diff --git a/listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo b/listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo similarity index 100% rename from listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo rename to listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo diff --git a/listings/ch02-applications/simple_vault/.gitignore b/listings/ch02-advanced-concepts/store_using_packing/.gitignore similarity index 100% rename from listings/ch02-applications/simple_vault/.gitignore rename to listings/ch02-advanced-concepts/store_using_packing/.gitignore diff --git a/listings/ch03-optimisations/store_using_packing/Scarb.toml b/listings/ch02-advanced-concepts/store_using_packing/Scarb.toml similarity index 100% rename from listings/ch03-optimisations/store_using_packing/Scarb.toml rename to listings/ch02-advanced-concepts/store_using_packing/Scarb.toml diff --git a/listings/ch03-optimisations/store_using_packing/src/contract.cairo b/listings/ch02-advanced-concepts/store_using_packing/src/contract.cairo similarity index 100% rename from listings/ch03-optimisations/store_using_packing/src/contract.cairo rename to listings/ch02-advanced-concepts/store_using_packing/src/contract.cairo diff --git a/listings/ch01-advanced-concepts/storing_arrays/src/lib.cairo b/listings/ch02-advanced-concepts/store_using_packing/src/lib.cairo similarity index 100% rename from listings/ch01-advanced-concepts/storing_arrays/src/lib.cairo rename to listings/ch02-advanced-concepts/store_using_packing/src/lib.cairo diff --git a/listings/ch03-optimisations/store_using_packing/src/tests.cairo b/listings/ch02-advanced-concepts/store_using_packing/src/tests.cairo similarity index 100% rename from listings/ch03-optimisations/store_using_packing/src/tests.cairo rename to listings/ch02-advanced-concepts/store_using_packing/src/tests.cairo diff --git a/listings/ch02-applications/upgradeable_contract/.gitignore b/listings/ch02-advanced-concepts/storing_arrays/.gitignore similarity index 100% rename from listings/ch02-applications/upgradeable_contract/.gitignore rename to listings/ch02-advanced-concepts/storing_arrays/.gitignore diff --git a/listings/ch01-advanced-concepts/storing_arrays/Scarb.toml b/listings/ch02-advanced-concepts/storing_arrays/Scarb.toml similarity index 100% rename from listings/ch01-advanced-concepts/storing_arrays/Scarb.toml rename to listings/ch02-advanced-concepts/storing_arrays/Scarb.toml diff --git a/listings/ch01-advanced-concepts/storing_arrays/src/contract.cairo b/listings/ch02-advanced-concepts/storing_arrays/src/contract.cairo similarity index 100% rename from listings/ch01-advanced-concepts/storing_arrays/src/contract.cairo rename to listings/ch02-advanced-concepts/storing_arrays/src/contract.cairo diff --git a/listings/ch01-advanced-concepts/write_to_any_slot/src/lib.cairo b/listings/ch02-advanced-concepts/storing_arrays/src/lib.cairo similarity index 100% rename from listings/ch01-advanced-concepts/write_to_any_slot/src/lib.cairo rename to listings/ch02-advanced-concepts/storing_arrays/src/lib.cairo diff --git a/listings/ch01-advanced-concepts/storing_arrays/src/tests.cairo b/listings/ch02-advanced-concepts/storing_arrays/src/tests.cairo similarity index 100% rename from listings/ch01-advanced-concepts/storing_arrays/src/tests.cairo rename to listings/ch02-advanced-concepts/storing_arrays/src/tests.cairo diff --git a/listings/ch01-advanced-concepts/struct_as_mapping_key/.gitignore b/listings/ch02-advanced-concepts/struct_as_mapping_key/.gitignore similarity index 100% rename from listings/ch01-advanced-concepts/struct_as_mapping_key/.gitignore rename to listings/ch02-advanced-concepts/struct_as_mapping_key/.gitignore diff --git a/listings/ch01-advanced-concepts/struct_as_mapping_key/Scarb.toml b/listings/ch02-advanced-concepts/struct_as_mapping_key/Scarb.toml similarity index 100% rename from listings/ch01-advanced-concepts/struct_as_mapping_key/Scarb.toml rename to listings/ch02-advanced-concepts/struct_as_mapping_key/Scarb.toml diff --git a/listings/ch01-advanced-concepts/struct_as_mapping_key/src/contract.cairo b/listings/ch02-advanced-concepts/struct_as_mapping_key/src/contract.cairo similarity index 100% rename from listings/ch01-advanced-concepts/struct_as_mapping_key/src/contract.cairo rename to listings/ch02-advanced-concepts/struct_as_mapping_key/src/contract.cairo diff --git a/listings/ch01-advanced-concepts/struct_as_mapping_key/src/lib.cairo b/listings/ch02-advanced-concepts/struct_as_mapping_key/src/lib.cairo similarity index 100% rename from listings/ch01-advanced-concepts/struct_as_mapping_key/src/lib.cairo rename to listings/ch02-advanced-concepts/struct_as_mapping_key/src/lib.cairo diff --git a/listings/ch01-advanced-concepts/struct_as_mapping_key/src/test.cairo b/listings/ch02-advanced-concepts/struct_as_mapping_key/src/test.cairo similarity index 100% rename from listings/ch01-advanced-concepts/struct_as_mapping_key/src/test.cairo rename to listings/ch02-advanced-concepts/struct_as_mapping_key/src/test.cairo diff --git a/listings/ch03-optimisations/store_using_packing/.gitignore b/listings/ch02-advanced-concepts/write_to_any_slot/.gitignore similarity index 100% rename from listings/ch03-optimisations/store_using_packing/.gitignore rename to listings/ch02-advanced-concepts/write_to_any_slot/.gitignore diff --git a/listings/ch01-advanced-concepts/write_to_any_slot/Scarb.toml b/listings/ch02-advanced-concepts/write_to_any_slot/Scarb.toml similarity index 100% rename from listings/ch01-advanced-concepts/write_to_any_slot/Scarb.toml rename to listings/ch02-advanced-concepts/write_to_any_slot/Scarb.toml diff --git a/listings/ch01-advanced-concepts/write_to_any_slot/src/contract.cairo b/listings/ch02-advanced-concepts/write_to_any_slot/src/contract.cairo similarity index 100% rename from listings/ch01-advanced-concepts/write_to_any_slot/src/contract.cairo rename to listings/ch02-advanced-concepts/write_to_any_slot/src/contract.cairo diff --git a/listings/ch03-optimisations/store_using_packing/src/lib.cairo b/listings/ch02-advanced-concepts/write_to_any_slot/src/lib.cairo similarity index 100% rename from listings/ch03-optimisations/store_using_packing/src/lib.cairo rename to listings/ch02-advanced-concepts/write_to_any_slot/src/lib.cairo diff --git a/listings/ch01-advanced-concepts/write_to_any_slot/src/tests.cairo b/listings/ch02-advanced-concepts/write_to_any_slot/src/tests.cairo similarity index 100% rename from listings/ch01-advanced-concepts/write_to_any_slot/src/tests.cairo rename to listings/ch02-advanced-concepts/write_to_any_slot/src/tests.cairo diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 3c02aca3..ba8be362 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -1,33 +1,34 @@ Summary -- [Starknet by Example](./starknet-by-example.md) - -- [Basics of Smart Contracts in Cairo](./ch00/introduction.md) - - - [Constructor](./ch00/constructor.md) - - [Visibility and Mutability](./ch00/visibility-mutability.md) - - [Events](./ch00/events.md) - - [Variables](./ch00/variables.md) - - [Mappings](./ch00/mappings.md) - - [Counter contract example](./ch00/counter.md) - - [Storing Custom Types](./ch00/storing-custom-types.md) - - [Custom types in entrypoints](./ch00/custom-types-in-entrypoints.md) - - [Errors](./ch00/errors.md) - - [Calling other contracts](./ch00/calling_other_contracts.md) - - [Contract interfaces and Traits generation](./ch00/interfaces-traits.md) - - [Contract testing](./ch00/contract-testing.md) - -- [Advanced concepts](./ch01/advanced-concepts.md) - - - [Writing to any storage slot](./ch01/write_to_any_slot.md) - - [Storing Arrays](./ch01/storing_arrays.md) - - [Struct as mapping key](./ch01/struct-mapping-key.md) - -- [Applications](./ch02/applications.md) - - - [Upgradeable Contract](./ch02/upgradeable_contract.md) - - [Defi Vault](./ch02/simple_vault.md) - -- [Optimisations](./ch03/optimisations.md) - - - [Storage Optimisations](./ch03/store_using_packing.md) +[Introduction](./starknet-by-example.md) + + +# Getting Started + + - [Basics of a Starknet contract](./ch00/basics/introduction.md) + - [Variables](./ch00/basics/variables.md) + - [Constructor](./ch00/basics/constructor.md) + - [Visibility and Mutability](./ch00/basics/visibility-mutability.md) + - [Counter contract 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) + - [Interfaces and interacting with contracts](./ch00/interacting/interacting.md) + - [Contract interfaces and Traits generation](./ch00/interacting/interfaces-traits.md) + - [Calling other contracts](./ch00/interacting/calling_other_contracts.md) + - [Testing contracts](./ch00/testing/contract-testing.md) + + +# Applications examples + - [Upgradeable Contract](./ch01/upgradeable_contract.md) + - [Defi Vault](./ch01/simple_vault.md) + + +# Advanced concepts + - [Writing to any storage slot](./ch02/write_to_any_slot.md) + - [Storing Arrays](./ch02/storing_arrays.md) + - [Struct as mapping key](./ch02/struct-mapping-key.md) + - [Optimisations](./ch02/optimisations/optimisations.md) + - [Storage Optimisations](./ch02/optimisations/store_using_packing.md) diff --git a/src/ch00/constructor.md b/src/ch00/basics/constructor.md similarity index 82% rename from src/ch00/constructor.md rename to src/ch00/basics/constructor.md index 85b4d12f..d58009c8 100644 --- a/src/ch00/constructor.md +++ b/src/ch00/basics/constructor.md @@ -5,6 +5,6 @@ Constructors are a special type of function that runs only once when deploying a Here's a simple example that demonstrates how to initialize the state of a contract on deployment by defining logic inside a constructor. ```rust -{{#include ../../listings/ch00-introduction/constructor/src/constructor.cairo}} +{{#include ../../../listings/ch00-getting-started/constructor/src/constructor.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x017fd6558e67451dA583d123D77F4e2651E91502D08F8F8432355293b11e1f8F) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/constructor/src/constructor.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x017fd6558e67451dA583d123D77F4e2651E91502D08F8F8432355293b11e1f8F) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/constructor/src/constructor.cairo). diff --git a/src/ch00/counter.md b/src/ch00/basics/counter.md similarity index 78% rename from src/ch00/counter.md rename to src/ch00/basics/counter.md index dfc51f85..733315b1 100644 --- a/src/ch00/counter.md +++ b/src/ch00/basics/counter.md @@ -11,6 +11,6 @@ Here's how it works: - When a user calls 'decrement', the contract decrements the counter by 1. ```rust -{{#include ../../listings/ch00-introduction/counter/src/counter.cairo}} +{{#include ../../../listings/ch00-getting-started/counter/src/counter.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x01664a69Fe701a1df7Bb0ae4A353792d0cf4E27146ee860075cbf6108b1D5718) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/counter/src/counter.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x01664a69Fe701a1df7Bb0ae4A353792d0cf4E27146ee860075cbf6108b1D5718) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/counter/src/counter.cairo). diff --git a/src/ch00/custom-types-in-entrypoints.md b/src/ch00/basics/custom-types-in-entrypoints.md similarity index 77% rename from src/ch00/custom-types-in-entrypoints.md rename to src/ch00/basics/custom-types-in-entrypoints.md index be11a9a7..9207675e 100644 --- a/src/ch00/custom-types-in-entrypoints.md +++ b/src/ch00/basics/custom-types-in-entrypoints.md @@ -4,7 +4,7 @@ Using custom types in entrypoints requires our type to implement the `Serde` tra Thankfully, we can just derive the `Serde` trait for our custom type. ```rust -{{#include ../../listings/ch00-introduction/custom_type_serde/src/contract.cairo}} +{{#include ../../../listings/ch00-getting-started/custom_type_serde/src/contract.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/custom_type_serde/src/contract.cairo). +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/custom_type_serde/src/contract.cairo). diff --git a/src/ch00/errors.md b/src/ch00/basics/errors.md similarity index 79% rename from src/ch00/errors.md rename to src/ch00/basics/errors.md index 0403c547..6d6f95f7 100644 --- a/src/ch00/errors.md +++ b/src/ch00/basics/errors.md @@ -16,24 +16,24 @@ To throw an error, use the `assert` or `panic` functions: Here's a simple example that demonstrates the use of these functions: ```rust -{{#include ../../listings/ch00-introduction/errors/src/simple_errors.cairo}} +{{#include ../../../listings/ch00-getting-started/errors/src/simple_errors.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x0022664463FF0b711CC9B549a9E87d65A0882bB1D29338C4108696B8F2216a40) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/errors/src/simple_errors.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x0022664463FF0b711CC9B549a9E87d65A0882bB1D29338C4108696B8F2216a40) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/errors/src/simple_errors.cairo). ## Custom errors You can make error handling easier by defining your error codes in a specific module. ```rust -{{#include ../../listings/ch00-introduction/errors/src/custom_errors.cairo}} +{{#include ../../../listings/ch00-getting-started/errors/src/custom_errors.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x0501CD5da5B453a18515B5A20b8029bd7583DFE7a399ad9f79c284F7829e4A57) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/errors/src/custom_errors.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x0501CD5da5B453a18515B5A20b8029bd7583DFE7a399ad9f79c284F7829e4A57) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/errors/src/custom_errors.cairo). ## Vault example Here's another example that demonstrates the use of errors in a more complex contract: ```rust -{{#include ../../listings/ch00-introduction/errors/src/vault_errors.cairo}} +{{#include ../../../listings/ch00-getting-started/errors/src/vault_errors.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x020C2da26F42A28Ef54ED428eF1810FE433784b055f9bF315C5d992b1579C268) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/errors/src/vault_errors.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x020C2da26F42A28Ef54ED428eF1810FE433784b055f9bF315C5d992b1579C268) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/errors/src/vault_errors.cairo). diff --git a/src/ch00/events.md b/src/ch00/basics/events.md similarity index 85% rename from src/ch00/events.md rename to src/ch00/basics/events.md index c82f29ad..0e724c36 100644 --- a/src/ch00/events.md +++ b/src/ch00/basics/events.md @@ -6,6 +6,6 @@ An event is defined as struct that derives the `#[starknet::Event]` trait. The f Here's a simple example of a contract using events that emit an event each time a counter is incremented by the "increment" function: ```rust -{{#include ../../listings/ch00-introduction/events/src/counter.cairo}} +{{#include ../../../listings/ch00-getting-started/events/src/counter.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x022e3B59518EA04aBb5da671ea04ecC3a154400f226d2Df38eFE146741b9E2F6) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/events/src/counter.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x022e3B59518EA04aBb5da671ea04ecC3a154400f226d2Df38eFE146741b9E2F6) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/events/src/counter.cairo). diff --git a/src/ch00/introduction.md b/src/ch00/basics/introduction.md similarity index 100% rename from src/ch00/introduction.md rename to src/ch00/basics/introduction.md diff --git a/src/ch00/mappings.md b/src/ch00/basics/mappings.md similarity index 90% rename from src/ch00/mappings.md rename to src/ch00/basics/mappings.md index 64ca4bbe..99329a67 100644 --- a/src/ch00/mappings.md +++ b/src/ch00/basics/mappings.md @@ -11,6 +11,6 @@ Some additional notes: - In mappings, the address of the value at key `k_1,...,k_n` is `h(...h(h(sn_keccak(variable_name),k_1),k_2),...,k_n)` where `ℎ` is the Pedersen hash and the final value is taken `mod2251−256`. You can learn more about the contract storage layout in the [Starknet Documentation](https://docs.starknet.io/documentation/architecture_and_concepts/Contracts/contract-storage/#storage_variables) ```rust -{{#include ../../listings/ch00-introduction/mappings/src/mappings.cairo}} +{{#include ../../../listings/ch00-getting-started/mappings/src/mappings.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x06214AB4c23Cc545bf2221D465eB83aFb7412779AD498BD48a724B3F645E3505) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/mappings/src/mappings.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x06214AB4c23Cc545bf2221D465eB83aFb7412779AD498BD48a724B3F645E3505) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/mappings/src/mappings.cairo). diff --git a/src/ch00/storing-custom-types.md b/src/ch00/basics/storing-custom-types.md similarity index 75% rename from src/ch00/storing-custom-types.md rename to src/ch00/basics/storing-custom-types.md index e70c26fd..1c494365 100644 --- a/src/ch00/storing-custom-types.md +++ b/src/ch00/basics/storing-custom-types.md @@ -3,7 +3,7 @@ While native types can be stored in a contract's storage without any additional work, custom types require a bit more work. This is because at compile time, the compiler does not know how to store custom types in storage. To solve this, we need to implement the `Store` trait for our custom type. Hopefully, we can just derive this trait for our custom type - unless it contains arrays or dictionaries. ```rust -{{#include ../../listings/ch00-introduction/storing_custom_types/src/contract.cairo}} +{{#include ../../../listings/ch00-getting-started/storing_custom_types/src/contract.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/storing_custom_types/src/contract.cairo). +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/storing_custom_types/src/contract.cairo). diff --git a/src/ch00/variables.md b/src/ch00/basics/variables.md similarity index 84% rename from src/ch00/variables.md rename to src/ch00/basics/variables.md index 5dbe0d36..efd5c142 100644 --- a/src/ch00/variables.md +++ b/src/ch00/basics/variables.md @@ -21,9 +21,9 @@ Local variables are stored in memory and are not stored on the blockchain. This Here's a simple example of a contract with only local variables: ```rust -{{#include ../../listings/ch00-introduction/variables/src/local_variables.cairo}} +{{#include ../../../listings/ch00-getting-started/variables/src/local_variables.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x015B3a10F9689BeD741Ca3C210017BC097122CeF76f3cAA191A20ff8b9b56b96) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/variables/src/local_variables.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x015B3a10F9689BeD741Ca3C210017BC097122CeF76f3cAA191A20ff8b9b56b96) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/variables/src/local_variables.cairo). ## Storage Variables @@ -36,9 +36,9 @@ On the other hand, you can read state variables, for free, without any transacti Here's a simple example of a contract with one storage variable: ```rust -{{#include ../../listings/ch00-introduction/variables/src/storage_variables.cairo}} +{{#include ../../../listings/ch00-getting-started/variables/src/storage_variables.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x06eA827B32875483709b785A7F9e846a52776Cd8D42C3fE696218c2624b0DCCa) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/variables/src/storage_variables.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x06eA827B32875483709b785A7F9e846a52776Cd8D42C3fE696218c2624b0DCCa) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/variables/src/storage_variables.cairo). ## Global Variables @@ -49,6 +49,6 @@ In Starknet, you can access global variables by using specific functions contain For example, the `get_caller_address` function returns the address of the caller of the current transaction, and the `get_contract_address` function returns the address of the current contract. ```rust -{{#include ../../listings/ch00-introduction/variables/src/global_variables.cairo}} +{{#include ../../../listings/ch00-getting-started/variables/src/global_variables.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x05bD2F3943bd4e030f85678b55b2EC2C1be939e32388530FB20ED967B3Be433F) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/variables/src/global_variables.cairo). \ No newline at end of file +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x05bD2F3943bd4e030f85678b55b2EC2C1be939e32388530FB20ED967B3Be433F) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/variables/src/global_variables.cairo). \ No newline at end of file diff --git a/src/ch00/visibility-mutability.md b/src/ch00/basics/visibility-mutability.md similarity index 93% rename from src/ch00/visibility-mutability.md rename to src/ch00/basics/visibility-mutability.md index 046d9b3b..20cc6b12 100644 --- a/src/ch00/visibility-mutability.md +++ b/src/ch00/basics/visibility-mutability.md @@ -25,6 +25,6 @@ Internal functions can't be called externally, but the same principle applies re Let's take a look at a simple example contract to see these in action: ```rust -{{#include ../../listings/ch00-introduction/visibility/src/visibility.cairo}} +{{#include ../../../listings/ch00-getting-started/visibility/src/visibility.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x0071dE3093AB58053b0292C225aa0eED40293e7694A0042685FF6D813d39889F) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/visibility/src/visibility.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x0071dE3093AB58053b0292C225aa0eED40293e7694A0042685FF6D813d39889F) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/visibility/src/visibility.cairo). diff --git a/src/ch00/env_setup.md b/src/ch00/env_setup.md new file mode 100644 index 00000000..71392ddc --- /dev/null +++ b/src/ch00/env_setup.md @@ -0,0 +1,5 @@ +# Local environnement setup + +The current version of this book use `{{#include ../../.tool-versions}}` + + diff --git a/src/ch00/calling_other_contracts.md b/src/ch00/interacting/calling_other_contracts.md similarity index 78% rename from src/ch00/calling_other_contracts.md rename to src/ch00/interacting/calling_other_contracts.md index 5b1be663..9efb90c1 100644 --- a/src/ch00/calling_other_contracts.md +++ b/src/ch00/interacting/calling_other_contracts.md @@ -10,11 +10,11 @@ The other way is to use the `starknet::call_contract_syscall` syscall yourself. In order to call other contracts using dispatchers, you will need to define the called contract's interface as a trait annotated with the `#[starknet::interface]` attribute, and then import the `IContractDispatcher` and `IContractDispatcherTrait` items in your contract. ```rust -{{#include ../../listings/ch00-introduction/calling_other_contracts/src/callee.cairo}} +{{#include ../../../listings/ch00-getting-started/calling_other_contracts/src/callee.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x015c3Bb6D0DE26b64FEAF9A8f4655CfADb5c128bF4510398972704ee12775DB1) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/calling_other_contracts/src/callee.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x015c3Bb6D0DE26b64FEAF9A8f4655CfADb5c128bF4510398972704ee12775DB1) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/calling_other_contracts/src/callee.cairo). ```rust -{{#include ../../listings/ch00-introduction/calling_other_contracts/src/caller.cairo}} +{{#include ../../../listings/ch00-getting-started/calling_other_contracts/src/caller.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x05fa8aF796343d2f22c53C17149386b67B7AC4aB52D9e308Aa507C185aA44778) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/calling_other_contracts/src/caller.cairo). \ No newline at end of file +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x05fa8aF796343d2f22c53C17149386b67B7AC4aB52D9e308Aa507C185aA44778) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/calling_other_contracts/src/caller.cairo). \ No newline at end of file diff --git a/src/ch00/interacting/interacting.md b/src/ch00/interacting/interacting.md new file mode 100644 index 00000000..cd6e7203 --- /dev/null +++ b/src/ch00/interacting/interacting.md @@ -0,0 +1,3 @@ +# Interacting with contracts + +In this chapter, we will see how to interact with contracts. \ No newline at end of file diff --git a/src/ch00/interfaces-traits.md b/src/ch00/interacting/interfaces-traits.md similarity index 80% rename from src/ch00/interfaces-traits.md rename to src/ch00/interacting/interfaces-traits.md index 7f0a42c2..c9922fac 100644 --- a/src/ch00/interfaces-traits.md +++ b/src/ch00/interacting/interfaces-traits.md @@ -16,18 +16,18 @@ In summary, there's two ways to handle interfaces: ## Explicit interface ```rust -{{#include ../../listings/ch00-introduction/interfaces_traits/src/explicit.cairo}} +{{#include ../../../listings/ch00-getting-started/interfaces_traits/src/explicit.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/interfaces_traits/src/explicit.cairo). +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/interfaces_traits/src/explicit.cairo). ## Implicit interface ```rust -{{#include ../../listings/ch00-introduction/interfaces_traits/src/implicit.cairo}} +{{#include ../../../listings/ch00-getting-started/interfaces_traits/src/implicit.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/interfaces_traits/src/implicit.cairo). +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/interfaces_traits/src/implicit.cairo). > Note: You can import an implicitly generated contract interface with `use contract::{GeneratedContractInterface}`. However, the `Dispatcher` will not be generated automatically. @@ -37,7 +37,7 @@ You can also use `#[generate_trait]` for your internal functions. Since this trait is generated in the context of the contract, you can define pure functions as well (functions without the `self` parameter). ```rust -{{#include ../../listings/ch00-introduction/interfaces_traits/src/implicit_internal.cairo}} +{{#include ../../../listings/ch00-getting-started/interfaces_traits/src/implicit_internal.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/interfaces_traits/src/implicit_internal.cairo). +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/interfaces_traits/src/implicit_internal.cairo). diff --git a/src/ch00/contract-testing.md b/src/ch00/testing/contract-testing.md similarity index 93% rename from src/ch00/contract-testing.md rename to src/ch00/testing/contract-testing.md index bca2f6dd..a8367170 100644 --- a/src/ch00/contract-testing.md +++ b/src/ch00/testing/contract-testing.md @@ -4,15 +4,15 @@ Testing plays a crucial role in software development, especially for smart contr Let's start with a simple smart contract as an example: ```rust -{{#include ../../listings/ch00-introduction/testing/src/contract.cairo}} +{{#include ../../../listings/ch00-getting-started/testing/src/contract.cairo}} ``` Now, take a look at the tests for this contract: ```rust -{{#include ../../listings/ch00-introduction/testing/src/tests.cairo}} +{{#include ../../../listings/ch00-getting-started/testing/src/tests.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-introduction/testing/src/lib.cairo). +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch00-getting-started/testing/src/lib.cairo). To define our test, we use scarb, which allows us to create a separate module guarded with `#[cfg(test)]`. This ensures that the test module is only compiled when running tests using `scarb test`. diff --git a/src/ch01/advanced-concepts.md b/src/ch01/advanced-concepts.md deleted file mode 100644 index d53246b7..00000000 --- a/src/ch01/advanced-concepts.md +++ /dev/null @@ -1,3 +0,0 @@ -# Advanced Concepts - -In this section, we will present some advanced concepts that are not required for writing smart contracts, but are useful for writing more complex applications. diff --git a/src/ch02/simple_vault.md b/src/ch01/simple_vault.md similarity index 81% rename from src/ch02/simple_vault.md rename to src/ch01/simple_vault.md index 7c278a7b..978fa15a 100644 --- a/src/ch02/simple_vault.md +++ b/src/ch01/simple_vault.md @@ -8,7 +8,7 @@ Here's how it works: - When a user withdraws, the contract burns their shares, calculates the yield, and withdraw both the yield and the initial amount of token deposited. ```rust -{{#include ../../listings/ch02-applications/simple_vault/src/simple_vault.cairo}} +{{#include ../../listings/ch01-applications/simple_vault/src/simple_vault.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch02-applications/simple_vault/src/simple_vault.cairo). \ No newline at end of file +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch01-applications/simple_vault/src/simple_vault.cairo). \ No newline at end of file diff --git a/src/ch02/upgradeable_contract.md b/src/ch01/upgradeable_contract.md similarity index 90% rename from src/ch02/upgradeable_contract.md rename to src/ch01/upgradeable_contract.md index c2eed644..22eabb3c 100644 --- a/src/ch02/upgradeable_contract.md +++ b/src/ch01/upgradeable_contract.md @@ -23,13 +23,13 @@ To illustrate this concept, let's consider an example with two contracts: `Upgra Start by deploying `UpgradeableContract_V0` as the initial version. Next, send a transaction that invokes the `upgrade` function, with the class hash of `UpgradeableContract_V1` as parameter to upgrade the class hash of the deployed contract to the `UpgradeableContract_V1` one. Then, call the `version` method on the contract to see that the contract was upgraded to the V1 version. ```rust -{{#include ../../listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo}} +{{#include ../../listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x005300003ade5d10447d941a42d48b7141074cd8bade2b16520684896a5090ea) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x005300003ade5d10447d941a42d48b7141074cd8bade2b16520684896a5090ea) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v0.cairo). ```rust -{{#include ../../listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo}} +{{#include ../../listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x017c86152badd1d665b9836571bd6b0a484f028748aa13d9b2d5d9c9192fafc6) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch02-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x017c86152badd1d665b9836571bd6b0a484f028748aa13d9b2d5d9c9192fafc6) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch01-applications/upgradeable_contract/src/upgradeable_contract_v1.cairo). diff --git a/src/ch02/applications.md b/src/ch02/applications.md deleted file mode 100644 index 44403891..00000000 --- a/src/ch02/applications.md +++ /dev/null @@ -1,3 +0,0 @@ -# Applications - -A collection of common Cairo applications. diff --git a/src/ch03/optimisations.md b/src/ch02/optimisations/optimisations.md similarity index 100% rename from src/ch03/optimisations.md rename to src/ch02/optimisations/optimisations.md diff --git a/src/ch03/store_using_packing.md b/src/ch02/optimisations/store_using_packing.md similarity index 89% rename from src/ch03/store_using_packing.md rename to src/ch02/optimisations/store_using_packing.md index 37b9cb5f..f0935339 100644 --- a/src/ch03/store_using_packing.md +++ b/src/ch02/optimisations/store_using_packing.md @@ -26,7 +26,7 @@ This allows to store the type `T` by first packing it into the type `PackedT` wi Here's an example of storing a `Time` struct with two `u8` values using the `StorePacking` trait: ```rust -{{#include ../../listings/ch03-optimisations/store_using_packing/src/contract.cairo}} +{{#include ../../../listings/ch02-advanced-concepts/store_using_packing/src/contract.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet-cairo1-compiler&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch03-optimisations/store_using_packing/src/contract.cairo). +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet-cairo1-compiler&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch02-advanced-concepts/store_using_packing/src/contract.cairo). diff --git a/src/ch01/storing_arrays.md b/src/ch02/storing_arrays.md similarity index 89% rename from src/ch01/storing_arrays.md rename to src/ch02/storing_arrays.md index c449084f..d2b2430e 100644 --- a/src/ch01/storing_arrays.md +++ b/src/ch02/storing_arrays.md @@ -7,12 +7,12 @@ On Starknet, complex values (e.g., tuples or structs), are stored in a continuou The following example demonstrates how to write a simple implementation of the `StorageAccess` trait for the `Array` type, allowing us to store arrays of up to 255 `felt252` elements. ```rust -{{#include ../../listings/ch01-advanced-concepts/storing_arrays/src/contract.cairo:StorageAccessImpl}} +{{#include ../../listings/ch02-advanced-concepts/storing_arrays/src/contract.cairo:StorageAccessImpl}} ``` You can then import this implementation in your contract and use it to store arrays in storage: ```rust -{{#include ../../listings/ch01-advanced-concepts/storing_arrays/src/contract.cairo:StoreArrayContract}} +{{#include ../../listings/ch02-advanced-concepts/storing_arrays/src/contract.cairo:StoreArrayContract}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x008F8069a3Fcd7691Db46Dc3b6F9D2C0436f9200E861330957Fd780A3595da86) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch01-advanced-concepts/storing_arrays/src/contract.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x008F8069a3Fcd7691Db46Dc3b6F9D2C0436f9200E861330957Fd780A3595da86) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch02-advanced-concepts/storing_arrays/src/contract.cairo). diff --git a/src/ch01/struct-mapping-key.md b/src/ch02/struct-mapping-key.md similarity index 84% rename from src/ch01/struct-mapping-key.md rename to src/ch02/struct-mapping-key.md index 7b2bfe5c..c21760ce 100644 --- a/src/ch01/struct-mapping-key.md +++ b/src/ch02/struct-mapping-key.md @@ -6,7 +6,7 @@ Consider the following example in which we would like to use an object of type `Pet` as a key in a `LegacyMap`. The `Pet` struct has three fields: `name`, `age` and `owner`. We consider that the combination of these three fields uniquely identifies a pet. ```rust -{{#include ../../listings/ch01-advanced-concepts/struct_as_mapping_key/src/contract.cairo}} +{{#include ../../listings/ch02-advanced-concepts/struct_as_mapping_key/src/contract.cairo}} ``` -Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch01-advanced-concepts/struct_as_mapping_key/src/contract.cairo). \ No newline at end of file +Play with this contract in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch02-advanced-concepts/struct_as_mapping_key/src/contract.cairo). \ No newline at end of file diff --git a/src/ch01/write_to_any_slot.md b/src/ch02/write_to_any_slot.md similarity index 91% rename from src/ch01/write_to_any_slot.md rename to src/ch02/write_to_any_slot.md index 7884a4c9..6b8218d2 100644 --- a/src/ch01/write_to_any_slot.md +++ b/src/ch02/write_to_any_slot.md @@ -9,6 +9,6 @@ This is useful when writing to storage variables that are not known at compile t In the following example, we use the Poseidon hash function to compute the address of a storage variable. Poseidon is a ZK-friendly hash function that is cheaper and faster than Pedersen, making it an excellent choice for onchain computations. Once the address is computed, we use the storage syscalls to interact with it. ```rust -{{#include ../../listings/ch01-advanced-concepts/write_to_any_slot/src/contract.cairo}} +{{#include ../../listings/ch02-advanced-concepts/write_to_any_slot/src/contract.cairo}} ``` -Visit contract on [Voyager](https://goerli.voyager.online/contract/0x033943CB781A4E63C9dcE0A1A09eAa3b617AA43CC61637C08c043a67f3fe0087) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch01-advanced-concepts/write_to_any_slot/src/contract.cairo). +Visit contract on [Voyager](https://goerli.voyager.online/contract/0x033943CB781A4E63C9dcE0A1A09eAa3b617AA43CC61637C08c043a67f3fe0087) or play with it in [Remix](https://remix.ethereum.org/?#activate=Starknet&url=https://github.com/NethermindEth/StarknetByExample/blob/main/listings/ch02-advanced-concepts/write_to_any_slot/src/contract.cairo). diff --git a/src/starknet-by-example.md b/src/starknet-by-example.md index f3bef604..4308beb4 100644 --- a/src/starknet-by-example.md +++ b/src/starknet-by-example.md @@ -2,7 +2,25 @@ Starknet By Example is a collection of examples of how to use the Cairo programming language to create smart contracts on Starknet. -Cairo is a Turing-complete programming language designed to write provable programs, abstracting the zk-STARK proof system away from the programmer. +Starknet is a permissionless Validity-Rollup that supports general computation. It is currently used as an Ethereum layer-2. Starknet use the STARK cryptographic proof system to ensure high safety and scalability. + +Starknet smart contracts are written in the Cairo language. Cairo is a Turing-complete programming language designed to write provable programs, abstracting the zk-STARK proof system away from the programmer. + +The current version of this book use `{{#include ../.tool-versions}}` + +## For whom is this for? + +Starknet By Example is for anyone who wants to quickly learn how to write smart contracts on Starknet using Cairo with some technical background in programming and blockchain. + +The first chapters will give you a basic understanding of the Cairo programming language and how to write, deploy and use smart contracts on Starknet. +The later chapters will cover more advanced topics and show you how to write more complex smart contracts. + +## Further reading If you want to learn more about the Cairo programming language, you can read the [Cairo Book](https://cairo-book.github.io/). If you want to learn more about Starknet, you can read the [Starknet documentation](https://docs.starknet.io/) and the [Starknet Book](https://book.starknet.io). + +Here's a list of other resources that you might find useful: +- [Starklings](https://github.com/shramee/starklings-cairo1): An interactive tutorial to get you up and running with Cairo v1 and Starknet +- [Cairopractice](https://cairopractice.com/): A blog with a series of articles about Cairo and Starknet +- [Cairo by example](https://cairo-by-example.com/): An introduction to Cairo, with simple examples