EIPs Explained

ERC-7765 · Draft(草案) · ERC · 2024-08-20

ERC-7765: Privileged Non-Fungible Tokens Tied To RWA

ERC-721 扩展,用于与现实资产绑定、带有可兑换权益的 NFT,提供在链上行使权益并检查其是否已被使用的标准方式。

它解决什么问题?

NFT 经常被作为对现实世界中某样东西的主张权出售:一双鞋、一张票、一张服务券。持有者想要**兑换(redeem)**这项权益,而卖家需要一条链上记录来证明某项特定权利已被使用,以免被重复主张。

如今每个项目都自行构建兑换逻辑,因此钱包、市场和履约服务无法通用地处理这些代币。ERC-7765 标准化了 NFT 如何暴露其权益,以及持有者如何行使这些权益。

它如何运作

代币是普通的 ERC-721 NFT(转账和授权保持不变),并额外实现 IERC7765:

函数 / 事件 用途
getPrivilegeIds(tokenId) 列出附加在代币上的权益
isExercisable(to, tokenId, privilegeId) 当前能否为 to 行使该权益?
isExercised(to, tokenId, privilegeId) 是否已经为 to 行使过?
exercisePrivilege(to, tokenId, privilegeId, data) 行使权益;应触发 PrivilegeExercised
PrivilegeExercised(operator, to, tokenId, privilegeId) 表示链下履约可以开始

to 参数让权益可以惠及持有者或调用者之外的人(例如送礼)。data 字节是自由格式的,可用于发货参考信息,或在链上结算的权益。

可选的 IERC7765Metadata 扩展新增了 privilegeURI(privilegeId),指向一份 JSON,其中包含每项权益的 name、description 和 resource。

该标准有意不规定谁可以调用 exercisePrivilege;访问控制交由各个实现自行决定。

示例代码

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IERC7765 {
    event PrivilegeExercised(
        address indexed _operator,
        address indexed _to,
        uint256 indexed _tokenId,
        uint256 _privilegeId
    );

    function exercisePrivilege(address _to, uint256 _tokenId, uint256 _privilegeId, bytes calldata _data) external;
    function isExercisable(address _to, uint256 _tokenId, uint256 _privilegeId) external view returns (bool);
    function isExercised(address _to, uint256 _tokenId, uint256 _privilegeId) external view returns (bool);
    function getPrivilegeIds(uint256 _tokenId) external view returns (uint256[] memory);
}

监听兑换事件的履约服务(ethers v6):

import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const nft = new Contract(nftAddress, [
  "event PrivilegeExercised(address indexed _operator, address indexed _to, uint256 indexed _tokenId, uint256 _privilegeId)",
], provider);

nft.on("PrivilegeExercised", (operator, to, tokenId, privilegeId) => {
  console.log(`ship privilege ${privilegeId} of token ${tokenId} for ${to}`);
});

需要注意

  • **状态:Draft。**接口仍可能变化。
  • 链上只记录某项权益已被主张。实物或服务的交付完全取决于发行方,因此买家依赖的是发行方的链下承诺。
  • 实现必须仔细跟踪每个代币、每项权益的状态,并为 exercisePrivilege 定义清晰的访问控制;规范将这两点列为主要的安全隐患。
  • 应通过 ERC-165 的 supportsInterface 声明支持。

#nft #rwa #redemption #erc721 #privileges

详细信息

作者
frank (@frankmint2024) <[email protected]>
状态
Draft(草案)
类型
Standards Track / ERC
创建日期
2024-08-20
依赖的提案

机器可读数据: Markdown · JSON