Create Rentable NFTs with the ERC4907 standard

Create Rentable NFTs with the ERC4907 standard - thirdweb Guides

In this guide, we'll show you how to create rentable NFTs using the ERC4907 standard; which allows the owner of an NFT to give another user temporary use of the NFT!

Let's get started!

What is the ERC4907 Standard?

ERC4907 is a standard for non-fungible tokens (NFTs) that can be rented out to other wallets. This means this NFT will have an owner as well as a user.

This is useful in cases where you don't want to transfer the ownership of the NFT, but instead, rent it out for a certain time period to some other wallet.

Deploy the ERC4907 Smart Contract

To deploy the contract, head to the Contracts page in your thirdweb Dashboard and hit "Deploy new contract":

deploy new contract
deploy new contract

You will be taken to our Explore page — where you can browse smart contracts built by the top protocols in web3 and deploy them in just a few clicks!

thirdweb explore page
thirdweb explore page

Select the ERC4907 contract. You will be presented with the following screen:

ERC4097 contract on thirdweb explore
ERC4097 contract on thirdweb explore

Click on the Deploy Now button and you will be presented with a dialogue asking you for the contract parameters. Here are the example parameters:

ERC4907 contract example parameters
ERC4907 contract example parameters

Let's briefly look at what these parameters mean:

  • _name: Collection name - this is typically what is shown on the NFT collection pages on platforms like OpenSea.
  • _symbol: Symbol for the NFTs (i.e. the ticker).
  • _royaltyRecipient: Wallet or smart contract address that will receive the royalties.
  • _royaltyBps: What percentage royalty fee you take on secondary sales. *(100 royalty basis points is 1% of royalty).

Feel free to change the parameters. Then, select the desired network and click on Deploy Now.

This will trigger a transaction to deploy the smart contract! After the process is complete, you will be redirected to the contract dashboard:

Contract dashboard for ERC4907 contract
Contract dashboard for ERC4907 contract

How To Rent NFTs

Let's mint an NFT so that we can rent it out to some other wallet!

Go to the NFTs tab on the top and click on the Mint button. Add the details for your NFT and click on the Mint NFT button. This will trigger a transaction and your NFT should be now visible on the NFTs tab:

NFT minted under NFT tab
NFT minted under NFT tab

Now to rent the NFT out, go to the Explorer tab and click on the setUser function from the Write section.

Enter the token ID of the NFT you want to rent out, the user of the NFT and the expires field that tells when the NFT can no longer be used by the user. This field accepts UNIX timestamp that you can generate here.

Renting out NFT
Renting out NFT

Click on Execute and approve the transaction. Once the transaction is successful, you've successfully rented out your NFT!

To check the rental status, use the userOf function in the Read section. Enter the token ID of your NFT and if the rental is still active you should see the address of the wallet that has been rented:

Checking rental status
Checking rental status

In cases where the expires time has passed and the user no longer holds the right to use the NFT, zero address will be returned when the userOf function is invoked:

Zero address returned when NFT no longer rented
Zero address returned when NFT no longer rented

You can now check the Code tab to get code snippets that you can use in your app to interact with this contract to create a seamless experience for your users.

Conclusion

Rental NFTs have a lot of use cases that include renting land, pieces of art, or even software licenses. In this guide, we saw how you can set up your own rental NFT smart contract easily using the dashboard.

If you face any errors or have any suggestions, feel free to join the Discord server and talk to the team!