Expired Rentals
How to know when a rental on reNFT has expired?
When we query for rentals on a Subgraph, 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 Subgraph Mapping (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, we can see 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:
Upon this request, the subgraph will provide the caller with a Renting
data model with the specified expiration fields included, for instance:
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:
Last updated