---
eip: 5791
label: ERC-5791
title: Physical Backed Tokens
status: Draft
type: Standards Track
category: ERC
created: 2022-10-17
requires: 191, 721
official: https://eips.ethereum.org/EIPS/eip-5791
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5791.md
canonical: https://eips.huatuo.xyz/zh/eip-5791/
lang: zh
tldr: 把 ERC-721 NFT 与实物中的安全芯片绑定，使只有持有该实物的人才能让芯片签署代币转移。
tags: [nft, physical, rwa, signatures]
---

# ERC-5791: Physical Backed Tokens

> Minimal interface for linking ownership of ERC-721 NFTs to a physical chip

**TL;DR:** 把 ERC-721 NFT 与实物中的安全芯片绑定，使只有持有该实物的人才能让芯片签署代币转移。

## 它解决什么问题？

代表运动鞋、艺术品或收藏品的 NFT 通常有两个问题：拥有 NFT 和拥有实物是两回事，而证明实物的真伪又依赖受信任的第三方。

实物支持代币（Physical Backed Tokens，PBT）把二者绑定起来。嵌入物品中的芯片持有一个无法被提取的私钥。谁实际拥有该物品，谁就能让芯片对一条消息签名，而这个签名就是移动 NFT 的依据。验证真伪不需要任何中心化机构。

## 它如何运作

- 每个代币都与一个由芯片公钥派生的**芯片地址**配对。配对时会触发 `ChipSet(tokenId, chipId)`，方便索引器把芯片映射到代币。没有关联芯片的代币无法被铸造。
- 该合集是**账户绑定**的：所有常规的 [ERC-721](/eip-721/) 转移函数都必须 revert。移动代币的唯一方式是 `transferToken`。
- `transferToken(to, chipId, chipSignature, signatureTimestamp, useSafeTransferFrom, extras)` 会检查芯片对接收方、芯片地址、近期区块时间戳和任何额外数据所作的 [ERC-191](/eip-191/) 签名，然后把代币转给 `to`。
- `tokenIdFor(chipId)` 和 `isChipSignatureForToken(tokenId, data, signature)` 让任何人都能检查某个芯片是否对应某个代币。
- 合约通过 [ERC-165](/eip-165/) 接口 ID `0x4901df9f` 声明支持。

铸造方式以及代币 ID 如何映射到芯片（由所有者预设、由受信任方签名、注册表、先到先得）留给实现自行决定。签名验证通过芯片地址进行，因此芯片不限于 secp256k1。

## 示例代码

接口：

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

interface IERC5791 {
    event ChipSet(uint256 indexed tokenId, address indexed chipId);

    function tokenIdFor(address chipId) external view returns (uint256 tokenId);

    function isChipSignatureForToken(uint256 tokenId, bytes calldata data, bytes calldata signature)
        external view returns (bool);

    function transferToken(
        address to,
        address chipId,
        bytes calldata chipSignature,
        uint256 signatureTimestamp,
        bool useSafeTransferFrom,
        bytes calldata extras
    ) external returns (uint256 tokenId);
}
```

参考实现构造芯片所签署摘要的方式大致如下：

```solidity
if (signatureTimestamp > block.timestamp) revert SignatureTimestampInFuture();
if (signatureTimestamp + maxDurationWindow < block.timestamp) revert SignatureTimestampTooOld();
bytes32 hash = keccak256(abi.encode(
    address(this), block.chainid, chipNonce[chipId], to, signatureTimestamp, keccak256(extras)
));
bytes32 digest = ECDSA.toEthSignedMessageHash(hash); // ERC-191
```

## 需要注意

- 状态为 **Draft**；接口仍可能变化。
- 对"实物支持"的信任只取决于芯片本身。芯片地址是否真的属于真实芯片，以及芯片是否一直附着且完好无损，被明确排除在范围之外。
- 在被签名数据中包含接收方和近期时间戳，可以防止重放，也能防止有人在交出物品之前预先签好转移。建议使用非确定性的 nonce。
- 物品持有者可以通过把芯片签名交给别人来把 NFT 发送给对方；规范把这视为类似出借，因为持有者随时可以收回 NFT。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-5791
