# Querying reNFT's on-chain data

## Collateral Free (aka Traditional Rentals)

### Ethereum

#### Get Renters[​](https://docs.renft.io/docs/Developers/collateral-free#query-loanrental-status) <a href="#query-loanrental-status" id="query-loanrental-status"></a>

To know who the active renters of your collection are at any point in time, you should make a GraphQL API request. Here is GraphiQL playground for you. It's useful for testing out queries:

{% embed url="<https://api.studio.thegraph.com/proxy/3020/sylvester/1.0.3/graphql?query=query+CollectionRenters%28%24nftAddress%3A+Bytes%21%29+%7B%0A++rentings%28%0A++++where%3A+%7B%0A++++%09lending_%3A+%7BnftAddress%3A+%24nftAddress%7D%2C%0A++++++expired%3A+false%2C%0A++++++cursor_gt%3A+0%0A++%09%7D%2C%0A++++first%3A+1000%2C%0A++++skip%3A+0%2C%0A++++orderBy%3A+cursor%2C%0A++++orderDirection%3A+desc%0A++%29+%7B%0A++++id%0A++++cursor%0A++++renterAddress%0A++++rentedAt%0A++++rentDuration%0A++++rentAmount%0A++++lending+%7B%0A++++++nftAddress%0A++++++tokenID%0A++++%7D%0A++%7D%0A%7D>" %}
reNFT Ethereum contract's GraphiQL client
{% endembed %}

Here is what it looks like if you follow the above link:

<figure><img src="https://3102760751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHx6VlzrcQxjsYD9J3le4%2Fuploads%2FRLotOk4zPhhMT6WFJVm0%2Fcollectionrenters.png?alt=media&#x26;token=506dda08-20c4-4b9f-ae83-6dc82f2a5718" alt=""><figcaption></figcaption></figure>

To actually make calls from your client, you simply make GraphQL POST requests to the following URL: `https://api.studio.thegraph.com/query/3020/sylvester/1.0.3`

You can play around with our GraphQL API schema in the GraphiQL UI. You will notice we have information such as `lendings` as well. However, you are interested in `rentings`, so that you can pinpoint who the current renters of your NFTs are. To do so, use the following query:

```graphql
query CollectionRenters($nftAddress: Bytes!) {
  rentings(
    where: {
    	lending_: {nftAddress: $nftAddress},
        expired: false,
        cursor_gt: 0
    },
    first: 1000,
    skip: 0,
    orderBy: cursor,
    orderDirection: desc
  ) {
    id
    cursor
    renterAddress
    rentedAt
    rentDuration
    rentAmount
    lending {
      nftAddress
      tokenID
    }
  }
}
```

Let's walk through the above. You need to supply `nftAddress` parameter in this query. This is your collection's address on Ethereum (this section concerns Ethereum renters querying). We have an `expired` flag that gets set to `true` when the rentings has overrun its duration and the lender has collected their payment on our dapp. **Note** that on Ethereum, rentals can over-run their duration. In our own API that is releasing soon, we will only return you rentals that are active at a given point in time. With the above approach, however, there is an extra step you need to do to ensure rental is in fact active. We will talk about it shortly. `cursor_gt: 0` is a way to paginate, that you will only ever need if you have more than `1000` active rentals at any given point in time. The restriction on this API is that it can only return a maximum of `1000` items. That is why we have: `first: 1000`. If you have more active rentals, then you will need to paginate like this (until you retrieve all rentals):

```graphql
query CollectionRenters($nftAddress: Bytes!) {
  rentings(
    where: {
    	lending_: {nftAddress: $nftAddress},
        expired: false,
        cursor_gt: 2003
    },
    first: 1000,
    skip: 1000,
    orderBy: cursor,
    orderDirection: desc
  ) {
    id
    cursor
    renterAddress
    rentedAt
    rentDuration
    rentAmount
    lending {
      nftAddress
      tokenID
    }
  }
}
```

The most important part here is that we have changed the value of `cursor_gt: 2003`. Taken the resultset of the original query, we noticed, hypothetically that the max `cursor` value was `2003`. This now retrieves the next `1000` rentals (or however many are left). You then repeat this process as required.

Note that `id` and `cursor` are equivalent. This is your renting id, you will not need to use it, but `cursor` is `Int` so that we can easily paginate. If we were to order the `id` which is a string, we would get an incorrect ordering of items.

We are now at a stage where we can talk about what information you need to use in your application / game to enable rentals. You simply recognise the result-set you are getting from this query as renters. You get their wallet addresses by looking at the `renterAddress` field above.

Finally, a note on `expired`. As I have mentioned previously, you need to do a small extra step here. After a rental over-runs its duration (that is to say, you take `rentedAt` UTC timestamp and add `rentDuration * 24 * 60 * 60` (duration in seconds) and compare to current UTC timestamp), its `expired` is still `false`. This is because our contract requires triggering of a particular function for lender (or anyone for that matter) to invoke for them to collect the rental payments. This action emits an on-chain event that then sets `expired` to true. So, the extra step that you need to take here is to simply after having received all the rentals from the above queries, go through each one and ensure that:

`rentedAt + rentDuration * 24 * 60 * 60 > current_timestamp_in_utc`

whatever rental items you have left after applying the above filter will ensure that you have the set of currently active rentals. Note that you can also take a route of writing a bot that invokes the mentioned function for your users. This would then ensure that all the rentals you are getting from the queries above are definitively active. If you are interested in how to do this, see this [repository](https://github.com/re-nft/example-stop-rent-bot/tree/main) (we are using this bot on polygon to stop rentals for everyone).

## Polygon

TODO
