Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
linghuccc committed Sep 25, 2024
2 parents ca49905 + f14ec0c commit 0a805a3
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 16 deletions.
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.24

学习 Starknet-js: Javascript SDK
- Starknet.js 是web 前端连接starknet 链的库。
- js-》 provider -》链

- Starknet accounts are contracts.
- The provider allows you to interact with the Starknet network.
- contracts: 合约地址 和 abi 接口

- Next.js是一个基于React的框架,构建服务器端渲染的应用程序。React仍然是应用程序的基础,但结构和导航机制--架构--是由Next.js定义的。

### 2024.09.23
听 线上的课程:starknet 工具链与开发环境
下一步目标,做一个合约,部署在测试链上。
Expand Down
84 changes: 84 additions & 0 deletions MartinYeung5.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,89 @@ download specific versions:
* katana --version
![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240924_9.png?raw=true)

### 2024.09.25
* initiating a Scarb project

* scarb new my_contract
![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_1.png?raw=true)

* update Scarb.toml
```
[package]
name = "my_contract"
version = "0.1.0"
edition = "2023_11"
[dependencies]
starknet = ">=2.5.4"
[[target.starknet-contract]]
```

有2個變數是必需要的,1個是starknet戶口,另一個是starknet代理: 用於設置使用網絡。
* 創建一個src/.env,
然後加入以下修改:
```
export STARKNET_ACCOUNT=katana-0
export STARKNET_RPC=http://0.0.0.0:5050
```

* 更新src/lib.cairo
```
#[starknet::interface]
trait IHello<T> {
fn get_name(self: @T) -> felt252;
fn set_name(ref self: T, name: felt252);
}
#[starknet::contract]
mod hello {
#[storage]
struct Storage {
name: felt252,
}
#[constructor]
fn constructor(ref self: ContractState, name: felt252) {
self.name.write(name);
}
#[abi(embed_v0)]
impl HelloImpl of super::IHello<ContractState> {
fn get_name(self: @ContractState) -> felt252 {
self.name.read()
}
fn set_name(ref self: ContractState, name: felt252) {
self.name.write(name);
}
}
}
```

Compile the contract with the Scarb compiler:
* scarb build
![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_1.png?raw=true)

The above command results in a compiled contract under target/dev/, named "my_contract_hello.contract_class.json"

去src, 執行:
* source .env

如果沒有執行 source src/.env , 會有以下錯誤訊息:
![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_3.png?raw=true)

執行
* katanakatana
如下圖所示
![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_4.png?raw=true)

去my_contract
To declare your contract, execute:
* starkli declare target/dev/my_contract_hello.contract_class.json
正常會出現以下錯誤訊息:
![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_5.png?raw=true)


<!-- Content_END -->
33 changes: 22 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 @@ -224,6 +224,17 @@ Starknet 残酷共学是由 LXDAO、Starknet Astro、AAStar 联合发起,旨

















Expand Down
41 changes: 40 additions & 1 deletion Reign.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ This chapter provides a guide for compiling, deploying, and interacting with a S
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
### 2024.09.24

### 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:
Expand Down Expand Up @@ -294,6 +295,44 @@ This chapter outlines the complete workflow for developing and managing Starknet
6. **Version Changes**:
- Version 2.3.0 introduced JSON outputs for Sierra and CASM code and support for components.

### 2024.09.25

#### Installation Steps for Starknet Development Tools

This guide helps set up essential Starknet development tools.

1. **Essential Tools**:
- **Starkli**: A command-line interface (CLI) for interacting with Starknet.
- **Scarb**: Cairo’s package manager for compiling code to Sierra, the intermediary language for Starknet.
- **Katana**: A Starknet node designed for local development.

2. **Starkli Installation**:
- Install via command:
```
curl https://get.starkli.sh | sh
```
- Verify installation with `starkli --version`. Repeat the steps to upgrade.

3. **Scarb Package Manager Installation**:
- **Requirements**: Ensure a Git executable is available in your PATH.
- Install via **asdf** for version management:
```
asdf plugin add scarb
asdf install scarb 2.5.4
asdf global scarb 2.5.4
```
- Alternatively, install directly:
```
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh
```
- Verify installation with `scarb --version`.

4. **Katana Node Installation**:
- Install using the Dojo engine installer:
```
curl -L https://install.dojoengine.org | bash
```
- Verify installation with `katana --version`.



