Skip to content

Commit b7fa368

Browse files
committed
Add study notes for 2025-08-15
1 parent 14b1586 commit b7fa368

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

janebirkey.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,76 @@ timezone: UTC+8
1515
## Notes
1616

1717
<!-- Content_START -->
18+
# 2025-08-15
19+
20+
实践案例:如何通过 Layer 2 将文章内容上链
21+
22+
23+
24+
这是一个典型的“链上+链下”结合的解决方案,完美平衡了成本、效率和去中心化。
25+
26+
**流程概览:**
27+
28+
1. **链下处理 (客户端/服务器端)**
29+
30+
- 将文章原文上传到**去中心化存储网络**,如 **IPFS** 或 Arweave,获取其内容标识符 (CID)。
31+
- 使用 `SHA-256` 算法计算文章原文的**哈希值**,作为文章的“数字指纹”。
32+
33+
```python
34+
import hashlib
35+
# 假设已将内容上传到 IPFS 并获得 CID
36+
# ipfs_cid = "Qm..."
37+
38+
article_content = "This is my article content."
39+
hash_object = hashlib.sha256(article_content.encode('utf-8'))
40+
article_hash = "0x" + hash_object.hexdigest()
41+
```
42+
43+
2. **部署 Layer 2 智能合约**
44+
45+
- 在 Layer 2 网络上(如 Arbitrum)部署一个智能合约,该合约用于记录文章的元数据。
46+
47+
```solidity
48+
// SPDX-License-Identifier: MIT
49+
pragma solidity ^0.8.0;
50+
51+
contract ArticleRegistry {
52+
struct Article {
53+
address author;
54+
string ipfsCID;
55+
uint256 timestamp;
56+
}
57+
58+
// 映射:文章哈希 -> 文章信息
59+
mapping(bytes32 => Article) public articles;
60+
61+
event ArticlePublished(address indexed author, bytes32 articleHash, string ipfsCID);
62+
63+
function publishArticle(bytes32 _articleHash, string memory _ipfsCID) public {
64+
require(articles[_articleHash].author == address(0), "Article already exists.");
65+
66+
articles[_articleHash] = Article({
67+
author: msg.sender,
68+
ipfsCID: _ipfsCID,
69+
timestamp: block.timestamp
70+
});
71+
72+
emit ArticlePublished(msg.sender, _articleHash, _ipfsCID);
73+
}
74+
}
75+
```
76+
77+
3. **客户端调用合约**
78+
79+
- 用户通过前端 DApp(使用 Ethers.js 等库)连接钱包,调用 L2 智能合约的 `publishArticle` 函数,传入第一步生成的 `article_hash``ipfs_cid`
80+
- 这笔交易在 L2 上被快速确认,Gas 费极低。
81+
82+
**最终结果:**
83+
84+
- **链下 (Off-chain)**:存储了文章原文,解决了高成本和存储容量问题。
85+
- **链上 Layer 2 (On-chain L2)**:以极低的成本记录了文章的**所有权证明**(作者地址)、**内容完整性证明**(哈希值)和**存在性证明**(时间戳和 IPFS 地址)。
86+
- **链上 Layer 1 (On-chain L1)**:L2 会定期将其状态根锚定到 L1,使得 L2 上的这条记录最终获得了 L1 级别的安全性,不可篡改。
87+
1888
# 2025-08-14
1989

2090
今天参加了两个晚会,同时了解了一下产品经理必会的prd文档,以及借助ai模拟了一个产品经理的工作流程常用的工具等等

0 commit comments

Comments
 (0)