资讯专栏INFORMATION COLUMN

OpenZeppelin ERC721源码分析

ctriptech / 2921人阅读

摘要:它和我写的上一篇源码分析介绍的有所不同,最小的单位为无法再分割,代表独一无二的,针对不可置换的的智能合约标准接口。源码分析到这里就结束了。

ERC721 官方简介是:A standard interface for non-fungible tokens, also known as deeds.也叫非同质代币,或者不可置换代币(NFTs)。提到ERC721,一个好理解的例子就是CryptoKitties 迷恋猫,每一只猫都是独一无二的拥有不同基因,有收藏价值属性。ERC721对于虚拟资产收藏品领域会有很好的应用价值和市场需求。

它和我写的上一篇《OpenZeppelin ERC20源码分析》介绍的ERC20有所不同,ERC721最小的单位为1无法再分割,代表独一无二的,针对不可置换的Token的智能合约标准接口。从 ERC721标准草案中可以看到,兼容ERC20的方法有4个:namesymboltotalSupplybalanceOf 添加的新方法:ownerOftakeOwnership ERC721还重写了approvetransfer

分析OpenZeppelin ERC721源码前同样我画了一个继承和调用关系的思维导图,可以帮助更容易地看源码。

ERC721Basic.sol

</>复制代码

  1. pragma solidity ^0.4.23;
  2. /**
  3. * @title ERC721 标准的基本接口
  4. * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
  5. */
  6. contract ERC721Basic {
  7. event Transfer(
  8. address indexed _from,
  9. address indexed _to,
  10. uint256 _tokenId
  11. );
  12. event Approval(
  13. address indexed _owner,
  14. address indexed _approved,
  15. uint256 _tokenId
  16. );
  17. event ApprovalForAll(
  18. address indexed _owner,
  19. address indexed _operator,
  20. bool _approved
  21. );
  22. function balanceOf(address _owner) public view returns (uint256 _balance);
  23. function ownerOf(uint256 _tokenId) public view returns (address _owner);
  24. function exists(uint256 _tokenId) public view returns (bool _exists);
  25. function approve(address _to, uint256 _tokenId) public;
  26. function getApproved(uint256 _tokenId)
  27. public view returns (address _operator);
  28. function setApprovalForAll(address _operator, bool _approved) public;
  29. function isApprovedForAll(address _owner, address _operator)
  30. public view returns (bool);
  31. function transferFrom(address _from, address _to, uint256 _tokenId) public;
  32. function safeTransferFrom(address _from, address _to, uint256 _tokenId)
  33. public;
  34. function safeTransferFrom(
  35. address _from,
  36. address _to,
  37. uint256 _tokenId,
  38. bytes _data
  39. )
  40. public;
  41. }

ERC721Basic 合约定义了基本的接口方法:

balanceOf 返回_owner的代币数量

ownerOf 根据_tokenId返回代币持有者address

exists _tokenId是否存在

approve 授权_tokenId给地址to

getApproved 查询_tokenId的授权人_operator address

setApprovalForAll 授权_operator具有所有代币的控制权

isApprovedForAll

transferFrom 转移代币所有权

safeTransferFrom 转移代币所有权

同时还定义了Transfer Approval ApprovalForAll 在后面的ERC721实现的代码中再来看事件的触发。

ERC721.sol

</>复制代码

  1. pragma solidity ^0.4.23;
  2. import "./ERC721Basic.sol";
  3. /**
  4. * @title ERC-721 标准的基本接口, 可选的枚举扩展
  5. * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
  6. */
  7. contract ERC721Enumerable is ERC721Basic {
  8. function totalSupply() public view returns (uint256);
  9. function tokenOfOwnerByIndex(
  10. address _owner,
  11. uint256 _index
  12. )
  13. public
  14. view
  15. returns (uint256 _tokenId);
  16. function tokenByIndex(uint256 _index) public view returns (uint256);
  17. }
  18. /**
  19. * @title ERC-721 ERC-721 标准的基本接口, 可选的元数据扩展
  20. * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
  21. */
  22. contract ERC721Metadata is ERC721Basic {
  23. function name() public view returns (string _name);
  24. function symbol() public view returns (string _symbol);
  25. function tokenURI(uint256 _tokenId) public view returns (string);
  26. }
  27. /**
  28. * @title ERC-721 标准的基本接口,完整实现接口
  29. * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
  30. */
  31. contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata {
  32. }

