# Collateral-Free Integration Guide

![reNFT collateral-free contract flows](https://3102760751-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHx6VlzrcQxjsYD9J3le4%2Fuploads%2Fp13K2RZ1M10oY3AJb47S%2F220719_Up-Front%20Payment_Info.png?alt=media\&token=24c726c5-e3ec-4004-b58c-13f43d465454)

> **The following discussion applies to `v5.0.4` of the SDK.**

### Lend/Rent NFTs In-App[​](https://docs.renft.io/docs/Developers/collateral-free#lendrent-nfts-in-app) <a href="#lendrent-nfts-in-app" id="lendrent-nfts-in-app"></a>

To interact with our smart contract, we'd recommend using our [SDK](https://github.com/re-nft/sdk).

The ReNFT object takes in an ethers [Signer](https://docs.ethers.io/v5/api/signer/#Signer) and an optional contract address if not using the default collateral-free contract.

```typescript
import { Sylvester } from "@renft/sdk";
const renft = new Sylvester(signer);
```

We name our contracts after famous cats. You can find the name mappings [here](https://docs.renft.io/developers/renft-contracts-addresses). `Sylvester` is the code-name for the collateral free contract.

### Batching[​](https://docs.renft.io/docs/Developers/collateral-free#batching) <a href="#batching" id="batching"></a>

Any of the following functions support batching as shown below for the Lend instruction where the user lends an AstroCat and a CatPlsr in the same function call:

```typescript
import { NFTStandard, PaymentToken, packPrice } from "@renft/sdk";

const astroCatLendingArgs = [
  NFTStandard.E1155,
  "0x0db8c099b426677f575d512874d45a767e9acc3c",
  "1",
  1,
  1,
  packPrice("1"),
  PaymentToken.WETH,
];

const catPlsrLendingArgs = [
  NFTStandard.E1155,
  "0x0db8c099b426677f575d512874d45a767e9acc3c",
  "2",
  1,
  1,
  packPrice("0.5"),
  PaymentToken.WETH,
];

const lendingArgs = astroCatLendingArgs.map((value, index) => {
  return [value, catPlsrLendingArgs[index]];
});

await renft.lend(...lendingArgs);
```

### Lend <a href="#lend" id="lend"></a>

```typescript
import { NFTStandard, PaymentToken, packPrice } from "@renft/sdk";

const nftStandard = NFTStandard.E1155;
const nftAddress = "0x0db8c099b426677f575d512874d45a767e9acc3c";
const tokenID = "1";
const lendAmount = 1; // qty of the NFT to lend
const maxRentDuration = 1; // in days
const dailyRentPrice = packPrice("1");
const paymentToken = PaymentToken.WETH;

await renft.lend(
  [nftStandard],
  [nftAddress],
  [tokenID],
  [lendAmount],
  [maxRentDuration],
  [dailyRentPrice],
  [paymentToken]
);
```

### Rent[​](https://docs.renft.io/docs/Developers/collateral-free#rent) <a href="#rent" id="rent"></a>

```typescript
import { NFTStandard } from "@renft/sdk";

const nftStandard = NFTStandard.E1155;
const nftAddress = "0x0db8c099b426677f575d512874d45a767e9acc3c";
const tokenID = "1";
const lendingID = "1"; // this information is pulled from the subgraph
const rentDuration = 1; // in days
const rentAmount = 1;

await renft.rent(
  [nftStandard],
  [nftAddress],
  [tokenID],
  [lendingID],
  [rentDuration],
  [rentAmount]
);
```

### Stop Rent <a href="#stop-rent" id="stop-rent"></a>

Even though no real posession of the NFT is given, the renter must signal that they have concluded "using" the NFT with this call. If the renter fails to do so, then the lender can invoke "Claim Rent" explained below, to redeem the full amount of rent. Note that "Stop Lend" will be blocked until the user calls "Claim Rent" first.[​](https://docs.renft.io/docs/Developers/collateral-free#stop-rent)

```typescript
import { NFTStandard } from "@renft/sdk";

const nftStandard = NFTStandard.E1155;
const nftAddress = "0x0db8c099b426677f575d512874d45a767e9acc3c";
const tokenID = "1";
const lendingID = "1"; // from subgraph
const rentingID = "1"; // from subgraph

await renft.stopRent(
  [nftStandard],
  [nftAddress],
  [tokenID],
  [lendingID],
  [rentingID],
);
```

### Claim Rent[​](https://docs.renft.io/docs/Developers/collateral-free#claim-rent) <a href="#claim-rent" id="claim-rent"></a>

```typescript
import { NFTStandard } from "@renft/sdk";

const nftStandard = NFTStandard.E1155;
const nftAddress = "0x0db8c099b426677f575d512874d45a767e9acc3c";
const tokenID = "1";
const lendingID = "1";
const rentingID = "1";

await renft.claimRent(
  [nftStandard],
  [nftAddress],
  [tokenID],
  [lendingID],
  [rentingID],
);
```

### Stop Lend[​](https://docs.renft.io/docs/Developers/collateral-free#stop-lend) <a href="#stop-lend" id="stop-lend"></a>

```typescript
import { NFTStandard } from "@renft/sdk";

const nftStandard = NFTStandard.E1155;
const nftAddress = "0x0db8c099b426677f575d512874d45a767e9acc3c";
const tokenID = "1";
const lendingID = "1";

await renft.stopLend(
  [nftStandard],
  [nftAddress],
  [tokenID],
  [lendingID],
);
```

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

To learn about how to learn about the status of a particular lending / rental, read [here](https://docs.renft.io/developers/querying-renfts-on-chain-data).

### Unpacking Data[​](https://docs.renft.io/docs/Developers/collateral-free#unpacking-data) <a href="#unpacking-data" id="unpacking-data"></a>

Prices are returned in a custom format (rationale for this format was to fit the lending into a single storage slot). To unpack them, use our [SDK](https://github.com/re-nft/sdk/tree/registry)'s `unpackPrice` function:

```typescript
import { PaymentToken, unpackPrice } from "@renft/sdk";

const parsePaymentToken = (tkn: string): PaymentToken => {
  switch (tkn) {
    case "0":
      return PaymentToken.SENTINEL;
    case "1":
      return PaymentToken.WETH;
    case "2":
      return PaymentToken.DAI;
    case "3":
      return PaymentToken.USDC;
    case "4":
      return PaymentToken.USDT;
    case "5":
      return PaymentToken.TUSD;
    default:
      return PaymentToken.DAI;
  }
};

const lendingsDataToLendings = (
  theGraphLendings: TheGraphLending[]
) => {
  const theGraphToLending = (theGraphLending: TheGraphLending) => {
    return {
      lendingID: theGraphLending.id,
      lenderAddress: theGraphLending.lenderAddress,
      dailyRentPrice: unpackPrice(theGraphLending.dailyRentPrice),
      maxRentDuration: Number(theGraphLending.maxRentDuration),
      lendAmount: Number(theGraphLending.lendAmount),
      paymentToken: parsePaymentToken(theGraphLending.paymentToken),
      lentAt: Number(theGraphLending.lentAt),
    };
  };

  return theGraphLendings.map(theGraphToLending);
};
```
