Quick Programming
Published in

Quick Programming

Rentable NFTs with ERC-4907

Rentable NFTs and how to implement them.

Photo by Aaron Sousa on Unsplash

NFTs are coming in all shapes and sizes, and there are countless extensions to create the exact functionality you need. And because there are so many ways to implement these functionalities, the Ethereum community comes up with clever EIPs or Ethereum Improvement Proposals that set a standard for implementing certain functionalities.

This allows marketplaces like OpenSea to appropriately interact with NFT smart contracts without knowing the specifics of each contract. But because they implement a certain interface, OpenSea knows what to expect, and how to interact with the basic ERC721 (NFT standard) functionality.

ERC-4907

EIP-4907 is a proposal for a rentable NFT extension standard that can rent a simple NFT out to a certain address for a specific amount of time. It does so using a single function. Along with some functions for reading data.

setUser(tokenID, Address, ExpirationTimeStamp)
userOf(tokenID)
userExpires(tokenID)

setUser will rent out the token to a user by updating a mapping with all tokens that belong to addresses. mapping (uint256 => UserInfo where UserInfo is a struct containing an address and an uint64 expiration timestamp.

The full code is as follows.

With IERC4907 available here, and ERC721 being the standard as written here.

We can see that ERC4907 only adds additional functionality to ERC721 so that it can be used on marketplaces like OpenSea and Rarible. It only adds a new mapping from which a temporary lender can be found, and if implemented in your dApp, they can use the token as their own.

If the token is transferred from the original owner to anyone else, the _users mapping will reset the owner of the token so the lender cannot use it anymore.

The original owner will also always have the option to update the lender’s information and can stop lending the token at any time.

Conclusion

I hope that this was useful for some of you! Please check out my other articles on smart contracts if you’ve enjoyed this one!

Thank you so much for reading and have an excellent day.

Consider supporting me by getting a Medium membership. It helps me out a lot, it won’t cost you anything extra, and you can read as many Medium articles as you like!

Follow me on Twitter and gm.xyz to keep up with me and my projects.

Check out Pixel Pizzas on Polygon.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
mbvissers.eth

mbvissers.eth

I occasionally write about programming and smart contracts. Follow me on Twitter @0xmbvissers