diff --git a/listings/getting-started/cairo_cheatsheet/src/array_example.cairo b/listings/getting-started/cairo_cheatsheet/src/array_example.cairo index c06ac7cf..8176491a 100644 --- a/listings/getting-started/cairo_cheatsheet/src/array_example.cairo +++ b/listings/getting-started/cairo_cheatsheet/src/array_example.cairo @@ -12,6 +12,6 @@ fn array() -> bool { let second_value = *arr.at(0); assert(second_value == 20, 'second value should match'); - // Returns true if an array is empty, then false if it isn't. + // Returns true if an array is empty, and false if it isn't. arr.is_empty() } diff --git a/listings/getting-started/cairo_cheatsheet/src/type_casting_example.cairo b/listings/getting-started/cairo_cheatsheet/src/type_casting_example.cairo index 0c7362d0..17150e32 100644 --- a/listings/getting-started/cairo_cheatsheet/src/type_casting_example.cairo +++ b/listings/getting-started/cairo_cheatsheet/src/type_casting_example.cairo @@ -21,7 +21,7 @@ fn type_casting() { let _new_u256: u256 = my_felt252.into(); let _new_felt252: felt252 = new_u16.into(); - //note a usize is smaller than a felt so we use the try_into + // Note: usize is smaller than felt252, so we use try_into let _new_usize: usize = my_felt252.try_into().unwrap(); // ANCHOR_END: sheet } diff --git a/listings/getting-started/cairo_cheatsheet/src/while_let_example.cairo b/listings/getting-started/cairo_cheatsheet/src/while_let_example.cairo index ebdc19ce..edc475e0 100644 --- a/listings/getting-started/cairo_cheatsheet/src/while_let_example.cairo +++ b/listings/getting-started/cairo_cheatsheet/src/while_let_example.cairo @@ -2,7 +2,7 @@ fn while_let() { // ANCHOR: sheet let mut option = Option::Some(0_usize); - // "while `let` destructures `option` into `Some(i)`: + // "while `let` destructures `option` into `Some(i)`, // evaluate the block (`{}`), else `break` while let Option::Some(i) = option { diff --git a/listings/getting-started/custom_type_serde/src/contract.cairo b/listings/getting-started/custom_type_serde/src/contract.cairo index beea5a07..9a320b75 100644 --- a/listings/getting-started/custom_type_serde/src/contract.cairo +++ b/listings/getting-started/custom_type_serde/src/contract.cairo @@ -6,7 +6,7 @@ pub trait ISerdeCustomType { // ANCHOR: contract // Deriving the `Serde` trait allows us to use -// the Person type as an entrypoint parameter and return value +// the `Person` type as an entrypoint parameter and as a return value #[derive(Drop, Serde)] pub struct Person { pub age: u8, diff --git a/listings/getting-started/events/src/counter.cairo b/listings/getting-started/events/src/counter.cairo index 346e47b5..10d879a6 100644 --- a/listings/getting-started/events/src/counter.cairo +++ b/listings/getting-started/events/src/counter.cairo @@ -17,7 +17,7 @@ pub mod EventCounter { #[event] #[derive(Copy, Drop, Debug, PartialEq, starknet::Event)] // The event enum must be annotated with the `#[event]` attribute. - // It must also derive atleast `Drop` and `starknet::Event` traits. + // It must also derive at least the `Drop` and `starknet::Event` traits. pub enum Event { CounterIncreased: CounterIncreased, UserIncreaseCounter: UserIncreaseCounter diff --git a/listings/getting-started/testing_how_to/src/contract.cairo b/listings/getting-started/testing_how_to/src/contract.cairo index 0ef9f56e..6eab76dd 100644 --- a/listings/getting-started/testing_how_to/src/contract.cairo +++ b/listings/getting-started/testing_how_to/src/contract.cairo @@ -202,14 +202,14 @@ mod tests_with_states { assert_eq!(state.get_value(), initial_value); assert_eq!(state.get_owner(), owner); - // Mutating the state from the contract change the testing state + // Mutating the state from the contract changes the testing state set_contract_address(owner); let new_value: u32 = 20; contract.set_value(new_value); set_contract_address(contract.contract_address); assert_eq!(state.get_value(), new_value); - // Mutating the state from the testing state change the contract state + // Mutating the state from the testing state changes the contract state set_caller_address(owner); state.set_value(initial_value); assert_eq!(contract.get_value(), initial_value); diff --git a/listings/getting-started/visibility/src/visibility.cairo b/listings/getting-started/visibility/src/visibility.cairo index f3482ee2..25256830 100644 --- a/listings/getting-started/visibility/src/visibility.cairo +++ b/listings/getting-started/visibility/src/visibility.cairo @@ -12,21 +12,21 @@ pub mod ExampleContract { value: u32 } - // The `abi(embed_v0)` attribute indicates that all + // The `#[abi(embed_v0)]` attribute indicates that all // the functions in this implementation can be called externally. // Omitting this attribute would make all the functions internal. #[abi(embed_v0)] impl ExampleContract of super::IExampleContract { // The `set` function can be called externally - // because it is written inside an implementation marked as `#[external]`. + // because it is written inside an implementation marked as `#[abi(embed_v0)]`. // It can modify the contract's state as it is passed as a reference. fn set(ref self: ContractState, value: u32) { self.value.write(value); } // The `get` function can be called externally - // because it is written inside an implementation marked as `#[external]`. - // However, it can't modify the contract's state is passed as a snapshot + // because it is written inside an implementation marked as `#[abi(embed_v0)]`. + // However, it can't modify the contract's state, as it is passed as a snapshot // -> It's only a "view" function. fn get(self: @ContractState) -> u32 { // We can call an internal function from any functions within the contract @@ -34,7 +34,7 @@ pub mod ExampleContract { } } - // The lack of the `external` attribute indicates that all the functions in + // The lack of the `#[abi(embed_v0)]` attribute indicates that all the functions in // this implementation can only be called internally. // We name the trait `PrivateFunctionsTrait` to indicate that it is an // internal trait allowing us to call internal functions. @@ -43,7 +43,7 @@ pub mod ExampleContract { // The `_read_value` function is outside the implementation that is // marked as `#[abi(embed_v0)]`, so it's an _internal_ function // and can only be called from within the contract. - // However, it can't modify the contract's state is passed + // However, it can't modify the contract's state, as it is passed // as a snapshot: it is only a "view" function. fn _read_value(self: @ContractState) -> u32 { self.value.read() diff --git a/po/es.po b/po/es.po index 6693ade5..2108a25c 100644 --- a/po/es.po +++ b/po/es.po @@ -426,11 +426,11 @@ msgstr "" #: src/ch00/basics/storage.md:29 msgid "" -"> Actually these two contracts have the same underlying sierra program.\n" +"> Actually these two contracts have the same underlying Sierra program.\n" "> From the compiler's perspective, the storage variables don't exist until " "they are used." msgstr "" -"> En realidad estos dos contratos tienen el mismo programa sierra " +"> En realidad estos dos contratos tienen el mismo programa Sierra " "subyacente.\n" "> Desde la perspectiva del compilador, las variables de almacenamiento no " "existen hasta que se utilizan." @@ -1004,14 +1004,14 @@ msgid "" " }\n" "\n" "\n" -" // The `abi(embed_v0)` attribute indicates that all the functions in " +" // The `#[abi(embed_v0)]` attribute indicates that all the functions in " "this implementation can be called externally.\n" " // Omitting this attribute would make all the functions in this " "implementation internal.\n" " #[abi(embed_v0)]\n" " impl ExampleContract of super::IExampleContract {\n" " // The `set` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" +"inside an implementation marked as `#[abi(embed_v0)]`.\n" " // It can modify the contract's state as it is passed as a " "reference.\n" " fn set(ref self: ContractState, value: u32) {\n" @@ -1019,8 +1019,8 @@ msgid "" " }\n" "\n" " // The `get` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" -" // However, it can't modify the contract's state is passed as a " +"inside an implementation marked as `#[abi(embed_v0)]`.\n" +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn get(self: @ContractState) -> u32 {\n" " // We can call an internal function from any functions within " @@ -1038,7 +1038,7 @@ msgid "" " // The `_read_value` function is outside the implementation that is " "marked as `#[abi(embed_v0)]`, so it's an _internal_ function\n" " // and can only be called from within the contract.\n" -" // However, it can't modify the contract's state is passed as a " +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn _read_value(self: @ContractState) -> u32 {\n" " self.value.read()\n" @@ -1062,14 +1062,14 @@ msgstr "" " }\n" "\n" "\n" -" // The `abi(embed_v0)` attribute indicates that all the functions in " +" // The `#[abi(embed_v0)]` attribute indicates that all the functions in " "this implementation can be called externally.\n" " // Omitting this attribute would make all the functions in this " "implementation internal.\n" " #[abi(embed_v0)]\n" " impl ExampleContract of super::IExampleContract {\n" " // The `set` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" +"inside an implementation marked as `#[abi(embed_v0)]`.\n" " // It can modify the contract's state as it is passed as a " "reference.\n" " fn set(ref self: ContractState, value: u32) {\n" @@ -1077,8 +1077,8 @@ msgstr "" " }\n" "\n" " // The `get` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" -" // However, it can't modify the contract's state is passed as a " +"inside an implementation marked as `#[abi(embed_v0)]`.\n" +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn get(self: @ContractState) -> u32 {\n" " // We can call an internal function from any functions within " @@ -1096,7 +1096,7 @@ msgstr "" " // The `_read_value` function is outside the implementation that is " "marked as `#[abi(embed_v0)]`, so it's an _internal_ function\n" " // and can only be called from within the contract.\n" -" // However, it can't modify the contract's state is passed as a " +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn _read_value(self: @ContractState) -> u32 {\n" " self.value.read()\n" @@ -1298,7 +1298,7 @@ msgid "" "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/Smart_Contracts/contract-" -"storage/#storage_variables)" +"storage/#storage_variables)." msgstr "" "- Son posibles asignaciones key-value más complejas; por ejemplo, podríamos " "usar `LegacyMap::<(ContractAddress, ContractAddress), Felt252>` para crear " @@ -1310,7 +1310,7 @@ msgstr "" "información sobre el diseño de almacenamiento por contrato en la " "[Documentación de Starknet](https://docs.starknet.io/documentation/" "architecture_and_concepts/Smart_Contracts/contract-storage/" -"#storage_variables)" +"#storage_variables)." #: src/ch00/basics/mappings.md:13 msgid "" @@ -4910,12 +4910,12 @@ msgstr "# Match" #: src/ch00/cairo_cheatsheet/match.md:3 msgid "" -"The \"match\" expression in Cairo allows us to control the flow of our code " -"by comparing a felt data type or an enum against various patterns and then " +"The `match` expression in Cairo allows us to control the flow of our code " +"by comparing a `felt252` data type or an enum against various patterns and then " "running specific code based on the pattern that matches.\n" "For example:" msgstr "" -"La expresión \"match\" en Cairo nos permite controlar el flujo de nuestro " +"La expresión `match` en Cairo nos permite controlar el flujo de nuestro " "código comparando un tipo de datos sentido o una enumeración con varios " "patrones y luego ejecutando código específico basado en el patrón que " "coincide.\n" @@ -5158,7 +5158,7 @@ msgid "" " let new_u256: u256 = my_felt252.into();\n" " let new_felt252: felt252 = new_u16.into();\n" "\n" -" //note a usize is smaller than a felt so we use the try_into\n" +" // Note: usize is smaller than felt252, so we use try_into\n" " let new_usize: usize = my_felt252.try_into().unwrap();\n" "```" msgstr "" @@ -5188,7 +5188,7 @@ msgstr "" " let new_u256: u256 = my_felt252.into();\n" " let new_felt252: felt252 = new_u16.into();\n" "\n" -" //note a usize is smaller than a felt so we use the try_into\n" +" // Note: usize is smaller than felt252, so we use try_into\n" " let new_usize: usize = my_felt252.try_into().unwrap();\n" "```" @@ -11071,36 +11071,36 @@ msgstr "" #~ "pasamos por referencia así: `ref self: ContractState`." #~ msgid "" -#~ "// The `abi(embed_v0)` attribute indicates that all the functions in this " +#~ "// The `#[abi(embed_v0)]` attribute indicates that all the functions in this " #~ "implementation can be called externally.\n" #~ " // Omitting this attribute would make all the functions in this " #~ "implementation internal.\n" #~ msgstr "" -#~ "// The `abi(embed_v0)` attribute indicates that all the functions in this " +#~ "// The `#[abi(embed_v0)]` attribute indicates that all the functions in this " #~ "implementation can be called externally.\n" #~ " // Omitting this attribute would make all the functions in this " #~ "implementation internal.\n" #~ msgid "" #~ "// The `set` function can be called externally because it is written " -#~ "inside an implementation marked as `#[external]`.\n" +#~ "inside an implementation marked as `#[abi(embed_v0)]`.\n" #~ " // It can modify the contract's state as it is passed as a " #~ "reference.\n" #~ msgstr "" #~ "// The `set` function can be called externally because it is written " -#~ "inside an implementation marked as `#[external]`.\n" +#~ "inside an implementation marked as `#[abi(embed_v0)]`.\n" #~ " // It can modify the contract's state as it is passed as a " #~ "reference.\n" #~ msgid "" #~ "// The `get` function can be called externally because it is written " -#~ "inside an implementation marked as `#[external]`.\n" -#~ " // However, it can't modify the contract's state is passed as a " +#~ "inside an implementation marked as `#[abi(embed_v0)]`.\n" +#~ " // However, it can't modify the contract's state, as it is passed as a " #~ "snapshot: it is only a \"view\" function.\n" #~ msgstr "" #~ "// The `get` function can be called externally because it is written " -#~ "inside an implementation marked as `#[external]`.\n" -#~ " // However, it can't modify the contract's state is passed as a " +#~ "inside an implementation marked as `#[abi(embed_v0)]`.\n" +#~ " // However, it can't modify the contract's state, as it is passed as a " #~ "snapshot: it is only a \"view\" function.\n" #~ msgid "" @@ -11125,13 +11125,13 @@ msgstr "" #~ "// The `_read_value` function is outside the implementation that is " #~ "marked as `#[abi(embed_v0)]`, so it's an _internal_ function\n" #~ " // and can only be called from within the contract.\n" -#~ " // However, it can't modify the contract's state is passed as a " +#~ " // However, it can't modify the contract's state, as it is passed as a " #~ "snapshot: it is only a \"view\" function.\n" #~ msgstr "" #~ "// The `_read_value` function is outside the implementation that is " #~ "marked as `#[abi(embed_v0)]`, so it's an _internal_ function\n" #~ " // and can only be called from within the contract.\n" -#~ " // However, it can't modify the contract's state is passed as a " +#~ " // However, it can't modify the contract's state, as it is passed as a " #~ "snapshot: it is only a \"view\" function.\n" #~ msgid "" @@ -11421,8 +11421,8 @@ msgstr "" #~ msgstr "" #~ "// Since a felt252 is smaller than a u256, we can use the into() method\n" -#~ msgid "//note a usize is smaller than a felt so we use the try_into\n" -#~ msgstr "//note a usize is smaller than a felt so we use the try_into\n" +#~ msgid "// Note: usize is smaller than felt252, so we use try_into\n" +#~ msgstr "// Note: usize is smaller than felt252, so we use try_into\n" #~ msgid "Modularity: Easily pluggable into multiple contracts." #~ msgstr "Modularidad: Fácilmente conectable a múltiples contratos." diff --git a/po/messages.pot b/po/messages.pot index 749a5ada..d59c19a2 100644 --- a/po/messages.pot +++ b/po/messages.pot @@ -291,7 +291,7 @@ msgstr "" #: src/ch00/basics/storage.md:29 msgid "" -"Actually these two contracts have the same underlying sierra program. From " +"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." msgstr "" @@ -583,7 +583,7 @@ msgstr "" #: src/ch00/basics/visibility-mutability.md:42 msgid "" -"// The `abi(embed_v0)` attribute indicates that all the functions in this " +"// The `#[abi(embed_v0)]` attribute indicates that all the functions in this " "implementation can be called externally.\n" " // Omitting this attribute would make all the functions in this " "implementation internal.\n" @@ -592,7 +592,7 @@ msgstr "" #: src/ch00/basics/visibility-mutability.md:46 msgid "" "// The `set` function can be called externally because it is written inside " -"an implementation marked as `#[external]`.\n" +"an implementation marked as `#[abi(embed_v0)]`.\n" " // It can modify the contract's state as it is passed as a " "reference.\n" msgstr "" @@ -600,8 +600,8 @@ msgstr "" #: src/ch00/basics/visibility-mutability.md:52 msgid "" "// The `get` function can be called externally because it is written inside " -"an implementation marked as `#[external]`.\n" -" // However, it can't modify the contract's state is passed as a " +"an implementation marked as `#[abi(embed_v0)]`.\n" +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" msgstr "" @@ -623,7 +623,7 @@ msgid "" "// The `_read_value` function is outside the implementation that is marked " "as `#[abi(embed_v0)]`, so it's an _internal_ function\n" " // and can only be called from within the contract.\n" -" // However, it can't modify the contract's state is passed as a " +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" msgstr "" @@ -719,7 +719,7 @@ msgid "" "`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)" +"Documentation](https://docs.starknet.io/documentation/architecture_and_concepts/Contracts/contract-storage/#storage_variables)." msgstr "" #: src/ch00/basics/mappings.md:28 @@ -1507,8 +1507,8 @@ msgstr "" #: src/ch00/cairo_cheatsheet/match.md:3 msgid "" -"The \"match\" expression in Cairo allows us to control the flow of our code " -"by comparing a felt data type or an enum against various patterns and then " +"The `match` expression in Cairo allows us to control the flow of our code " +"by comparing a `felt252` data type or an enum against various patterns and then " "running specific code based on the pattern that matches. For example:" msgstr "" @@ -1579,7 +1579,7 @@ msgid "// Since a felt252 is smaller than a u256, we can use the into() method\n msgstr "" #: src/ch00/cairo_cheatsheet/type_casting.md:29 -msgid "//note a usize is smaller than a felt so we use the try_into\n" +msgid "// Note: usize is smaller than felt252, so we use try_into\n" msgstr "" #: src/ch01/upgradeable_contract.md:3 diff --git a/po/zh-cn.po b/po/zh-cn.po index 26111fe2..a1b8bb7a 100644 --- a/po/zh-cn.po +++ b/po/zh-cn.po @@ -392,11 +392,11 @@ msgstr "" #: src/ch00/basics/storage.md:29 msgid "" -"> Actually these two contracts have the same underlying sierra program.\n" +"> Actually these two contracts have the same underlying Sierra program.\n" "> From the compiler's perspective, the storage variables don't exist until " "they are used." msgstr "" -"> 实际上,这两个合约的底层 sierra 程序是一样的。\n" +"> 实际上,这两个合约的底层 Sierra 程序是一样的。\n" "> 从编译器的角度来看,存储变量在使用之前是不存在的。" #: src/ch00/basics/storage.md:32 @@ -936,14 +936,14 @@ msgid "" " }\n" "\n" "\n" -" // The `abi(embed_v0)` attribute indicates that all the functions in this " +" // The `#[abi(embed_v0)]` attribute indicates that all the functions in this " "implementation can be called externally.\n" " // Omitting this attribute would make all the functions in this " "implementation internal.\n" " #[abi(embed_v0)]\n" " impl ExampleContract of super::IExampleContract {\n" " // The `set` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" +"inside an implementation marked as `#[abi(embed_v0)]`.\n" " // It can modify the contract's state as it is passed as a " "reference.\n" " fn set(ref self: ContractState, value: u32) {\n" @@ -951,8 +951,8 @@ msgid "" " }\n" "\n" " // The `get` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" -" // However, it can't modify the contract's state is passed as a " +"inside an implementation marked as `#[abi(embed_v0)]`.\n" +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn get(self: @ContractState) -> u32 {\n" " // We can call an internal function from any functions within the " @@ -970,7 +970,7 @@ msgid "" " // The `_read_value` function is outside the implementation that is " "marked as `#[abi(embed_v0)]`, so it's an _internal_ function\n" " // and can only be called from within the contract.\n" -" // However, it can't modify the contract's state is passed as a " +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn _read_value(self: @ContractState) -> u32 {\n" " self.value.read()\n" @@ -994,14 +994,14 @@ msgstr "" " }\n" "\n" "\n" -" // The `abi(embed_v0)` attribute indicates that all the functions in this " +" // The `#[abi(embed_v0)]` attribute indicates that all the functions in this " "implementation can be called externally.\n" " // Omitting this attribute would make all the functions in this " "implementation internal.\n" " #[abi(embed_v0)]\n" " impl ExampleContract of super::IExampleContract {\n" " // The `set` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" +"inside an implementation marked as `#[abi(embed_v0)]`.\n" " // It can modify the contract's state as it is passed as a " "reference.\n" " fn set(ref self: ContractState, value: u32) {\n" @@ -1009,8 +1009,8 @@ msgstr "" " }\n" "\n" " // The `get` function can be called externally because it is written " -"inside an implementation marked as `#[external]`.\n" -" // However, it can't modify the contract's state is passed as a " +"inside an implementation marked as `#[abi(embed_v0)]`.\n" +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn get(self: @ContractState) -> u32 {\n" " // We can call an internal function from any functions within the " @@ -1028,7 +1028,7 @@ msgstr "" " // The `_read_value` function is outside the implementation that is " "marked as `#[abi(embed_v0)]`, so it's an _internal_ function\n" " // and can only be called from within the contract.\n" -" // However, it can't modify the contract's state is passed as a " +" // However, it can't modify the contract's state, as it is passed as a " "snapshot: it is only a \"view\" function.\n" " fn _read_value(self: @ContractState) -> u32 {\n" " self.value.read()\n" @@ -3672,12 +3672,12 @@ msgstr "# 分支" #: src/ch00/cairo_cheatsheet/match.md:3 msgid "" -"The \"match\" expression in Cairo allows us to control the flow of our code " -"by comparing a felt data type or an enum against various patterns and then " +"The `match` expression in Cairo allows us to control the flow of our code " +"by comparing a `felt252` data type or an enum against various patterns and then " "running specific code based on the pattern that matches.\n" "For example:" msgstr "" -"在 Cairo 中,”match” 表达式允许我们通过将 felt 数据类型或枚举与各种模式进行比" +"在 Cairo 中,`match` 表达式允许我们通过将 `felt252` 数据类型或枚举与各种模式进行比" "较,然后根据匹配的模式运行特定的代码来控制代码的流程。例如:" #: src/ch00/cairo_cheatsheet/match.md:6 @@ -3911,7 +3911,7 @@ msgid "" " let new_u256: u256 = my_felt252.into();\n" " let new_felt252: felt252 = new_u16.into();\n" "\n" -" //note a usize is smaller than a felt so we use the try_into\n" +" // Note: usize is smaller than felt252, so we use try_into\n" " let new_usize: usize = my_felt252.try_into().unwrap();\n" "```" msgstr "" diff --git a/src/ch00/basics/bytearrays-strings.md b/src/ch00/basics/bytearrays-strings.md index 7c864065..5b882065 100644 --- a/src/ch00/basics/bytearrays-strings.md +++ b/src/ch00/basics/bytearrays-strings.md @@ -9,11 +9,11 @@ Each character is encoded on 8 bits following the ASCII standard, so it's possib Short strings are declared with single quotes, like this: `'Hello, World!'`. See the [Felt](../cairo_cheatsheet/felt.md) section for more information about short strings with the `felt252` type. -> Notice that any short string only use up to 31 bytes, so it's possible to represent any short string with the `bytes31`. +> Notice that any short string only use up to 31 bytes, so it's possible to represent any short string with `bytes31`. ## ByteArray (Long strings) -The `ByteArray` struct is used to store strings of arbitrary length. It contain a field `data` of type `Array` to store a sequence of short strings. +The `ByteArray` struct is used to store strings of arbitrary length. It contains a field `data` of type `Array` to store a sequence of short strings. ByteArrays are declared with double quotes, like this: `"Hello, World!"`. diff --git a/src/ch00/basics/custom-types-in-entrypoints.md b/src/ch00/basics/custom-types-in-entrypoints.md index 0cac2514..c3bf484d 100644 --- a/src/ch00/basics/custom-types-in-entrypoints.md +++ b/src/ch00/basics/custom-types-in-entrypoints.md @@ -3,9 +3,8 @@ Using custom types in entrypoints requires our type to implement the `Serde` trait. This is because when calling an entrypoint, the input is sent as an array of `felt252` to the entrypoint, and we need to be able to deserialize it into our custom type. Similarly, when returning a custom type from an entrypoint, we need to be able to serialize it into an array of `felt252`. Thankfully, we can just derive the `Serde` trait for our custom type. -The purpose is to only show the capability of using custom types as inputs and outputs in contract calls. -We are not employing getters and setters for managing the contract's state in this example for simplicity. - ```rust {{#rustdoc_include ../../../listings/getting-started/custom_type_serde/src/contract.cairo:contract}} ``` + +> Note: The purpose of this example is to demonstrate the ability to use custom types as inputs and outputs in contract calls. For simplicity, we are not using getters and setters to manage the contract's state. diff --git a/src/ch00/basics/documentation.md b/src/ch00/basics/documentation.md index 41c25f16..ff8a2eb3 100644 --- a/src/ch00/basics/documentation.md +++ b/src/ch00/basics/documentation.md @@ -1,14 +1,14 @@ # Documentation -It's important to take the time to document your code. It will helps developers and users to understand the contract and its functionalities. +It's important to take the time to document your code. It will help developers and users to understand the contract and its functionalities. In Cairo, you can add comments with `//`. -### Best Practices: +### Best Practices Since Cairo 1, the community has adopted a [Rust-like documentation style](https://doc.rust-lang.org/rust-by-example/meta/doc.html). -### Contract Interface: +### Contract Interface In smart contracts, you will often have a trait that defines the contract's interface (with `#[starknet::interface]`). This is the perfect place to include detailed documentation explaining the purpose and functionality of the contract entry points. You can follow this template: @@ -32,8 +32,8 @@ trait IContract { Keep in mind that this should not describe the implementation details of the function, but rather the high-level purpose and functionality of the contract from the perspective of a user. -### Implementation Details: +### Implementation Details -When writing the logic of the contract, you can add comments to describe the technical implementation details of the functions. +When writing the contract logic, you can add comments to describe the technical implementation details of the functions. > Avoid over-commenting: Comments should provide additional value and clarity. diff --git a/src/ch00/basics/errors.md b/src/ch00/basics/errors.md index 73ae940c..31006283 100644 --- a/src/ch00/basics/errors.md +++ b/src/ch00/basics/errors.md @@ -9,11 +9,11 @@ To throw an error, use the `assert` or `panic` functions: If the check fails, an error is thrown along with a specified value, often a message. It's similar to the `require` statement in Solidity. -- `panic` immediately halt the execution with the given error value. - It should be used when the condition to check is complex and for internal errors. It's similar to the `revert` statement in Solidity. - (Use `panic_with_felt252` to be able to directly pass a felt252 as the error value) +- `panic` immediately halts the execution with the given error value. + It should be used for complex condition checks and for internal errors. It's similar to the `revert` statement in Solidity. + You can use `panic_with_felt252` to directly pass a `felt252` as the error value. -The `assert_eq!`, `assert_ne!`, `assert_lt!`, `assert_le!`, `assert_gt!` and `assert_ge!` macros can be used as an `assert` shorthand to compare two values, but **only** in tests. In contract, you should only use the `assert` function. +The `assert_eq!`, `assert_ne!`, `assert_lt!`, `assert_le!`, `assert_gt!` and `assert_ge!` macros can be used as an `assert` shorthand to compare two values, but **only** in tests. In contracts, you should only use the `assert` function. Here's a simple example that demonstrates the use of these functions: diff --git a/src/ch00/basics/events.md b/src/ch00/basics/events.md index 4e0791aa..8b6ca2a5 100644 --- a/src/ch00/basics/events.md +++ b/src/ch00/basics/events.md @@ -1,9 +1,9 @@ # Events Events are a way to emit data from a contract. All events must be defined in the `Event` enum, which must be annotated with the `#[event]` attribute. -An event is defined as a struct that derives the `#[starknet::Event]` trait. The fields of that struct correspond to the data that will be emitted. An event can be indexed for easy and fast access when querying the data at a later time, by adding a `#[key]` attribute to a field member. +An event is defined as a struct that derives the `starknet::Event` trait. The fields of that struct correspond to the data that will be emitted. An event can be indexed for easy and fast access when querying the data at a later time by adding a `#[key]` attribute to a field member. -Here's a simple example of a contract using events that emit an event each time a counter is incremented by the "increment" function: +Here's a simple example of a contract that emits an event each time a counter is incremented by the `increment` function: ```rust {{#rustdoc_include ../../../listings/getting-started/events/src/counter.cairo:contract}} diff --git a/src/ch00/basics/mappings.md b/src/ch00/basics/mappings.md index adf55eca..db0b6825 100644 --- a/src/ch00/basics/mappings.md +++ b/src/ch00/basics/mappings.md @@ -8,8 +8,7 @@ Some additional notes: - More complex key-value mappings are possible, for example we could use `LegacyMap::<(ContractAddress, ContractAddress), felt252>` to create an allowance on an ERC20 token contract. -- 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/Smart_Contracts/contract-storage/#storage_variables) - +- 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 \\( \bmod {2^{251}} - 256 \\). You can learn more about the contract storage layout in the [Starknet Documentation](https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/contract-storage/#storage_variables). ```rust {{#rustdoc_include ../../../listings/getting-started/mappings/src/mappings.cairo:contract}} diff --git a/src/ch00/basics/storage.md b/src/ch00/basics/storage.md index fd8b1d1e..b3f7f3e5 100644 --- a/src/ch00/basics/storage.md +++ b/src/ch00/basics/storage.md @@ -15,7 +15,7 @@ You can define [storage variables](./variables.md#storage-variables) in your con {{#rustdoc_include ../../../listings/getting-started/storage/src/contract.cairo:contract}} ``` -> Actually these two contracts have the same underlying sierra program. +> 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) +You can also read about [storing custom types](./storing-custom-types.md). diff --git a/src/ch00/basics/storing-custom-types.md b/src/ch00/basics/storing-custom-types.md index 24cd3c79..ed96f088 100644 --- a/src/ch00/basics/storing-custom-types.md +++ b/src/ch00/basics/storing-custom-types.md @@ -1,6 +1,6 @@ # Storing Custom Types -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. +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. It is enough to just derive this trait, unless our custom type contains arrays or dictionaries. ```rust {{#rustdoc_include ../../../listings/getting-started/storing_custom_types/src/contract.cairo:contract}} diff --git a/src/ch00/basics/syscalls.md b/src/ch00/basics/syscalls.md index 7a4fc336..cddc5e7f 100644 --- a/src/ch00/basics/syscalls.md +++ b/src/ch00/basics/syscalls.md @@ -7,6 +7,7 @@ Some of the OS functionalities are exposed to smart contracts through the use of Syscalls return a `SyscallResult` which is either `Sucess` of `Failure`, allowing the contract to handle errors. Here's the available syscalls: + - [get_block_hash](#get_block_hash) - [get_execution_info](#get_execution_info) - [call_contract](#call_contract) @@ -91,6 +92,7 @@ pub struct TxInfo { ``` `starknet::info` provides helper functions to access the `ExecutionInfo` fields in a more convenient way: + - `get_execution_info() -> Box` - `get_caller_address() -> ContractAddress` - `get_contract_address() -> ContractAddress` @@ -108,9 +110,9 @@ fn call_contract_syscall( ``` Call a contract at `address` with the given `entry_point_selector` and `calldata`. -Failure can't be caught for this syscall, if the call fails, the whole transaction will revert. +Failure can't be caught for this syscall, and if the call fails, the whole transaction will revert. -This is not the recommended way to call a contract. Instead, use the dispatcher generated from the contract interface as shown in the [Calling other contracts](../interacting/calling_other_contracts.md). +This is not the recommended way to call a contract. Instead, use the dispatcher generated from the contract interface as shown in the [Calling other contracts](../interacting/calling_other_contracts.md) chapter. @@ -206,7 +208,7 @@ This is used for contract upgrades. Here's an example from the [Upgradeable Cont ``` The new class code will only be used for future calls to the contract. -The current transaction containing the `replace_class` syscall will continue to use the old class code. (You can explicitly use the new class code by calling `call_contract` after the `replace_class` syscall in the same transaction) +The current transaction containing the `replace_class` syscall will continue to use the old class code. Note that you can explicitly use the new class code in the same transaction by calling `call_contract` after the `replace_class` syscall. #### storage_read @@ -233,7 +235,7 @@ Similar to `storage_read`, this low-level syscall is used to write the value `va ## Documentation -Syscalls are defined in [`starknet::syscall`](https://github.com/starkware-libs/cairo/blob/ec14a5e2c484190ff40811c973a72a53739cedb7/corelib/src/starknet/syscalls.cairo) +Syscalls are defined in [`starknet::syscall`](https://github.com/starkware-libs/cairo/blob/ec14a5e2c484190ff40811c973a72a53739cedb7/corelib/src/starknet/syscalls.cairo). You can also read the [official documentation page](https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/system-calls-cairo1/) for more details. @@ -267,5 +269,5 @@ mod gas_costs { } ``` -Specific gas cost are defined in this [file](https://github.com/starkware-libs/cairo/blob/ec14a5e2c484190ff40811c973a72a53739cedb7/crates/cairo-lang-runner/src/casm_run/mod.rs#L333) +Specific gas cost are defined in this [file](https://github.com/starkware-libs/cairo/blob/ec14a5e2c484190ff40811c973a72a53739cedb7/crates/cairo-lang-runner/src/casm_run/mod.rs#L333) --> diff --git a/src/ch00/basics/variables.md b/src/ch00/basics/variables.md index abcab571..ff9a785f 100644 --- a/src/ch00/basics/variables.md +++ b/src/ch00/basics/variables.md @@ -30,7 +30,7 @@ Storage variables are persistent data stored on the blockchain. They can be acce To write or update a storage variable, you need to interact with the contract through an external entrypoint by sending a transaction. -On the other hand, you can read state variables, for free, without any transaction, simply by interacting with a node. +On the other hand, you can read state variables for free, without any transaction, simply by interacting with a node. Here's a simple example of a contract with one storage variable: @@ -42,7 +42,7 @@ Here's a simple example of a contract with one storage variable: Global variables are predefined variables that provide information about the blockchain and the current execution environment. They can be accessed at any time and from anywhere! -In Starknet, you can access global variables by using specific functions from the starknet core library. +In Starknet, you can access global variables by using specific functions from the Starknet core library. 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. diff --git a/src/ch00/basics/visibility-mutability.md b/src/ch00/basics/visibility-mutability.md index bbaa5f59..c7ec4301 100644 --- a/src/ch00/basics/visibility-mutability.md +++ b/src/ch00/basics/visibility-mutability.md @@ -7,18 +7,18 @@ There are two types of functions in Starknet contracts: - Functions that are accessible externally and can be called by anyone. - Functions that are only accessible internally and can only be called by other functions in the contract. -These functions are also typically divided into two different implementations blocks. The first `impl` block for externally accessible functions is explicitly annotated with an `#[abi(embed_v0)]` attribute. This indicates that all the functions inside this block can be called either as a transaction or as a view function. The second `impl` block for internally accessible functions is not annotated with any attribute, which means that all the functions inside this block are private by default. +These functions are also typically divided into two different implementation blocks. The first `impl` block for externally accessible functions is explicitly annotated with an `#[abi(embed_v0)]` attribute. This indicates that all the functions inside this block can be called either as a transaction or as a view function. The second `impl` block for internally accessible functions is not annotated with any attribute, which means that all the functions inside this block are private by default. ## State Mutability Regardless of whether a function is internal or external, it can either modify the contract's state or not. When we declare functions that interact with storage variables inside a smart contract, we need to explicitly state that we are accessing the `ContractState` by adding it as the first parameter of the function. This can be done in two different ways: -- If we want our function to be able to mutate the state of the contract, we pass it by reference like this: `ref self: ContractState`. -- If we want our function to be read-only and not mutate the state of the contract, we pass it by snapshot like this: `self: @ContractState`. +- If we want our function to be able to mutate the state of the contract, we pass it by reference like this: `ref self: ContractState` +- If we want our function to be read-only and not mutate the state of the contract, we pass it by snapshot like this: `self: @ContractState` -Read-only functions, also called view functions, can be directly called without making a transaction. You can interact with them directly through a RPC node to read the contract's state, and they're free to call! -External functions, that modify the contract's state, on the other side can only be called by making a transaction. +Read-only functions, also called view functions, can be directly called without making a transaction. You can interact with them directly through an RPC node to read the contract's state, and they're free to call! +External functions, that modify the contract's state, on the other hand, can only be called by making a transaction. Internal functions can't be called externally, but the same principle applies regarding state mutability. diff --git a/src/ch00/cairo_cheatsheet/felt.md b/src/ch00/cairo_cheatsheet/felt.md index 1caa710e..6f1bd841 100644 --- a/src/ch00/cairo_cheatsheet/felt.md +++ b/src/ch00/cairo_cheatsheet/felt.md @@ -1,7 +1,7 @@ -# Felt252 +# Felt -Felt252 is a fundamental data type in Cairo from which all other data types are derived. -Felt252 can also be used to store [short string representations](../basics/bytearrays-strings.md#short-strings) with a maximum length of 31 characters. +`felt252` is a fundamental data type in Cairo from which all other data types are derived. +`felt252` can also be used to store [short string representations](../basics/bytearrays-strings.md#short-strings) with a maximum length of 31 characters. For example: diff --git a/src/ch00/cairo_cheatsheet/loop.md b/src/ch00/cairo_cheatsheet/loop.md index 2f3a92de..cdaf96ff 100644 --- a/src/ch00/cairo_cheatsheet/loop.md +++ b/src/ch00/cairo_cheatsheet/loop.md @@ -1,6 +1,7 @@ # `loop` A `loop` specifies a block of code that will run repetitively until a halting condition is encountered. + For example: ```rust diff --git a/src/ch00/cairo_cheatsheet/mapping.md b/src/ch00/cairo_cheatsheet/mapping.md index a177c6c4..b9ece39e 100644 --- a/src/ch00/cairo_cheatsheet/mapping.md +++ b/src/ch00/cairo_cheatsheet/mapping.md @@ -1,6 +1,6 @@ -# Mapping +# `LegacyMap` -The ```LegacyMap``` type can be used to represent a collection of key-value. +The `LegacyMap` type can be used to represent a collection of key-value. ```rust {{#include ../../../listings/getting-started/cairo_cheatsheet/src/mapping_example.cairo}} diff --git a/src/ch00/cairo_cheatsheet/match.md b/src/ch00/cairo_cheatsheet/match.md index dfb127b9..d5a7b2f4 100644 --- a/src/ch00/cairo_cheatsheet/match.md +++ b/src/ch00/cairo_cheatsheet/match.md @@ -1,6 +1,7 @@ # Match -The "match" expression in Cairo allows us to control the flow of our code by comparing a felt data type or an enum against various patterns and then running specific code based on the pattern that matches. +The `match` expression in Cairo allows us to control the flow of our code by comparing a `felt252` data type or an enum against various patterns and then running specific code based on the pattern that matches. + For example: ```rust diff --git a/src/ch00/cairo_cheatsheet/struct.md b/src/ch00/cairo_cheatsheet/struct.md index d5fe295f..768c813a 100644 --- a/src/ch00/cairo_cheatsheet/struct.md +++ b/src/ch00/cairo_cheatsheet/struct.md @@ -1,6 +1,7 @@ # Struct -A struct is a data type similar to tuple. Like tuples they can be used to hold data of different types. +A struct is a data type similar to a tuple. Like tuples, they can be used to hold data of different types. + For example: ```rust diff --git a/src/ch00/cairo_cheatsheet/tuples.md b/src/ch00/cairo_cheatsheet/tuples.md index 2b82bd43..b3218b67 100644 --- a/src/ch00/cairo_cheatsheet/tuples.md +++ b/src/ch00/cairo_cheatsheet/tuples.md @@ -1,6 +1,7 @@ # Tuples Tuples is a data type to group a fixed number of items of potentially different types into a single compound structure. Unlike arrays, tuples have a set length and can contain elements of varying types. Once a tuple is created, its size cannot change. + For example: ```rust diff --git a/src/ch00/cairo_cheatsheet/type_casting.md b/src/ch00/cairo_cheatsheet/type_casting.md index f6a143d9..7e78d891 100644 --- a/src/ch00/cairo_cheatsheet/type_casting.md +++ b/src/ch00/cairo_cheatsheet/type_casting.md @@ -1,7 +1,8 @@ # Type casting -Cairo supports the conversion from one scalar types to another by using the into and try_into methods. -`traits::Into` is used for conversion from a smaller data type to a larger data type, while `traits::TryInto` is used when converting from a larger to a smaller type that might not fit. +Cairo supports the conversion from one scalar type to another by using the `into` and `try_into` methods. +The `into` method is used for conversion from a smaller data type to a larger data type, while `try_into` is used when converting from a larger to a smaller type that might not fit. + For example: ```rust diff --git a/src/ch00/cairo_cheatsheet/while.md b/src/ch00/cairo_cheatsheet/while.md index 97cb1bed..51c91602 100644 --- a/src/ch00/cairo_cheatsheet/while.md +++ b/src/ch00/cairo_cheatsheet/while.md @@ -8,4 +8,5 @@ A `while` loop allows you to specify a condition that must be true for the loop ### See also -[loop](loop.md) +- [loop](loop.md) +- [while let](while_let.md) diff --git a/src/ch00/cairo_cheatsheet/while_let.md b/src/ch00/cairo_cheatsheet/while_let.md index 4f9c4caa..90eda4b3 100644 --- a/src/ch00/cairo_cheatsheet/while_let.md +++ b/src/ch00/cairo_cheatsheet/while_let.md @@ -8,4 +8,5 @@ A `while let` loop is a combination of a `while` loop and a `let` statement. It ### See also -[while](while.md) +- [while](while.md) +- [if let](if_let.md) diff --git a/src/ch00/interacting/calling_other_contracts.md b/src/ch00/interacting/calling_other_contracts.md index 62f02078..c9b3d89c 100644 --- a/src/ch00/interacting/calling_other_contracts.md +++ b/src/ch00/interacting/calling_other_contracts.md @@ -3,9 +3,9 @@ There are two different ways to call other contracts in Cairo. The easiest way to call other contracts is by using the dispatcher of the contract you want to call. -You can read more about Dispatchers in the [Cairo Book](https://book.cairo-lang.org/ch99-02-02-contract-dispatcher-library-dispatcher-and-system-calls.html#contract-dispatcher) +You can read more about Dispatchers in the [Cairo Book](https://book.cairo-lang.org/ch99-02-02-contract-dispatcher-library-dispatcher-and-system-calls.html#contract-dispatcher). -The other way is to use the `starknet::call_contract_syscall` syscall yourself. However, this method is not recommended and will not be covered in this example. +The other way is to use the `starknet::call_contract_syscall` syscall yourself. However, this method is not recommended and will not be covered in this chapter. 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. @@ -15,7 +15,7 @@ Here's the `Callee` contract interface and implementation: {{#rustdoc_include ../../../listings/getting-started/calling_other_contracts/src/caller.cairo:callee_contract}} ``` -The following `Caller` contract use the `Callee` interface to call the `Callee` contract: +The following `Caller` contract uses the `Callee` dispatcher to call the `Callee` contract: ```rust {{#rustdoc_include ../../../listings/getting-started/calling_other_contracts/src/caller.cairo:caller_contract}} diff --git a/src/ch00/interacting/factory.md b/src/ch00/interacting/factory.md index 4d5c8baa..76e503a6 100644 --- a/src/ch00/interacting/factory.md +++ b/src/ch00/interacting/factory.md @@ -1,8 +1,8 @@ # Factory Pattern -The factory pattern is a well known pattern in object oriented programming. It provides an abstraction on how to instantiate a class. +The factory pattern is a well known pattern in object oriented programming. It provides an abstraction on how to instantiate a class. -In the case of smart contracts, we can use this pattern by defining a factory contract that have the sole responsibility of creating and managing other contracts. +In the case of smart contracts, we can use this pattern by defining a factory contract that has the sole responsibility of creating and managing other contracts. ## Class hash and contract instance @@ -14,7 +14,7 @@ Using the factory pattern, we can deploy multiple instances of the same contract ## Minimal example -Here's a minimal example of a factory contract that deploy the `SimpleCounter` contract: +Here's a minimal example of a factory contract that deploys the `SimpleCounter` contract: ```rust {{#rustdoc_include ../../../listings/getting-started/factory/src/simple_factory.cairo:contract}} @@ -24,6 +24,6 @@ This factory can be used to deploy multiple instances of the `SimpleCounter` con The `SimpleCounter` class hash is stored inside the factory, and can be upgraded with the `update_counter_class_hash` function which allows to reuse the same factory contract when the `SimpleCounter` contract is upgraded. -This minimal example lacks several useful features such as access control, tracking of deployed contracts, events, ... +> Note: This minimal example lacks several useful features such as access control, tracking of deployed contracts, events etc. diff --git a/src/ch00/interacting/interfaces-traits.md b/src/ch00/interacting/interfaces-traits.md index f9b49cb7..54a2e591 100644 --- a/src/ch00/interacting/interfaces-traits.md +++ b/src/ch00/interacting/interfaces-traits.md @@ -2,15 +2,15 @@ Contract interfaces define the structure and behavior of a contract, serving as the contract's public ABI. They list all the function signatures that a contract exposes. For a detailed explanation of interfaces, you can refer to the [Cairo Book](https://book.cairo-lang.org/ch99-01-02-a-simple-contract.html). -In cairo, to specify the interface you need to define a trait annotated with `#[starknet::interface]` and then implement that trait in the contract. +In Cairo, to specify the interface you need to define a trait annotated with `#[starknet::interface]` and then implement that trait in the contract. When a function needs to access the contract state, it must have a `self` parameter of type `ContractState`. This implies that the corresponding function signature in the interface trait must also take a `TContractState` type as a parameter. It's important to note that every function in the contract interface must have this `self` parameter of type `TContractState`. -You can use the `#[generate_trait]` attribute to implicitly generate the trait for a specific implementation block. This attribute automatically generates a trait with the same functions as the ones in the implemented block, replacing the `self` parameter with a generic `TContractState` parameter. However, you will need to annotate the block with the `#[abi(per_item)]` attribute, and each function with the appropriate attribute depending on whether it's an external function, a constructor or a l1 handler. +You can use the `#[generate_trait]` attribute to implicitly generate the trait for a specific implementation block. This attribute automatically generates a trait with the same functions as the ones in the implemented block, replacing the `self` parameter with a generic `TContractState` parameter. However, you will need to annotate the block with the `#[abi(per_item)]` attribute, and each function with the appropriate attribute depending on whether it's an external function, a constructor or an L1 handler. In summary, there's two ways to handle interfaces: -- Explicitly, by defining a trait annoted with `#[starknet::interface]` +- Explicitly, by defining a trait annotated with `#[starknet::interface]` - Implicitly, by using `#[generate_trait]` combined with the `#[abi(per_item)]` attributes, and annotating each function inside the implementation block with the appropriate attribute. ## Explicit interface diff --git a/src/ch00/testing/contract-testing.md b/src/ch00/testing/contract-testing.md index 5d9c3e0c..ae51404a 100644 --- a/src/ch00/testing/contract-testing.md +++ b/src/ch00/testing/contract-testing.md @@ -20,16 +20,16 @@ Each test is defined as a function with the `#[test]` attribute. You can also ch As we are in the context of a smart contract, you can also set up the gas limit for a test by using the `#[available_gas(X)]`. This is a great way to ensure that some of your contract's features stay under a certain gas limit! -> Note: The term "gas" here refers to Sierra gas, not L1 gas +> Note: The term "gas" here refers to Sierra gas, not L1 gas. Now, let's move on to the testing process: -- Use the `deploy` function logic to declare and deploy your contract. -- Use `assert` to verify that the contract behaves as expected in the given context. - - You can also use assertions macros: `assert_eq`, `assert_ne`, `assert_gt`, `assert_ge`, `assert_lt`, `assert_le` +- Use the `deploy` function logic to declare and deploy your contract +- Use `assert` to verify that the contract behaves as expected in the given context + - You can also use assertion macros: `assert_eq!`, `assert_ne!`, `assert_gt!`, `assert_ge!`, `assert_lt!`, `assert_le!` -If you didn't noticed yet, every examples in this book have hidden tests, you can see them by clicking on the "Show hidden lines" (eyes icon) on the top right of code blocks. -You can also find a detailed explanation of testing in cairo in the [Cairo book - Chapter 10](https://book.cairo-lang.org/ch10-00-testing-cairo-programs.html). +If you haven't noticed yet, every example in this book has hidden tests, you can see them by clicking the "Show hidden lines" (eyes icon) on the top right of code blocks. +You can also find a detailed explanation of testing in Cairo in [The Cairo Book](https://book.cairo-lang.org/ch10-00-testing-cairo-programs.html). ## Using the contract state @@ -82,12 +82,12 @@ You may also need the `info` module from the corelib, which allows you to access - `get_block_timestamp() -> u64` - `get_block_number() -> u64` -You can found the full list of functions in the [Starknet Corelib repo](https://github.com/starkware-libs/cairo/tree/main/corelib/src/starknet). +You can find the full list of functions in the [Starknet Corelib repo](https://github.com/starkware-libs/cairo/tree/main/corelib/src/starknet). ## Starknet Foundry Starknet Foundry is a powerful toolkit for developing smart contracts on Starknet. It offers support for testing Starknet smart contracts on top of `scarb` with the `Forge` tool. -Testing with `snforge` is similar to the process we just described but simplified. Moreover, additional features are on the way, including cheatcodes or parallel tests execution. We highly recommend exploring Starknet Foundry and incorporating it into your projects. +Testing with `snforge` is similar to the process we just described, but simplified. Moreover, additional features are on the way, including cheatcodes and parallel test execution. We highly recommend exploring Starknet Foundry and incorporating it into your projects. For more detailed information about testing contracts with Starknet Foundry, check out the [Starknet Foundry Book - Testing Contracts](https://foundry-rs.github.io/starknet-foundry/testing/contracts.html). diff --git a/src/starknet-by-example.md b/src/starknet-by-example.md index 8ab3b71a..962109c8 100644 --- a/src/starknet-by-example.md +++ b/src/starknet-by-example.md @@ -2,7 +2,7 @@ Starknet By Example is a collection of examples of how to use the Cairo programming language to create smart contracts on Starknet. -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 is a permissionless Validity-Rollup that supports general computation. It is currently used as an Ethereum layer-2. Starknet uses 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. @@ -20,9 +20,9 @@ The later chapters will cover more advanced topics and show you how to write mor Each chapter is a standalone example that demonstrates a specific feature or common use case of smart contracts on Starknet. If you are new to Starknet, it is recommended to read the chapters in order. -Most examples contains interfaces and tests that are hidden by default. You can hover over the code blocks and click on the "Show hidden lines" (eyes icon) to see the hidden code. +Most examples contain interfaces and tests that are hidden by default. You can hover over the code blocks and click on the "Show hidden lines" (eyes icon) to see the hidden code. -You can run each examples online by using the [Starknet Remix Plugin](https://remix.ethereum.org/?#activate=Starknet). +You can run each example online by using the [Starknet Remix Plugin](https://remix.ethereum.org/?#activate=Starknet). ## Further reading @@ -33,7 +33,8 @@ For more resources, check [Awesome Starknet](https://github.com/keep-starknet-st ## Versions -The current version of this book use: +The current version this book uses: + ``` cairo 2.6.3 edition = '2023_11'