LogoLogo
HomeLaunch App
  • Introduction
  • General Info
    • Rental Use Cases
    • Compatible Blockchains
    • Whitelabel Interface
    • Custom Solutions
    • Protocol Composability
    • Protocol Fee
    • Frequently Asked (FAQ)
  • Rental Solutions
    • Collateral-Free
    • Collateralized
  • Developers
    • Integration Guide
    • SDK
      • @renft/sdk@^v6.0.0
        • Interacting with Smart Contracts
        • Collateral-Free Integration Guide
        • Castle Crush (Reward Share)
      • @renft/sdk@v5.0.4
        • Collateral-Free Integration Guide
        • Castle Crush (Reward Share)
    • reNFT Contracts' Addresses
    • Querying reNFT's on-chain data
      • Castle Crush (Reward Share)
  • Video Tutorials
    • Collateral-Free
      • How To Lend
      • How To Rent
    • Castle Crush (Reward Share)
      • How To Lend
      • How To Rent
    • Collateralized
      • How To Lend
      • How To Rent
      • Returning & Defaulting
    • Expired Rentals
  • About reNFT
    • Team
    • Contact
Powered by GitBook
On this page
  • Expired Rentals
  • Elapsed Rentals
  1. Video Tutorials

Expired Rentals

How to know when a rental on reNFT has expired?

PreviousReturning & DefaultingNextTeam

Last updated 2 years ago

When we query for rentals on a , there are various attributes which define the time-variant rental status of a Renting. These attributes are: rentedAt, rentDuration and expired; and they are often easily misinterpreted.

In this short section, we'll demystify the purpose of these fields.

Expired Rentals

The Rental subgraph data modal possesses an expired property. This is used to define when a rental successfully terminated within the agreement of the rental period.

By taking a look through the (which indexes high-level representations of all on-chain transactions which took place), we can see that when a rental has been claimed, the Rental object is marked as expired.

Conversely, the expired property initialized to false when a Rental is first initiated.

Elapsed Rentals

If the current date is greater than the time the asset was rented plus the duration of the rent, the rental period has been exceeded by the renter.

This rental state can be determined programmatically by consulting the appropriate subgraph for the smart contract the rental took place on. Using GraphQL to query a subgraph, we can determine the rentedAt and rentDuration of a specific Renting as follows:

{
  renting(id: "2") {
    id
    rentedAt
    rentDuration
    expired
  }
}

Upon this request, the subgraph will provide the caller with a Renting data model with the specified expiration fields included, for instance:

{
  "data": {
    "renting": {
       "id": "1",
      "rentedAt": "1671617899",
      "rentDuration": "1",
      "expired": false
    }
  }
}

Note that there are no on-chain events for an expiration, since this would require an associated transaction.

In this regard, if we need to determine if a rental has expired off-chain, we must compute the time at which a rental expires and compare this against the current time.

Below, we outline an example implementation in TypeScript:

const rentedAtInSeconds = Number(renting.rentedAt);
const rentDurationInDays = Number(renting.rentDuration);

const rentedAtMilliseconds = new Date(rentedAtInSeconds * 1000).getTime();
const rentDurationMilliseconds = rentDurationInDays * 24 * 60 * 60 * 1000;

const now = Date.now(); // Current time in milliseconds.

const rentingHasElapsed =
  now > rentedAtMilliseconds + rentDurationMilliseconds;
  
if (rentingHasElapsed)
  doSomethingWithElapsedRenting(renting); // Perform some app-specific handling.
Subgraph
Subgraph Mapping
we can see