Skip to content

Commit

Permalink
Merge branch 'main' of github.com:IntensiveCoLearning/starknet
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaopengjun5162 committed Sep 24, 2024
2 parents dd9cfee + fb71817 commit 9b516a0
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Ellen.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


<!-- Content_END -->
12 changes: 12 additions & 0 deletions Hansen.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ timezone: Asia/Shanghai
## Notes

<!-- Content_START -->
### 2024.09.23
听 线上的课程:starknet 工具链与开发环境
下一步目标,做一个合约,部署在测试链上。

- https://voyager.online/ stark 的浏览器
- 部署合约,可以用 starkli 命令行 ,也可以用js-sdk 方式 , 后者更简单
- address 是 account 的一个属性, 通过address 可以确定你的账号信息。 在部署合约的时候, 只有address 是不够的。
- 用“人”钱包,部署合约时, 先要 将账号 部署,




### 2024.09.22
今天 大概看了一下 , cairo 的语法,
安装了 scarb 包管理器
Expand Down
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ⭕️ | ⭕️ ||| | | | | | | | | | | | | | | | |
<!-- END_COMMIT_TABLE -->


Expand Down Expand Up @@ -218,6 +218,13 @@ Starknet 残酷共学是由 LXDAO、Starknet Astro、AAStar 联合发起,旨













Expand Down
35 changes: 35 additions & 0 deletions Reign.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project_name>`, 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 <project_name>`: Initialize a new project.
- `scarb build`: Compile the project into Sierra code.
- `scarb add <dependency> --git <repo>`: 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.





<!-- Content_END -->
175 changes: 175 additions & 0 deletions River.md
Original file line number Diff line number Diff line change
Expand Up @@ -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与递归不仅仅在概念上是等价的,同时通过编译在底层表达上也类似。
<!-- Content_END -->
2 changes: 2 additions & 0 deletions geyu.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


<!-- Content_END -->

0 comments on commit 9b516a0

Please sign in to comment.