# EIP-4400与EIP-4907介绍与对比

By [Yooma](https://paragraph.com/@yooma) · 2022-10-11

---

opensea是NFT最大的交易市场，对于这个交易就比如生活中我们买了辆车，买了个房子，卖家放到交易市场出售，买家购买。但是生活中并不是单单的只有买房卖房，有钱人毕竟是少数，绝大部分人还是租房住，那么对于Voxels，Decentraland等等平台那些NFT的owner如何出租自己的NFT，一些可能会短时间用到这些NFT的用户又不能花昂贵的钱买过来用两天就放着，这里就涉及到了租赁的功能

**介绍**

**首先看看什么是**[**ERC-20**](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/)

**ERC -- Ethereum Request for Comment 的缩写，用于对代币和以太坊生态系统提出改进建议。**

[**ERC-20**](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/) **是加密货币行业中最流行的代币标准。一类相同的代币，一个简单的接口，允许开发者在以太坊区块链之上创建他们的代币。通俗的讲 ERC-20 代币就像我们生活中钞票一样，可互换代币具有等值单位的相同资产**

**其次**

[**EIP-721**](https://erc721.org/) **则是不可替代的代币标准，是一类独特的令牌(Token)。就像所有的房子，收藏品等都是不同的，都有唯一的。**

**生活中我们用人民币/美元等买房子/车，这里我们可以说用符合ERC-20标准的代币去买一个符合EIP-721协议的NFT (例如使用ETH/USDC购买Voxels/Decentraland中的一块土地)，而这只购买，在购买之后NFT的owner也就改变，ERC-721中并没有实现可以租赁的功能**

[**EIP-4400**](https://eips.ethereum.org/EIPS/eip-4400)**和**[**EIP-4907**](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4907.md)**就是基于ERC-721的扩展，增加角色来达到可租赁的目的**

[**EIP-4400**](https://eips.ethereum.org/EIPS/eip-4400)**引入了consumer角色，对于引入这个角色需求也就源于这样一个事实。除了NFT的owner之外还可以有其他角色来对房子等NFT进行装饰使用，那么这个consumer被设置之后也就可以对该NFT进行使用装饰等操作**

**EIP-4400代码 增加了1个event和2个function分别是 ：**

*   当NFT的owner改变了consumer的时候发出，如果NFT的owner改变了那么consumer也就设置为空了
    
*   获取该NFT的consumer
    
*   更改NFT的consumer
    

    /// @title EIP-721 Consumer Role extension
    ///  Note: the EIP-165 identifier for this interface is 0x953c8dfa
    interface IEIP721Consumable /* is EIP721 */ {
      
        /// @notice Emitted when `owner` changes the `consumer` of an NFT
        /// The zero address for consumer indicates that there is no consumer address
        /// When a Transfer event emits, this also indicates that the consumer address
        /// for that NFT (if any) is set to none
        event ConsumerChanged(address indexed owner, address indexed consumer, uint256 indexed tokenId);
    
        /// @notice Get the consumer address of an NFT
        /// @dev The zero address indicates that there is no consumer
        /// Throws if `_tokenId` is not a valid NFT
        /// @param _tokenId The NFT to get the consumer address for
        /// @return The consumer address for this NFT, or the zero address if there is none
        function consumerOf(uint256 _tokenId) view external returns (address);
    
        /// @notice Change or reaffirm the consumer address for an NFT
        /// @dev The zero address indicates there is no consumer address
        /// Throws unless `msg.sender` is the current NFT owner, an authorised
        /// operator of the current owner or approved address
        /// Throws if `_tokenId` is not valid NFT
        /// @param _consumer The new consumer of the NFT
        function changeConsumer(address _consumer, uint256 _tokenId) external;
    }
    

[EIP-4907](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4907.md)**也引入了一个角色称为user，而且在这个基础之上增加了过期时间，当NFT租赁时间到期时会自动结束使用期限，不用第二次交易，这样就会节省gas费，而在之前的租赁当中NFT的owner要提交两笔链上交易，一笔在期限开始时将新地址列为新用户角色，另一笔在结束时收回用户角色**

*   更新user
    
*   设置user
    
*   获取user
    
*   获取过期时间
    
    在更新user和设置user的时候传入过期时间
    

    interface IERC4907 {
    
        // Logged when the user of an NFT is changed or expires is changed
        /// @notice Emitted when the `user` of an NFT or the `expires` of the `user` is changed
        /// The zero address for user indicates that there is no user address
        event UpdateUser(uint256 indexed tokenId, address indexed user, uint64 expires);
    
        /// @notice set the user and expires of an NFT
        /// @dev The zero address indicates there is no user
        /// Throws if `tokenId` is not valid NFT
        /// @param user  The new user of the NFT
        /// @param expires  UNIX timestamp, The new user could use the NFT before expires
        function setUser(uint256 tokenId, address user, uint64 expires) external;
    
        /// @notice Get the user address of an NFT
        /// @dev The zero address indicates that there is no user or the user is expired
        /// @param tokenId The NFT to get the user address for
        /// @return The user address for this NFT
        function userOf(uint256 tokenId) external view returns(address);
    
        /// @notice Get the user expires of an NFT
        /// @dev The zero value indicates that there is no user
        /// @param tokenId The NFT to get the user expires for
        /// @return The user expires for this NFT
        function userExpires(uint256 tokenId) external view returns(uint256);
    }
    

**EIP-4400和EIP-4907的区别**

**相同点：**

*   **都是为了NFT的租赁而出现的**
    
*   **都是基于EIP721的扩展在此基础之上实现了新增的功能**
    
*   **都增加了一个使用者的角色，在EIP4400中称为consumer，在EIP4907中称为user，而这个对应的就是租赁者**
    
*   **在lender想租出自己的NFT，把NFT挂到租赁平台租出去时，lender的NFT会被转移到合约平台的合约地址当中，此时合约平台会再给lender增加可以操作此NFT的权限以便在有人租赁此NFT之前lender可以继续使用自己的NFT**
    

**不同点：**

*   **在增加使用者角色之上EIP4907又增加了一个userExpires，在租赁到期时间无需再进行第二次交易**
    

[LandWorks](https://landworks.xyz/explore)是基于EIP-4400租赁，而[Double protocal](https://double.one/)是基于EIP-4907

[这篇文章](https://medium.com/double-protocol/3-steps-of-making-nfts-rentable-1-8d8f82485706)对于使NFT可租赁的方法进行了讲解

对于如何基于EIP-4907实现租赁，这篇文章做了讲解

[https://mirror.xyz/0x450AF1Ea236932c0e18B53BC1FeB15E47AA292df/VW2cNhU45VQu-7oJBBNkpZUdPcspW2bjvugIPv\_AyZs](https://mirror.xyz/0x450AF1Ea236932c0e18B53BC1FeB15E47AA292df/VW2cNhU45VQu-7oJBBNkpZUdPcspW2bjvugIPv_AyZs)

---

*Originally published on [Yooma](https://paragraph.com/@yooma/eip-4400-eip-4907)*
