Skip to content

Commit 19d295b

Browse files
committed
Add study notes for 2025-08-19
1 parent 879672a commit 19d295b

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

0xMiloAI.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,54 @@ web3初学者
1515
## Notes
1616

1717
<!-- Content_START -->
18+
# 2025-08-19
19+
20+
今日总结:
21+
22+
一、前端与合约交互流程
23+
24+
连接钱包:检测并请求用户授权(MetaMask)
25+
26+
实例化合约:使用 ABI 和合约地址创建合约对象
27+
28+
调用合约函数:执行 .send()(写入)或 .call()(读取)
29+
30+
签名并广播交易:用户确认交易 → 网络广播
31+
32+
更新状态:前端获取交易结果,刷新页面内容
33+
34+
二、关键技术栈
35+
36+
合约语言:Solidity
37+
38+
交互库:Web3.js / Ethers.js(新项目推荐 Viem、Wagmi)
39+
40+
钱包连接器:RainbowKit、Web3Modal 等
41+
42+
状态管理:React Context
43+
44+
错误处理:网络异常、授权失败、Gas 不足等
45+
46+
三、前端示例操作(基于 Web3.js)
47+
1. 连接钱包
48+
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
49+
web3 = new Web3(window.ethereum);
50+
account = accounts[0];
51+
52+
2. 导入 ABI & 实例化合约
53+
const contract = new web3.eth.Contract(contractABI, contractAddress);
54+
55+
3. 写操作(留言)
56+
await contract.methods.leaveMessage("Hello").send({ from: account });
57+
58+
4. 读操作(查看留言)
59+
const count = await contract.methods.getMessageCount(address).call();
60+
const msg = await contract.methods.getMessage(address, 0).call();
61+
62+
四、最终效果
63+
64+
用户可通过网页界面完成钱包连接、链上留言、查询留言等交互,实现一个完整的区块链留言 DApp 原型。
65+
1866
# 2025-08-18
1967

2068
今日总结:

0 commit comments

Comments
 (0)