Expand Down
98 changes: 98 additions & 0 deletions River.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,104 @@ Loops和递归是两种重复执行代码的方式。
### 2024.09.24
#### 数组
数组是一系列具有相同类型的元素的集合。可以使用核心库的特征`ArrayTrait`来创建和使用数组。
⚠️ 数组是一种队列,里面的值无法修改。事实上一旦写入到内存槽中就无法重写,只能读取。在数组中,只能在最后添加元素,以及从前面删除元素。
###### 创建数组
* `ArrayTrait::new()`
* `ArrayTrait::<T>::new();`
~~~rust
fn main() {
let mut a = ArrayTrait::new();
a.append(0);
a.append(1);
a.append(2);
let mut arr1 = ArrayTrait::<u128>::new();
let mut arr2:Array<u128> = ArrayTrait::new();
}
~~~
###### 更新数组
* 添加元素:`append()`
* 删除元素:`pop_front()`。会返回`Option`,使用`unwrap()`获取删除的元素,如果返回`Option::None`表示数组是空的
~~~rust
fn main() {
let mut a = ArrayTrait::new();
a.append(10);
a.append(1);
a.append(2);
let first_value = a.pop_front().unwrap();
println!("The first value is {}", first_value);
}
~~~
###### 读取数组
* `get()`:返回`Option<Box<@T>>`,如果元素不存在则返回None,
* `at()`:`arr.at(index)`和`arr[index]`等价,如果下标益处则会Panic
###### 容量相关的方法
* `len()`:确定数组的元素个数,返回`usize`类型的值
* `is_empty()`:判断数组是否为空
###### `array!`Macro
如果需要创建在编译期就能确定值的数组时,可以使用`array!`来简化创建带有元素的数组
~~~rust
let arr = array![1, 2, 3, 4, 5];
~~~
###### 存储多种类型
可以使用`Enum`自定义的数据类型在数组中存储多种数据类型
~~~rust
#[derive(Copy, Drop)]
enum Data {
Integer: u128,
Felt: felt252,
Tuple: (u32, u32),
}
fn main() {
let mut messages: Array<Data> = array![];
messages.append(Data::Integer(100));
messages.append(Data::Felt('hello world'));
messages.append(Data::Tuple((10, 30)));
}
~~~
###### `Span`
`Span`是一种表示数组快照的结构。
用来在不修改原数组的前提下,提供数组中元素的安全以及访问控制。
在函数间传递数组或者执行只读操作的时候,保证数据完整性和避免借用问题时非常有用。
使用方法:`array.span()`
<!-- Content_END -->
14 changes: 11 additions & 3 deletions awaqawaqawaq.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ StarkNet's tokenomics .
### 2024.09.23
- [观看了第一期视频,看的懂但是看不懂🙃🙃🙃](https://youtu.be/p6mPT2HOGKI)




### 2024.09.24
- 事件
- 将数据存储在事件中比存储在存储变量中更具成本效益
- 事件不能直接从合约内部读取。
- 诸如 starknet.js 的应用程序可以通过 RPC 接口订阅这些事件,并在前端触发响应。
- #[event]和#[derive(Drop, starknet::Event)]
- 事件变体成员必须是一个与变体同名的结构体
- 使用emit()释放
- 异常处理
- assert()
- panic()
<!-- Content_END -->
3 changes: 2 additions & 1 deletion geyu.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fork 了 counter-workshop
通过了counter-workshop Step 4
### 2024.09.23
学习 https://docs.starknet.io/ 的文档,目前进度:Deploying a smart contract

### 2024.09.24
学习 https://docs.starknet.io/ 的文档,目前进度: Using a development network

<!-- Content_END -->
24 changes: 24 additions & 0 deletions phipupt.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,28 @@ Starknet Foundry 使用:
Starknet Foundry 居然还没有本地节点?


### 2024.09.24
starknet-devnet-rs 使用

安装:
```
cargo install starknet-devnet
```
运行节点:
```
starknet-devnet-rs
```

RPC 调用(获取账户余额):
curl -X POST --data '{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_getAccountBalance",
"params": {
"address": "<address>",
"unit": "WEI",
"block_tag": "latest"
}
}' http://127.0.0.1:5050/rpc

<!-- Content_END -->

0 comments on commit 0a805a3

Please sign in to comment.