ERC721 合约继承了 ERC721Basic 的基础上,添加枚举和元数据的扩展。

ERC721Enumerable枚举扩展可以使代币更具有可访问性:

totalSupply 返回代币总量

tokenOfOwnerByIndex 通过_owner所有者地址和索引值返回所有者代币列表中的_tokenId

tokenByIndex 通过索引值返回tokenId

ERC721Metadata元数据扩展哦用来描述合约元信息

name 返回合约名字

symbol 返回代币符号

tokenURI 返回_tokenId对应的资源URI

ERC721BasicToken

</>复制代码

  1. pragma solidity ^0.4.23;
  2. import "./ERC721Basic.sol";
  3. import "./ERC721Receiver.sol";
  4. import "../../math/SafeMath.sol";
  5. import "../../AddressUtils.sol";
  6. /**
  7. * @title ERC721 标准基本实现
  8. * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
  9. */
  10. contract ERC721BasicToken is ERC721Basic {
  11. using SafeMath for uint256;
  12. using AddressUtils for address;
  13. // Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`
  14. // which can be also obtained as `ERC721Receiver(0).onERC721Received.selector`
  15. bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba;
  16. // token ID 到 持有人owner的映射
  17. mapping (uint256 => address) internal tokenOwner;
  18. // token ID 到授权地址address的映射
  19. mapping (uint256 => address) internal tokenApprovals;
  20. // 持有人到持有的token数量的映射
  21. mapping (address => uint256) internal ownedTokensCount;
  22. // 持有人到操作人授权的映射
  23. mapping (address => mapping (address => bool)) internal operatorApprovals;
  24. /**
  25. * @dev 确保msg.sender是tokenId的持有人
  26. * @param _tokenId uint256 ID of the token to validate its ownership belongs to msg.sender
  27. */
  28. modifier onlyOwnerOf(uint256 _tokenId) {
  29. require(ownerOf(_tokenId) == msg.sender);
  30. _;
  31. }
  32. /**
  33. * @dev 通过检查msg.sender是否是代币的持有人,被授权或者操作人来确保msg.sender可以交易一个token
  34. * @param _tokenId uint256 ID of the token to validate
  35. */
  36. modifier canTransfer(uint256 _tokenId) {
  37. require(isApprovedOrOwner(msg.sender, _tokenId));
  38. _;
  39. }
  40. /**
  41. * @dev 获取持有者的代币总数
  42. * @param _owner address to query the balance of
  43. * @return uint256 representing the amount owned by the passed address
  44. */
  45. function balanceOf(address _owner) public view returns (uint256) {
  46. require(_owner != address(0));
  47. return ownedTokensCount[_owner];
  48. }
  49. /**
  50. * @dev 根据token ID获取持有者
  51. * @param _tokenId uint256 ID of the token to query the owner of
  52. * @return owner address currently marked as the owner of the given token ID
  53. */
  54. function ownerOf(uint256 _tokenId) public view returns (address) {
  55. address owner = tokenOwner[_tokenId];
  56. require(owner != address(0));
  57. return owner;
  58. }
  59. /**
  60. * @dev 指定的token是否存在
  61. * @param _tokenId uint256 ID of the token to query the existence of
  62. * @return whether the token exists
  63. */
  64. function exists(uint256 _tokenId) public view returns (bool) {
  65. address owner = tokenOwner[_tokenId];
  66. return owner != address(0);
  67. }
  68. /**
  69. * @dev 批准另一个人address来交易指定的代币
  70. * @dev 0 address 表示没有授权的地址
  71. * @dev 给定的时间内,一个token只能有一个批准的地址
  72. * @dev 只有token的持有者或者授权的操作人才可以调用
  73. * @param _to address to be approved for the given token ID
  74. * @param _tokenId uint256 ID of the token to be approved
  75. */
  76. function approve(address _to, uint256 _tokenId) public {
  77. address owner = ownerOf(_tokenId);
  78. require(_to != owner);
  79. require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
  80. if (getApproved(_tokenId) != address(0) || _to != address(0)) {
  81. tokenApprovals[_tokenId] = _to;
  82. emit Approval(owner, _to, _tokenId);
  83. }
  84. }
  85. /**
  86. * @dev 获取token被授权的地址,如果没有设置地址则为0
  87. * @param _tokenId uint256 ID of the token to query the approval of
  88. * @return address currently approved for the given token ID
  89. */
  90. function getApproved(uint256 _tokenId) public view returns (address) {
  91. return tokenApprovals[_tokenId];
  92. }
  93. /**
  94. * @dev 设置或者取消对操作人的授权
  95. * @dev 一个操作人可以代表他们转让发送者的所有token
  96. * @param _to operator address to set the approval
  97. * @param _approved representing the status of the approval to be set
  98. */
  99. function setApprovalForAll(address _to, bool _approved) public {
  100. require(_to != msg.sender);
  101. operatorApprovals[msg.sender][_to] = _approved;
  102. emit ApprovalForAll(msg.sender, _to, _approved);
  103. }
  104. /**
  105. * @dev 查询是否操作人被指定的持有者授权
  106. * @param _owner 要查询的授权人地址
  107. * @param _operator 要查询的授权操作人地址
  108. * @return bool whether the given operator is approved by the given owner
  109. */
  110. function isApprovedForAll(
  111. address _owner,
  112. address _operator
  113. )
  114. public
  115. view
  116. returns (bool)
  117. {
  118. return operatorApprovals[_owner][_operator];
  119. }
  120. /**
  121. * @dev 将指定的token所有权转移给另外一个地址
  122. * @dev 不鼓励使用这个方法,尽量使用`safeTransferFrom`
  123. * @dev 要求 msg.sender 必须为所有者,已授权或者操作人
  124. * @param _from current owner of the token
  125. * @param _to address to receive the ownership of the given token ID
  126. * @param _tokenId uint256 ID of the token to be transferred
  127. */
  128. function transferFrom(
  129. address _from,
  130. address _to,
  131. uint256 _tokenId
  132. )
  133. public
  134. canTransfer(_tokenId)
  135. {
  136. require(_from != address(0));
  137. require(_to != address(0));
  138. clearApproval(_from, _tokenId);
  139. removeTokenFrom(_from, _tokenId);
  140. addTokenTo(_to, _tokenId);
  141. emit Transfer(_from, _to, _tokenId);
  142. }
  143. /**
  144. * @dev 更安全的方法,将指定的token所有权转移给另外一个地址
  145. * @dev 如果目标地址是一个合约,必须实现 `onERC721Received`,这个要求安全交易并返回值
  146. `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; 否则交易被还原
  147. * @dev 要求 msg.sender 必须为所有者,已授权或者操作人
  148. * @param _from current owner of the token
  149. * @param _to address to receive the ownership of the given token ID
  150. * @param _tokenId uint256 ID of the token to be transferred
  151. */
  152. function safeTransferFrom(
  153. address _from,
  154. address _to,
  155. uint256 _tokenId
  156. )
  157. public
  158. canTransfer(_tokenId)
  159. {
  160. safeTransferFrom(_from, _to, _tokenId, "");
  161. }
  162. /**
  163. * @dev 更安全的方法,将指定的token所有权转移给另外一个地址
  164. * @dev 如果目标地址是一个合约,必须实现 `onERC721Received`,这个要求安全交易并返回值
  165. `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; 否则交易被还原
  166. * @dev 要求 msg.sender 必须为所有者,已授权或者操作人
  167. * @param _from current owner of the token
  168. * @param _to address to receive the ownership of the given token ID
  169. * @param _tokenId uint256 ID of the token to be transferred
  170. * @param _data bytes data to send along with a safe transfer check
  171. */
  172. function safeTransferFrom(
  173. address _from,
  174. address _to,
  175. uint256 _tokenId,
  176. bytes _data
  177. )
  178. public
  179. canTransfer(_tokenId)
  180. {
  181. transferFrom(_from, _to, _tokenId);
  182. require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data));
  183. }
  184. /**
  185. * @dev 返回给定的spender是否可以交易一个给定的token
  186. * @param _spender address of the spender to query
  187. * @param _tokenId uint256 ID of the token to be transferred
  188. * @return bool whether the msg.sender is approved for the given token ID,
  189. * is an operator of the owner, or is the owner of the token
  190. */
  191. function isApprovedOrOwner(
  192. address _spender,
  193. uint256 _tokenId
  194. )
  195. internal
  196. view
  197. returns (bool)
  198. {
  199. address owner = ownerOf(_tokenId);
  200. return (
  201. _spender == owner ||
  202. getApproved(_tokenId) == _spender ||
  203. isApprovedForAll(owner, _spender)
  204. );
  205. }
  206. /**
  207. * @dev 增发一个新token的内部方法
  208. * @dev 如果增发的token已经存在则撤销
  209. * @param _to The address that will own the minted token
  210. * @param _tokenId uint256 ID of the token to be minted by the msg.sender
  211. */
  212. function _mint(address _to, uint256 _tokenId) internal {
  213. require(_to != address(0));
  214. addTokenTo(_to, _tokenId);
  215. emit Transfer(address(0), _to, _tokenId);
  216. }
  217. /**
  218. * @dev 销毁一个token的内部方法
  219. * @dev 如果token不存在则撤销
  220. * @param _tokenId uint256 ID of the token being burned by the msg.sender
  221. */
  222. function _burn(address _owner, uint256 _tokenId) internal {
  223. clearApproval(_owner, _tokenId);
  224. removeTokenFrom(_owner, _tokenId);
  225. emit Transfer(_owner, address(0), _tokenId);
  226. }
  227. /**
  228. * @dev 清除当前的给定token的授权,内部方法
  229. * @dev 如果给定地址不是token的持有者则撤销
  230. * @param _owner owner of the token
  231. * @param _tokenId uint256 ID of the token to be transferred
  232. */
  233. function clearApproval(address _owner, uint256 _tokenId) internal {
  234. require(ownerOf(_tokenId) == _owner);
  235. if (tokenApprovals[_tokenId] != address(0)) {
  236. tokenApprovals[_tokenId] = address(0);
  237. emit Approval(_owner, address(0), _tokenId);
  238. }
  239. }
  240. /**
  241. * @dev 内部方法,将给定的token添加到给定地址列表中
  242. * @param _to address 指定token的新所有者
  243. * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
  244. */
  245. function addTokenTo(address _to, uint256 _tokenId) internal {
  246. require(tokenOwner[_tokenId] == address(0));
  247. tokenOwner[_tokenId] = _to;
  248. ownedTokensCount[_to] = ownedTokensCount[_to].add(1);
  249. }
  250. /**
  251. * @dev 内部方法,将给定的token从地址列表中移除
  252. * @param _from address 给定token的之前持有中地址
  253. * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
  254. */
  255. function removeTokenFrom(address _from, uint256 _tokenId) internal {
  256. require(ownerOf(_tokenId) == _from);
  257. ownedTokensCount[_from] = ownedTokensCount[_from].sub(1);
  258. tokenOwner[_tokenId] = address(0);
  259. }
  260. /**
  261. * @dev 内部函数,调用目标地址上的 `onERC721Received`
  262. * @dev 如果目标地址不是合同则不执行调用
  263. * @param _from address representing the previous owner of the given token ID
  264. * @param _to target address that will receive the tokens
  265. * @param _tokenId uint256 ID of the token to be transferred
  266. * @param _data bytes optional data to send along with the call
  267. * @return whether the call correctly returned the expected magic value
  268. */
  269. function checkAndCallSafeTransfer(
  270. address _from,
  271. address _to,
  272. uint256 _tokenId,
  273. bytes _data
  274. )
  275. internal
  276. returns (bool)
  277. {
  278. if (!_to.isContract()) {
  279. return true;
  280. }
  281. bytes4 retval = ERC721Receiver(_to).onERC721Received(
  282. _from, _tokenId, _data);
  283. return (retval == ERC721_RECEIVED);
  284. }
  285. }

