Risk Warning: Beware of illegal fundraising in the name of 'virtual currency' and 'blockchain'. — Five departments including the Banking and Insurance Regulatory Commission
Information
Discover
Search
Login
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt
BTC
ETH
HTX
SOL
BNB
View Market
Source code interpretation: How does the new Ethereum standard EIP-4907 realize NFT leasing?
十四君
特邀专栏作者
2022-07-07 07:51
This article is about 1954 words, reading the full article takes about 3 minutes
Let's read this minimal source code together to understand how other NFT leases are implemented?

abstract

secondary title

This week, the rentable NFT standard "EIP-4907" submitted by the NFT rental market Double Protocol passed the final review of the Ethereum development team and became the 30th ERC standard "Final" status.

Let's read this minimal source code together to understand how other NFT leases are implemented?

secondary title

Why do you need a lease?

The explosion of NFT is undoubted, and its popularity has led to the demand for its asset practicability, especially in the metaverse and play-to-earn (P2E) scenarios, pure asset ownership is not enough to support more application gameplay birth.

The shortage of NFT liquidity has made him very popular and has been criticized at the same time. His previous financial operations of property rights integration have caused various security issues in the market, such as fraud, plagiarism, fishing, running away, and asset theft.

What Eip-4907 wants to solve is to separate the asset value and use value of NFT, and release the market liquidity of NFT

Source code interpretation

Since Eip4907 is extremely simple, no matter whether you are a technical student or not, you can try to understand the detailed design of the code.

secondary title"2.1. Implementation principle:

As an extension of ERC-721, EIP-4907 adds a variable UserInfo, so that the application can query the target address "user" and lease time" expires of this NFT.

  • . If it is found that the lease time has exceeded, the lease relationship will be declared invalid.

  • The code is extremely simple and only has 72 lines. Using this standard is to add on top of the original ERC721

1 event (used to notify off-chain applications is called an event)

  • 3 methods (used to implement on-chain data management functions)

  • respectively

  • UpdateUser event: When the NFT is transferred and the rental color setting is set, a notification of the rental user change is issued

  • userOf method: Available to anyone, query the rental users of this NFTID

userExpires method: Available to anyone, query the expiration time of this NFTID

secondary title

The best way to understand the ERC standard protocol is to understand the underlying data structure that manages data[Source Code Interpretation] What exactly is the NFT you bought?

For example: previous text

[Source Code Interpretation] What exactly is the NFT you bought?

In fact, NFT only records data through two mappings (_owners, _balances), that is, a storage structure of key-value correspondence in the form of a dictionary

Eip-4907 adds a new data object UserInfo to increase the dimension of "user" in addition to the concept of ownership

The data structure is simple, which means that the implementation of the management method is also very simple

  • 2.2. Set user setUser method

  • Setting up users is only 3 steps

  • 【Audit】Whether the initiator of this transaction holds this NFTid or has the right to automatically debit Approved

[Settings] Set the user address and expiration time of the user in UserInfo

【Notice】Send an UpdateUser event that is set successfully

2.3. Query the user information of NFTid

The timeout that the media advertises everywhere automatically expires, and the logic of saving gas without the need for secondary on-chain transaction registration invalidation is here.

2.3. Query the user expiration time information of NFTid

Here, there is no need to judge whether it has expired like user query, because knowing the last expiration time is also a way to speed up the usage rate of NFT users.

This eip4907 protocol adds part of the content to the standard transaction method Transfer. It is implemented through _beforeTokenTransfer, which is to force the deletion of this part of the user's information after the Transfer transaction is transferred, and send an event notification that the user has expired.

Summarize

SummarizeCan EIP-5058 prevent NFT project parties from running away with buckets?

Unexpectedly, the code is finished so soon, because he has indeed finished writing it, yes, it is not like the previous method of restricting transfer rights EIP-5058, see the previous article [

Can EIP-5058 prevent NFT project parties from running away with buckets?

In fact, his EIP-4907 is just an extra variable, and it is called a rental user. It can be declared, but whether other applications recognize it is another matter. After all, its mandatory is limited, and the transfer can forcibly terminate the rental authorization.

Of course, you may ask, why is it so simple and quickly become a rare Final standard that can make waves every time?

The explosion of web3 in the past may have benefited from financial operations, but a good ecology can not only be of financial value, but also needs to have more commercial value, and requires a wider range of users to integrate into life and production to form a value closed loop. After all, currency is only a means rather than an end itself.

Quote:

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4907.md

Can EIP-5058 prevent NFT project parties from running away with buckets?

[Decryption] The NFT created by OpenSea for free can appear in my wallet without being linked to the chain?

[Source Code Interpretation] What exactly is the NFT you bought?

Can EIP-5058 prevent NFT project parties from running away with buckets?

What are we looking at when we look at Etherscan?

When Netflix's NFT forgets web2's business security

ETH
Welcome to Join Odaily Official Community