Collateral-Free Integration Guide
The official instructions on how to interact with our open Collateral-Free rental contracts.
Last updated
import {
getRenftContract,
DEPLOYMENT_SYLVESTER_ETHEREUM_MAINNET_V0,
SylvesterV0FunctionInterface,
} from "@renft/sdk";
import { ethers } from "ethers";
const signer = ethers.Wallet.createRandom(); // In practical dApps, this would be the user's wallet!
const renft: SylvesterV0FunctionInterface = getRenftContract({
deployment: DEPLOYMENT_SYLVESTER_ETHEREUM_MAINNET_V0,
signer,
});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) =>
[value, catPlsrLendingArgs[index]]
);
await renft.lend(...lendingArgs);import { NFTStandard, PaymentToken, packPrice } from "@renft/sdk";
const nftStandard = NFTStandard.E1155;
const nftAddress = "0x0db8c099b426677f575d512874d45a767e9acc3c";
const tokenID = "1";
const lendAmount = 1; // Quantity of the NFT to lend.
const maxRentDuration = 1; // Duration is measured in days.
const dailyRentPrice = packPrice("1"); // Create a properly formatted rental price.
const paymentToken = PaymentToken.WETH;
await renft.lend(
[nftStandard],
[nftAddress],
[tokenID],
[lendAmount],
[maxRentDuration],
[dailyRentPrice],
[paymentToken]
);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]
);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],
);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],
);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],
);import { PaymentToken, unpackPrice } from "@renft/sdk";
// Convert a low-level representation of an ERC-20 used on
// the marketplace into a TypeScript-friendly enum.
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;
}
};
// In this example, let's imagine we've read Lending collection data
// from a Sylvester subgraph. Here's how we'd transform the low-level
// blockchain data into high-level, human (and feline) friendly types.
const lendingsDataToLendings = (
theGraphLendings: TheGraphLending[]
) => {
const theGraphToLending = (theGraphLending: TheGraphLending) => {
return {
lendingID: theGraphLending.id,
lenderAddress: theGraphLending.lenderAddress,
// Convert the price back into a BigNumber.
dailyRentPrice: unpackPrice(theGraphLending.dailyRentPrice),
maxRentDuration: Number(theGraphLending.maxRentDuration),
lendAmount: Number(theGraphLending.lendAmount),
paymentToken: parsePaymentToken(theGraphLending.paymentToken),
lentAt: Number(theGraphLending.lentAt),
};
};
return theGraphLendings.map(theGraphToLending);
};