Integration Steps
Last updated
Last updated
To help you integrate more efficiently, we have summarized the following integration development steps and provided an integration example for better understanding.
There are five steps:
Install and setup RentFun.
Add rental-related fields to the NFT structure, primarily two fields: rented (boolean) and endTime (number).
Default values for these fields could be: {rendted: false, endTime: 0}
.
Rental NFTs returned by the SDK will include these fields. Here's the Rental structure:
endTime is a timestamp in seconds, vault is a contract address used to hold the NFT.
Modify the method for obtaining user NFTs to include the user's rented NFTs.
Monitor the rental's remaining time.
Use
rented && endTime < Math.floor(Date.now() / 1000)
to determine whether the rental has expired.
Display the two new fields: rented and endTime.
You can skip this step if you don't want to display these fields.
Install and setup RentFun.
The commit used yarn add rentfun
, which updated both yarn.lock
and package.json
.
Add rental-related fields to the NFT structure.
Modify the method for obtaining user NFTs.
The name getUserTurtles was renamed to getOwnedTurtles and default values rented: false
, endTime: 0
were added to the returned metadata structure.
Another function, getRentedTurtles, was added to get the user's rented NFTs.
A new function was created with the same name as getUserTurtles to combine the results of getOwnedTurtles and getRentedTurtles. This way, the previous calls to getUserTurtles don't require any changes. The new function looks like this:
Monitor the rental's remaining time during gameplay to end the game when the rental expires.
Display the two new fields: rented and endTime.
is an open-source NFT game integrated with RentFun.
This of Game-Turtis contains all the code changes needed for RentFun integration. Below is an explanation of the changes in this commit to help you better understand the integration steps above.
This change can be seen in the file , where you can also see the Rental structure that will be used later in a new funtion called getRentedTurtles.
Previously, there was a function called getUserTurtles in the file used to get user NFTs. This function was modified as follows:
Implement listening to endTime and controlling the end of the game through the file . Code could be like this:
The other two files, and , was modified to help the file GameManager.ts obtain the values of the two new fields: rented and endTime.
This change can be seen in the file .