ERC721BasicToken 实现了ERC721Basic合约定义的接口方法,主要对token的持有人的一个添加和修改,以及授权和交易的管理,实现了基本的非同质化token的业务逻辑。具体方法实现并不难,就是对映射的公有变量的管理,但是对于权限和安全验证值得关注,比如函数修改器还有require

ERC721Token.sol

</>复制代码

  1. pragma solidity ^0.4.23;
  2. import "./ERC721.sol";
  3. import "./ERC721BasicToken.sol";
  4. /**
  5. * @title 完整 ERC721 Token
  6. * 该实现包括所有ERC721标准必须的和可选的方法,此外还包括使用操作者批准所有功能
  7. * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
  8. */
  9. contract ERC721Token is ERC721, ERC721BasicToken {
  10. // 代币名称
  11. string internal name_;
  12. // 代币符号
  13. string internal symbol_;
  14. // 所有者到所有者拥有的代币列表的映射
  15. mapping(address => uint256[]) internal ownedTokens;
  16. // 所有者代币列表中代币ID到索引的映射
  17. mapping(uint256 => uint256) internal ownedTokensIndex;
  18. // 保存所有代币ID的数组,用于枚举
  19. uint256[] internal allTokens;
  20. // allTokens数组中代币ID到索引的映射
  21. mapping(uint256 => uint256) internal allTokensIndex;
  22. // 可选的代币资源URIs映射
  23. mapping(uint256 => string) internal tokenURIs;
  24. /**
  25. * @dev Constructor function
  26. */
  27. constructor(string _name, string _symbol) public {
  28. name_ = _name;
  29. symbol_ = _symbol;
  30. }
  31. /**
  32. * @dev 获取代币名称
  33. * @return string representing the token name
  34. */
  35. function name() public view returns (string) {
  36. return name_;
  37. }
  38. /**
  39. * @dev 获取代币符号
  40. * @return string representing the token symbol
  41. */
  42. function symbol() public view returns (string) {
  43. return symbol_;
  44. }
  45. /**
  46. * @dev 根据_tokenId返回对应的资源URI
  47. * @dev 如果token不存在异常返回空字符串
  48. * @param _tokenId uint256 ID of the token to query
  49. */
  50. function tokenURI(uint256 _tokenId) public view returns (string) {
  51. require(exists(_tokenId));
  52. return tokenURIs[_tokenId];
  53. }
  54. /**
  55. * @dev 获取token id 通过给定的token列表中的索引
  56. * @param _owner address owning the tokens list to be accessed
  57. * @param _index uint256 representing the index to be accessed of the requested tokens list
  58. * @return uint256 token ID at the given index of the tokens list owned by the requested address
  59. */
  60. function tokenOfOwnerByIndex(
  61. address _owner,
  62. uint256 _index
  63. )
  64. public
  65. view
  66. returns (uint256)
  67. {
  68. require(_index < balanceOf(_owner));
  69. return ownedTokens[_owner][_index];
  70. }
  71. /**
  72. * @dev 获取合约存储的token总数
  73. * @return uint256 representing the total amount of tokens
  74. */
  75. function totalSupply() public view returns (uint256) {
  76. return allTokens.length;
  77. }
  78. /**
  79. * @dev 根据token 索引值获取合约中token的
  80. * @dev 如果索引大于等于token总数则撤销
  81. * @param _index uint256 representing the index to be accessed of the tokens list
  82. * @return uint256 token ID at the given index of the tokens list
  83. */
  84. function tokenByIndex(uint256 _index) public view returns (uint256) {
  85. require(_index < totalSupply());
  86. return allTokens[_index];
  87. }
  88. /**
  89. * @dev 内部方法,给存在token添加token URI
  90. * @dev Reverts if the token ID does not exist
  91. * @param _tokenId uint256 ID of the token to set its URI
  92. * @param _uri string URI to assign
  93. */
  94. function _setTokenURI(uint256 _tokenId, string _uri) internal {
  95. require(exists(_tokenId));
  96. tokenURIs[_tokenId] = _uri;
  97. }
  98. /**
  99. * @dev 内部方法,添加token ID 到给定的地址的列表中
  100. * @param _to address 给定token ID的新的持有者
  101. * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
  102. */
  103. function addTokenTo(address _to, uint256 _tokenId) internal {
  104. // 调用父合约的addTokenTo
  105. super.addTokenTo(_to, _tokenId);
  106. uint256 length = ownedTokens[_to].length;
  107. ownedTokens[_to].push(_tokenId);
  108. //当前的长度作为索引
  109. ownedTokensIndex[_tokenId] = length;
  110. }
  111. /**
  112. * @dev 内部方法,从一个给定地址的列表中移除token
  113. * @param _from address 给定token ID的之前的持有者address
  114. * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
  115. */
  116. function removeTokenFrom(address _from, uint256 _tokenId) internal {
  117. // 调用父合约的移除方法
  118. super.removeTokenFrom(_from, _tokenId);
  119. // 获取token的索引
  120. uint256 tokenIndex = ownedTokensIndex[_tokenId];
  121. // 获取持有人token的最后一个token索引
  122. uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
  123. // 获取最后一个token
  124. uint256 lastToken = ownedTokens[_from][lastTokenIndex];
  125. //将最后一个token放到被删除的索引位置,lastTokenIndex置0
  126. ownedTokens[_from][tokenIndex] = lastToken;
  127. ownedTokens[_from][lastTokenIndex] = 0;
  128. // 注意这里需要处理单元素数组,tokenIndex和lastTokenIndex都将置0.然后可以确保将ownedTokens列表中删除_tokenId,首先将lastToken换到第一个位置,然后删除列表最后位置的元素
  129. ownedTokens[_from].length--;
  130. ownedTokensIndex[_tokenId] = 0;
  131. ownedTokensIndex[lastToken] = tokenIndex;
  132. }
  133. /**
  134. * @dev 内部方法,增发一个新的token
  135. * @dev 如果token已经存在了就撤销
  136. * @param _to address the beneficiary that will own the minted token
  137. * @param _tokenId uint256 ID of the token to be minted by the msg.sender
  138. */
  139. function _mint(address _to, uint256 _tokenId) internal {
  140. super._mint(_to, _tokenId);
  141. allTokensIndex[_tokenId] = allTokens.length;
  142. allTokens.push(_tokenId);
  143. }
  144. /**
  145. * @dev 内部方法,销毁一个指定的token
  146. * @dev token不存在则撤销
  147. * @param _owner owner of the token to burn
  148. * @param _tokenId uint256 ID of the token being burned by the msg.sender
  149. */
  150. function _burn(address _owner, uint256 _tokenId) internal {
  151. super._burn(_owner, _tokenId);
  152. // 清除资源URI
  153. if (bytes(tokenURIs[_tokenId]).length != 0) {
  154. delete tokenURIs[_tokenId];
  155. }
  156. // 做所有的token数组后续处理
  157. uint256 tokenIndex = allTokensIndex[_tokenId];
  158. uint256 lastTokenIndex = allTokens.length.sub(1);
  159. uint256 lastToken = allTokens[lastTokenIndex];
  160. // 可以参考增发removeTokenFrom
  161. allTokens[tokenIndex] = lastToken;
  162. allTokens[lastTokenIndex] = 0;
  163. allTokens.length--;
  164. allTokensIndex[_tokenId] = 0;
  165. allTokensIndex[lastToken] = tokenIndex;
  166. }
  167. }

