diff --git a/Ellen.md b/Ellen.md index 1dfb6db..8caa880 100644 --- a/Ellen.md +++ b/Ellen.md @@ -24,4 +24,12 @@ ### 2024.09.22 - 学习 https://docs.openzeppelin.com/contracts-cairo/0.16.0/erc20 + +### 2024.09.23 +- 听分享部署合约 +- sncast account deploy --fee-token eth --name Test1 +- sncast --account Test1 declare --fee-token eth --contract-name HelloStarknet +- sncast deploy --class-hash 0x1a6835329277e9a402a747e041546d418cee105c2a8de41c6dd4930e80c8681 --fee-token eth + + diff --git a/Hansen.md b/Hansen.md index eed7dcd..73e11d4 100644 --- a/Hansen.md +++ b/Hansen.md @@ -11,6 +11,18 @@ timezone: Asia/Shanghai ## Notes +### 2024.09.23 +听 线上的课程:starknet 工具链与开发环境 +下一步目标,做一个合约,部署在测试链上。 + +- https://voyager.online/ stark 的浏览器 +- 部署合约,可以用 starkli 命令行 ,也可以用js-sdk 方式 , 后者更简单 +- address 是 account 的一个属性, 通过address 可以确定你的账号信息。 在部署合约的时候, 只有address 是不够的。 +- 用“人”钱包,部署合约时, 先要 将账号 部署, + + + + ### 2024.09.22 今天 大概看了一下 , cairo 的语法, 安装了 scarb 包管理器 diff --git a/README.md b/README.md index d85ebe1..3227a72 100644 --- a/README.md +++ b/README.md @@ -111,19 +111,19 @@ Starknet 残酷共学是由 LXDAO、Starknet Astro、AAStar 联合发起,旨 | Name | 9.18 | 9.19 | 9.20 | 9.21 | 9.22 | 9.23 | 9.24 | 9.25 | 9.26 | 9.27 | 9.28 | 9.29 | 9.30 | 10.01 | 10.02 | 10.03 | 10.04 | 10.05 | 10.06 | 10.07 | 10.08 | | ------------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | | Ache | ⭕️ | ⭕️ | ❌ | | | | | | | | | | | | | | | | | | | -| geyu | ⭕️ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | | -| aliyan404 | ✅ | ✅ | ✅ | ⭕️ | ✅ | ✅ | | | | | | | | | | | | | | | | -| Hansen | ✅ | ✅ | ⭕️ | ✅ | ✅ | | | | | | | | | | | | | | | | | -| Reign | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | -| qiaopengjun | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | -| Ric-Li-C | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | -| River | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | | -| awaqawaqawaq | ✅ | ✅ | ✅ | ⭕️ | ⭕️ | ✅ | | | | | | | | | | | | | | | | -| phipupt | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | -| MartinYeung5 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| geyu | ⭕️ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| aliyan404 | ✅ | ✅ | ✅ | ⭕️ | ✅ | ✅ | | | | | | | | | | | | | | | | +| Hansen | ✅ | ✅ | ⭕️ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| Reign | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| qiaopengjun | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| Ric-Li-C | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| River | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| awaqawaqawaq | ✅ | ✅ | ✅ | ⭕️ | ⭕️ | ✅ | | | | | | | | | | | | | | | | +| phipupt | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | +| MartinYeung5 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | | dethan3 | ✅ | ⭕️ | ✅ | ⭕️ | ❌ | | | | | | | | | | | | | | | | | | Cavn | ✅ | ✅ | ⭕️ | ⭕️ | ❌ | | | | | | | | | | | | | | | | | -| Ellen | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | | | | | | | | | | | | | | | | | +| Ellen | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | | @@ -218,6 +218,13 @@ Starknet 残酷共学是由 LXDAO、Starknet Astro、AAStar 联合发起,旨 + + + + + + + diff --git a/Reign.md b/Reign.md index fa87717..131878e 100644 --- a/Reign.md +++ b/Reign.md @@ -263,4 +263,39 @@ This chapter provides a guide for compiling, deploying, and interacting with a S - Convert new names to felt252 format before invoking. This chapter outlines the complete workflow for developing and managing Starknet smart contracts, focusing on ensuring compatibility between tools and providing practical commands for contract management. + + +### 2024.09.23 +### Summary of Scarb: The Package Manager + +**Scarb** is the package manager for Cairo and Starknet projects, handling dependencies, compiling projects, and streamlining the development process, similar to Rust's Cargo. Here's an overview of its usage: + +1. **Initialization and Workflow**: + - Set up a project with `scarb new `, which generates a `Scarb.toml` file and a `src/lib.cairo` file. + - Add dependencies directly in the `Scarb.toml` file or via the `scarb add` command. + - Compile projects into Sierra code using `scarb build`, producing an intermediate output for deployment to Starknet. + +2. **Project Structure**: + - A typical Cairo package includes a `Scarb.toml` file and a `src` directory containing `.cairo` files (e.g., `lib.cairo`). + - External libraries can be added via the `[dependencies]` section of `Scarb.toml`, specifying either registry or Git sources. + +3. **Components**: + - Starting with version 2.3.0, Scarb supports **Components**—modular add-ons that encapsulate reusable logic, storage, and events for smart contracts, allowing for easy extension of contract functionality. + +4. **Example**: + - A simple Cairo contract can be modularized using components, such as separating ownership logic into an `ownable_component` module and integrating it with the main contract. + +5. **Commands Cheat Sheet**: + - `scarb new `: Initialize a new project. + - `scarb build`: Compile the project into Sierra code. + - `scarb add --git `: Add a Git-hosted dependency. + - `scarb clean`: Remove build artifacts. + +6. **Version Changes**: + - Version 2.3.0 introduced JSON outputs for Sierra and CASM code and support for components. + + + + + diff --git a/River.md b/River.md index 9bfcf7b..a8dca42 100644 --- a/River.md +++ b/River.md @@ -493,6 +493,181 @@ fn plus_one(x: u32) -> u32 { } ~~~ +### 2024.09.23 + +#### 流程控制 + +##### if表达式 + +###### 常规写法 + +~~~rust +fn main() { + let number = 3; + + if number == 12 { + println!("number is 12"); + } else if number == 3 { + println!("number is 3"); + } else if number - 2 == 1 { + println!("number minus 2 is 1"); + } else { + println!("number not found"); + } +} +~~~ + +###### 在let语句中使用if + +~~~rust +fn main() { + let condition = true; + let number = if condition { + 5 + } else { + 6 + }; +} +~~~ + +##### 循环控制 + + 在`Cairo`中有三种Loop循环类型:`loop`、`while`、`for` + +###### `loop` + +* 常规 + + ~~~rust + fn main() { + loop { + println!("again!"); + } + } + ~~~ + +* 带有`break`关键字 + + ~~~rust + fn main() { + let mut i: usize = 0; + loop { + if i > 10 { + break; + } + println!("i = {}", i); + i += 1; + } + } + ~~~ + +* 带有`continue`关键字 + + ~~~rust + fn main() { + let mut i: usize = 0; + loop { + if i > 10 { + break; + } + if i == 5 { + i += 1; + continue; + } + println!("i = {}", i); + i += 1; + } + } + ~~~ + +* 带有返回值 + + ~~~rust + fn main() { + let mut counter = 0; + + let result = loop { + if counter == 10 { + break counter * 2; + } + counter += 1; + }; + println!("The result is {}", result); + } + ~~~ + +###### `while` + +~~~rust +fn main() { + let mut number = 3; + + while number != 0 { + println!("{number}!"); + number -= 1; + }; + + println!("LIFTOFF!!!"); +} +~~~ + +###### `for` + +~~~rust +fn main() { + let a = [10, 20, 30, 40, 50].span(); + + for element in a { + println!("the value is: {element}"); + } + + for number in 1..4_u8 { + println!("{number}!"); + }; +} +~~~ + +###### Loops与递归 + +Loops和递归是两种重复执行代码的方式。 + +* `loop`关键字用来创建一个无限循环,同时使用`break`关键字退出循环。 + + ~~~rust + fn main() -> felt252 { + let mut x: felt252 = 0; + loop { + if x == 2 { + break; + } else { + x += 1; + } + }; + x + } + ~~~ + +* 递归通过在函数内部调用自身来实现 + + ~~~rust + fn main() -> felt252 { + recursive_function(0) + } + + fn recursive_function(mut x: felt252) -> felt252 { + if x == 2 { + x + } else { + recursive_function(x + 1) + } + } + ~~~ + +在`Cairo`中,Loops与递归不仅仅在概念上是等价的,同时通过编译在底层表达上也类似。 + + + + diff --git a/geyu.md b/geyu.md index 983432e..63579df 100644 --- a/geyu.md +++ b/geyu.md @@ -26,6 +26,8 @@ fork 了 counter-workshop 通过了counter-workshop Step 3 ### 2024.09.22 通过了counter-workshop Step 4 +### 2024.09.23 +学习 https://docs.starknet.io/ 的文档,目前进度:Deploying a smart contract