Implement Borrower Features
This page describes how you can implement Borrower features into your Platform.
Typically, web3 platforms implement two types of utilities (features) for NFTs: on-chain and off-chain.
On-chain utility refers to smart contracts, meaning only holders of a specific NFT can call a function.
Off-chain utility refers to features external to the blockchain. For example, a game only allows holders of a specific NFT to access their website.
The following section will discuss how you can enable Borrowers to use on-chain and off-chain utilities.
Enabling Off-chain Utility
When integrating NFTs with only off-chain utility, developers don't need to deploy additional solidity to enable NFT Rentals.
Let's say you are a developer building a game that entirely runs on a backend (server or cloud). The only blockchain aspect of your game is that items are represented as NFTs, which can be bought, sold, and transferred directly in the blockchain.
To enable a Borrower to access the utility of a borrowed NFT, all your system needs to do is recognize which NFTs your users are borrowing at any given time. There are multiple ways for your backend to find out this information:
Monitoring Events: The Roles Registry contract issues a blockchain event every time an NFT is rented. You can monitor these events directly on the blockchain and store all rentals in a database for your backend.
Calling View Functions: The Roles Registry contract also has view functions that can query the state of a rental. All functions and events are documented in the ERC-7432 specification.
Subgraph API: TheGraph is a blockchain indexing technology that allows developers to query indexed data easily. You can use the subgraph GraphQL API to find if your user has any rentals.
Orium API: Orium's API is also a great way to determine if your users have active rentals. This API has additional filters and sorting features to facilitate the integration process.
You can Contact our team to get access to the Orium and Subgraph's APIs.
Enabling On-chain Utility
Assume you are developing a blockchain game where only the owner can farm tokens using an NFT. To expand your community, you decide to allow NFT holders to rent their NFTs when they are not using them.
To farm tokens, users have to call the following function:
Now, you want to allow an NFT Borrower to do that on behalf of the user. To implement this feature, we can modify the farm function to check if the NFT is rented:
Last updated