How to Create a Rentable NFTs

Posted By : Rishab

Mar 24, 2023

Introduction to NFT Renting

 

NFT renting, also known as NFT leasing, is a process where individuals who do not own a particular NFT can borrow or rent it from the owner for a set time. This process is facilitated by smart contracts, which manage the terms and conditions of the rental agreement. After the rental period ends, the NFT is returned to its original owner. Businesses can now benefit from NFT development while building diverse NFT rental platforms.

 


You may also like |  How to Create a Compressed NFT on Solana

 

How do NFT Rentals Work?

 

In most cases, it all starts with the NFT rental market. A few platforms that let users rent NFTs are Trava NFT, UnitBox DAO, Vera, N3RP, reNFT, Double Protocol, and IQ Protocol.
But, here we focus on creating a smart contract that facilitates the process of renting your NFT:

 

Also, Read | A Detailed Guide to NFT Minting on Solana using Metaplex API


To rent an NFT, you can follow these general steps:- 

 

Create or mint the NFT

 

Using a blockchain platform, you can create a unique token that represents ownership of the asset.

 

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol";

interface IERC4907 {
   // Logged when the user of a token assigns a new user or updates expires
   /// @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 a 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);
  
}
 
contract ERC4907 is ERC721, IERC4907 {
   struct UserInfo
   {
       address user;   // address of user role
       uint64 expires; // unix timestamp, user expires
   }

   mapping (uint256  => UserInfo) internal _users;

   constructor(string memory name_, string memory symbol_)
    ERC721(name_,symbol_)
    {
    }

   /// @notice set the user and expires of a 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) public virtual{
       require(_isApprovedOrOwner(msg.sender, tokenId),"ERC721: transfer caller is not owner nor approved");
       UserInfo storage info =  _users[tokenId];
       info.user = user;
       info.expires = expires;
       emit UpdateUser(tokenId,user,expires);
   }

   /// @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)public view virtual returns(address){
       if( uint256(_users[tokenId].expires) >=  block.timestamp){
           return  _users[tokenId].user;
       }
       else{
                 return address(0);
       }
   }

   /// @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) public view virtual returns(uint256){
       return _users[tokenId].expires;
   }

   /// @dev See {IERC165-supportsInterface}.
   function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
       return interfaceId == type(IERC4907).interfaceId || super.supportsInterface(interfaceId);
   }

   function _beforeTokenTransfer(
       address from,
       address to,
       uint256 tokenId
   ) internal virtual override{
       super._beforeTokenTransfer(from, to, tokenId);

       if (from != to && _users[tokenId].user != address(0)) {
           delete _users[tokenId];
           emit UpdateUser(tokenId, address(0), 0);
       }
   }
}

contract RentableNft is ERC4907 {

   constructor(string memory name_, string memory symbol_)
    ERC4907(name_,symbol_)
    {
       }

   function mint(uint256 tokenId, address to) public {
       _mint(to, tokenId);
   }

}

 

Set up the rental terms

 

Determine the rental period, rental fee, and any conditions or restrictions on the NFT.

 

List the NFT for rent

 

Once the rental conditions are finalized, list your NFT on rental platforms for interested people to browse, once the rental conditions are finalized by the owner.

 

Transfer ownership for a stipulated period

 

When someone rents their NFT, they transfer their ownership as a rental period. This can be done with the help of smart contracts that we created above. At the end of the rental period, ownership will revert to the actual owner.

 

If an agreement is reached, the price, rental period, and other relevant factors will be executed by the smart contract. The lessee sends the desired amount of cryptocurrency to the smart contract, and once the lease period is over, the smart contract returns the NFT to its rightful owner.

 

Sometimes smart contracts require tenants to provide some security. If the lessee does not return the NFT within the specified time, the security will be sent to the owner of the NFT. Some platforms require no collateral, but instead of offering real NFTs, smart contracts are created and issued wrapped NFTs to tenants.

 

Also, Explore |  NFT-Based Loyalty Programs: Revamping Customer Engagement

 

Here are some platforms that offer Rentable NFT services

 

Notable NFT Leasing/Renting Platforms:-

 

  • reNFT - Metaverse's Multi-Chain NFT Leasing Framework
  • UnitBox DAO - A Revenue Share Model-Based NFT Leasing Protocol
  • Vera - A Multi-Chain Defi Protocol for Leasing and NFT staking
  • IQ Protocol - Free protocol for NFTs and fungible tokens for rent without collateral
  • Defy - Decentralized multi-chain protocol for renting, lending, and staking NFTs

 

If you have a project in mind related to related to NFTs, feel free to connect with our skilled NFT developers. Get in touch today!

Leave a

Comment

Name is required

Invalid Name

Comment is required

Recaptcha is required.

blog-detail

October 8, 2024 at 03:09 pm

Your comment is awaiting moderation.

By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.

Chat with Us
Telegram Button
Youtube Button
Contact Us

Oodles | Blockchain Development Company

Name is required

Please enter a valid Name

Please enter a valid Phone Number

Please remove URL from text