ERC721Token实现了完整的ERC721标准,在继承了ERC721BasicToken的基础上增加了一些token的操作,主要在包括token的元数据,资源URI,增发销毁,还有就是token索引的映射关系。对于具体实现我们根据实际情况通过继承ERC721BasicToken或者ERC721Token来添加自己的业务逻辑。

OpenZeppelin ERC721源码分析到这里就结束了。

转载请注明: 转载自Ryan是菜鸟 | LNMP技术栈笔记

如果觉得本篇文章对您十分有益,何不 打赏一下

本文链接地址: OpenZeppelin ERC721源码分析

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/24227.html

相关文章

  • OpenZeppelin ERC20源码分析

    摘要:前提是拥有者必须要通过某些机制对这个请求进行确认,比如通过进行。事件,当被调用时,需要触发该事件。允许从中转出的数增加所有者允许花费代币的数量。已经归属合约,其余归还给所有者。计算已归属但尚未释放的金额。源码分析到这里就结束了。 ERC20:Ethereum Request for Comments 20,是一个基于以太坊代币的接口标准(协议)。所有符合ERC-20标准的代币都能立即兼...

    kumfo 评论0 收藏0
  • 以太坊开发实战学习-ERC721标准(七)

    摘要:从这节开始,我们将学习代币标准以及加密收集资产等知识。声明一个继承的新合约,命名为。注意目前是一个草稿,还没有正式商定的实现。所以把这一个可能的实现当作考虑,但不要把它作为代币的官方标准。 从这节开始,我们将学习代币, ERC721标准, 以及加密收集资产等知识。 一、代币 代币 让我们来聊聊以太坊上的代币。 如果你对以太坊的世界有一些了解,你很可能听过人们聊到代币——尤其是 ERC2...

    android_c 评论0 收藏0
  • 以太坊开发实战学习-合约安全(八)

    摘要:合约安全增强溢出和下溢我们将来学习你在编写智能合约的时候需要注意的一个主要的安全特性防止溢出和下溢。实战演练给加上一些标签把这里变成标准的注释把一个管理转移僵尸所有权的合约符合对标准草案的实现 通过上一节的学习,我们完成了 ERC721 的实现。并不是很复杂,对吧?很多类似的以太坊概念,当你只听人们谈论它们的时候,会觉得很复杂。所以最简单的理解方式就是你自己来实现它。 一、预防溢出 不...

    UsherChen 评论0 收藏0
  • 剖析非同质化代币ERC721-全面解析ERC721标准

    摘要:本文就来剖析下什么是是什么在创建代币一篇,我们讲到过代币,和一样,同样是一个代币标准,官方简要解释是,简写为,多翻译为非同质代币。返回合约代币符号,尽管是可选,但强烈建议实现,即便是返回空字符串。 本文首发于深入浅出区块链社区原文链接:剖析非同质化代币ERC721-全面解析ERC721标准原文已更新,请读者前往原文阅读 什么是ERC-721?现在我们看到的各种加密猫猫狗狗都是基于ERC...

    Sike 评论0 收藏0
  • Java开发区块链的三大sdk库

    摘要:是企业与区块链相遇的地方。的框架旨在成为开发区块链解决方案的支柱。以太坊,主要是针对工程师使用进行区块链以太坊开发的详解。 如果你想将区块链合并到一个Java项目中,现在我们来看看就是这个细分领域中三个最大的OSS玩家。 好的伙计们,我们都听说过比特币,以太坊或其他加密货币,其中有一些时髦的名字围绕着我们常见的新闻,但我们作为Java开发人员知道如何轻松地与这些区块链技术进行交互吗?以...

    iKcamp 评论0 收藏0

发表评论

0条评论

ctriptech

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<