@@ -15,6 +15,167 @@ timezone: UTC+8
1515## Notes
1616
1717<!-- Content_START -->
18+ # 2025-08-17
19+
20+ ## ** ERC721 - NFT 标准**
21+
22+ ### ** 定义:**
23+
24+ ERC721 是以太坊上的非同质化代币(NFT)标准,定义了每个代币的唯一性。每个 ERC721 代币都有一个独特的标识符(token ID),用于表示一个独特的资产,比如艺术作品、游戏道具等。
25+
26+ ### ** 作用:**
27+
28+ ERC721 标准确保了不同项目发行的 NFT 能在以太坊生态中兼容,钱包、市场和其他平台都可以统一支持这些代币的转移和交互。
29+
30+ ### ** ERC721 核心功能**
31+
32+ #### 必需函数:
33+
34+ 1 . ** balanceOf(address \_ owner)** - 返回特定地址拥有的 NFT 数量
35+
36+ ``` solidity
37+ function balanceOf(address _owner) public view returns (uint256 balance);
38+ ```
39+
40+ 2 . ** ownerOf(uint256 \_ tokenId)** - 返回指定 ` tokenId ` 的拥有者地址
41+
42+ ``` solidity
43+ function ownerOf(uint256 _tokenId) public view returns (address owner);
44+ ```
45+
46+ 3 . ** safeTransferFrom(address \_ from, address \_ to, uint256 \_ tokenId)** - 安全转移 ` tokenId ` 所代表的 NFT
47+
48+ ``` solidity
49+ function safeTransferFrom(address _from, address _to, uint256 _tokenId) public;
50+ ```
51+
52+ 4 . ** transferFrom(address \_ from, address \_ to, uint256 \_ tokenId)** - 非安全转移 ` tokenId ` 所代表的 NFT
53+
54+ ``` solidity
55+ function transferFrom(address _from, address _to, uint256 _tokenId) public;
56+ ```
57+
58+ 5 . ** approve(address \_ to, uint256 \_ tokenId)** - 允许 ` to ` 地址管理特定 ` tokenId ` 的 NFT
59+
60+ ``` solidity
61+ function approve(address _to, uint256 _tokenId) public;
62+ ```
63+
64+ 6 . ** setApprovalForAll(address \_ operator, bool \_ approved)** - 允许 ` operator ` 地址管理当前用户所有的 NFT
65+
66+ ``` solidity
67+ function setApprovalForAll(address _operator, bool _approved) public;
68+ ```
69+
70+ 7 . ** getApproved(uint256 \_ tokenId)** - 获取 ` tokenId ` 被批准的地址
71+
72+ ``` solidity
73+ function getApproved(uint256 _tokenId) public view returns (address operator);
74+ ```
75+
76+ 8 . ** isApprovedForAll(address \_ owner, address \_ operator)** - 判断 ` operator ` 是否被授权管理 ` owner ` 的所有 NFT
77+
78+ ``` solidity
79+ function isApprovedForAll(address _owner, address _operator) public view returns (bool);
80+ ```
81+
82+ #### 必需事件:
83+
84+ 1 . ** Transfer** - 当 NFT 转移时触发
85+
86+ ``` solidity
87+ event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
88+ ```
89+
90+ 2 . ** Approval** - 当授权某个地址转移 NFT 时触发
91+
92+ ``` solidity
93+ event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
94+ ```
95+
96+ 3 . ** ApprovalForAll** - 当授权或撤销授权某个地址管理所有 NFT 时触发
97+
98+ ``` solidity
99+ event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
100+ ```
101+
102+ ### ** ERC721 使用场景:**
103+
104+ * 数字艺术:每个艺术作品都对应一个独特的 NFT。
105+ * 游戏道具:如游戏内皮肤、装备等。
106+ * 收藏品:如虚拟卡片、纪念品等。
107+ * 房地产:虚拟世界中的土地、房产代币化。
108+
109+ ---
110+
111+ ## ** ERC4626 - Vault 标准**
112+
113+ ### ** 定义:**
114+
115+ ERC4626 是一种标准接口,定义了通过存入和提取资产的方式来与金库(Vault)交互。它旨在为资产管理协议(例如存款协议、借贷协议、流动性池等)提供统一标准,允许用户通过相同的接口存取资产并获得相应的收益。
116+
117+ ### ** 作用:**
118+
119+ ERC4626 主要用于提供更高效、标准化的资产存储方式,尤其是集中资产管理系统的标准化协议。
120+
121+ ### ** ERC4626 核心功能**
122+
123+ * ** totalSupply()** :返回金库中持有的总份额。
124+
125+ ``` solidity
126+ function totalSupply() external view returns (uint256);
127+ ```
128+
129+ * ** balanceOf(address account)** :返回特定地址的金库份额。
130+
131+ ``` solidity
132+ function balanceOf(address account) external view returns (uint256);
133+ ```
134+
135+ * ** deposit(uint256 assets, address receiver)** :向金库存入资产并获取份额。
136+
137+ ``` solidity
138+ function deposit(uint256 assets, address receiver) external returns (uint256 shares);
139+ ```
140+
141+ * ** withdraw(uint256 assets, address receiver, address owner)** :从金库提取资产并返回份额。
142+
143+ ``` solidity
144+ function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
145+ ```
146+
147+ * ** convertToShares(uint256 assets)** :将存入的资产转换为份额。
148+
149+ ``` solidity
150+ function convertToShares(uint256 assets) external view returns (uint256);
151+ ```
152+
153+ * ** convertToAssets(uint256 shares)** :将份额转换为资产。
154+
155+ ``` solidity
156+ function convertToAssets(uint256 shares) external view returns (uint256);
157+ ```
158+
159+ ### ** ERC4626 必需事件**
160+
161+ * ** Deposit** :当用户存入资产时触发。
162+
163+ ``` solidity
164+ event Deposit(address indexed sender, address indexed receiver, uint256 assets, uint256 shares);
165+ ```
166+
167+ * ** Withdraw** :当用户提取资产时触发。
168+
169+ ``` solidity
170+ event Withdraw(address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);
171+ ```
172+
173+ ### ** ERC4626 使用场景:**
174+
175+ * ** DeFi 存款池** :用户存入资产,获得相应的份额,并能通过 ERC4626 标准提取资产。
176+ * ** 借贷协议** :如 Compound 和 Aave,借贷资产都可以通过 ERC4626 进行管理。
177+ * ** 流动性池** :支持 LP(流动性提供者)存入流动性资产并通过标准化方式提取。
178+
18179# 2025-08-16
19180
20181# Web3 新人小白初入职场 X Space 重点记录
0 commit comments