npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nftsafe/sdk

v0.0.9

Published

Lend and rent any ERC721s and ERC1155s on supported mainnet and testnet.

Downloads

8

Readme

Welcome to NFTSafe SDK

Lend and rent any ERC721s and ERC1155s on supported mainnet and testnet.

NFT Safe allows you to lend and rent ERC 721 and ERC 1155 NFTs in collateralized and collateral free way.

Install

yarn add @nftsafe/sdk or Add "@nftsafe/sdk": "latest-version" to your package.json

How to access:

import-module in your in page import { SupportedChainIds, ContractType, GetNetworkDetailsByChainId, CONTRACT_TYPE_LIST,SupportedChainIds, ALL_SUPPORTED_CHAIN_IDS ....} from '@nftsafe/sdk'

Get Contract and Network details:

SDK provider the "NetworkConfig" JSON to get the Contract addresses, Subgraph URL, Chain information, and the Blockchain supporting utils
NetworkConfig = { chainid: { name: string, chainId: number, shortName: string, chain: string, networkId: number, nativeCurrency: {}, rpc: string[], faucets: string[], explorers: { name: string, url: string, standard: string }, infoURL: string, logoURL: string, collateralizedContractAddresses: string[], collateralFreeContractAddresses: string[], revenueSharedConfiguratorContractAddresses: string[], e721ContractAddresses: string[], // Testnet e721BContractAddresses: string[], // Testnet e1155ContractAddresses: string[], // Testnet e1155BContractAddresses: string[], // Testnet wETHContractAddresses: string[], daiContractAddresses: string[], usdcContractAddresses: string[], usdtContractAddresses: string[], tUSDContractAddresses: string[], utilsContractAddresses: string[], subgraphs: { collateralized: string, collateralFree: string, e721: string, // Testnet or Moralis unsupported chains e1155: string // Testnet or Moralis unsupported chains }, moralisDetails: { isSupported: boolean, lookupValue: string }, chainApiId: string, isSupported: boolean, isTestnet: boolean } }

How to use:

  • import sdk import { NetworkConfig, SupportedChainIds, ContractType, GetNetworkDetailsByChainId } from '@nftsafe/sdk';

  • Now you can use it

const GetNetworkDetailsByChainId = (networkId: SupportedChainIds): TypeNetworkDetails => { return NetworkConfig[networkId] } const polygonContactDetails = GetNetworkDetailsByChainId(137) Or const polygonContactDetails = NetworkConfig[137]

  1. polygonContactDetails.collateralizedContractAddresses[0]
  2. polygonContactDetails.collateralFreeContractAddresses[0] .... To get subgraph endpoint
  3. polygonContactDetails.subgraphs.collateralized
  4. polygonContactDetails.subgraphs.collateralFree ....

Supported Chains:

The "SupportedChainIds" enum is available in SDK to help you

Supported Payment Tokens:

The "PaymentToken" enum will return currently supporting Payment tokens.

Supporting NFT Standard:

The "NFTStandard" enum avaialble in sdk

Create NFTSafe contract object :

The "ContractType" enum which is already present in SDK will help you to get the specific type of contract.

  1. Collateralized Contract: final object = new NFTSafe(signer, Number(chainId), ContractType.COLLATERALIZED);
  2. Collateral Free Contract: final object = new NFTSafe(signer, Number(chainId), ContractType.COLLATERAL_FREE);

Call to contract methods:

  • Here, in arguments all individual elements should be in the form of List
  1. object.lend( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendAmounts: number[], maxRentDurations: number[], minRentDurations: number[], dailyRentPrices: number[], paymentOptions: PaymentToken[], collateralPrices: number[] );

  2. object.stopLending( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[] );

  3. object.rent( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentDurations: number[], rentAmounts: number[] );

  4. object.stopRenting( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentingIds: BigNumber[] );

  5. object.claimRentOrCollateral( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendingIds: BigNumber[], rentingIds: BigNumber[] );

  • Later SDK will use "prepareBatch" methods of SDK's utils file to convert it into formatted value

  • Let's see for lend call how SDK converts data into formatted data by using "prepareBatch" method

    lend( nftStandards: NFTStandard[], nftAddresses: string[], tokenIds: BigNumber[], lendAmounts: number[], maxRentDurations: number[], minRentDurations: number[], dailyRentPrices: number[], paymentOptions: PaymentToken[], collateralPrices: number[] ): Promise { const args = prepareBatch({ nftStandards: nftStandards.map(nft => Number(nft)), nftAddresses: nftAddresses.map(nft => String(nft).toLowerCase()), tokenIds: tokenIds.map(id => BigNumber.from(id)), lendAmounts: lendAmounts.map(amt => Number(amt)), maxRentDurations: maxRentDurations.map(x => Number(x)), minRentDurations: minRentDurations.map(x => Number(x)), dailyRentPrices: dailyRentPrices.map(x => packPrice(Number(x))), paymentOptions, collateralPrices: collateralPrices.map(x => packPrice(Number(x))), });

    return await this.contract.lend( args.nftStandards, args.nftAddresses, args.tokenIds, args.lendAmounts, args.maxRentDurations, args.minRentDurations, args.dailyRentPrices, args.paymentOptions, args.collateralPrices ); }

Note: Good to have below validation

  1. the "nftStandards" should be one of the available in "NFTStandard" type of SDK. For instance, NFTStandard.E721 and NFTStandard.E1155
  2. The "maxRentDurations" must be grater than "minRentDurations".
  3. The "paymentOptions" should be one of the available in "PaymentToken" type of SDK. To give you an idea, PaymentToken.WETH, PaymentToken.USDT etc.
  4. The "collateralPrices" value should be ZERO for the CollateralFree contract.
  • In addition, for Lend method only it will use two unique methods for below to values:
    • dailyRentPrices: dailyRentPrices.map(x => packPrice(Number(x))),
    • collateralPrices: collateralPrices.map(x => packPrice(Number(x))),

packPrice" : Used by SDK

  • Converts a number into the format that is acceptable by the NFTSafe contract.
  • TLDR; to fit a single storage slot in the NFTSafe contract, we split the whole
  • and decimal parts of a number to only have a maximum of 4 digits. That means, the
  • maximum price is 9999.9999. If more decimals are supplied, they are truncated.
  • If the price exceeds the maximum whole part, this throws.
  • @param price value to pack
  • @returns price format that is acceptable by NFTSafe contract

"unpackPrice" : Used in frontend

  • when you fetch data from the Blockchain after that you need to use "unpackPrice" method to get the actual value from a formatted value

  • price is from 1 to 4294967295. i.e. from 0x00000001 to 0xffffffff

    dailyRentPrice = unpackPrice(formated_dailyRentPrice), collateralPrice = unpackPrice(formated_collateralPrice),

Example:

User entred value: dailyRentPrices = 6 WETH , collateralPrices = 20 WETH

Used by SDK dailyRentPrices = packprice(6); // output: 0x00060000 collateralPrices = packPrice(20) // output: 0x00140000

Used in frontend dailyRentPrices =unpackPrice(0x00060000); // output: 6 collateralPrices = unpackPrice(0x00140000) // output: 20

POLYGON_MAINNET:

collateralizedContractAddresses: ["0xa0DAb138C1EC3a5D2142835E589C0a4870145107"] collateralFreeContractAddresses: ["0x4223e7608dB4619596b5c0E2fb0B0db5ee976bc0"] subgraphs: { collateralized: "https://polygon.infy.network/subgraphs/name/infy-collateralized/subgraph", collateralFree: "https://polygon.infy.network/subgraphs/name/infy-collateral-free/subgraph" }

POLYGON_TESTNET:

collateralizedContractAddresses: ["0x145BC3029bA50B9F5279e1335b5B6963cF8693Df"] collateralFreeContractAddresses: ["0x9a8EFf42Ce306655B21FC527213A69fc894b821b"] subgraphs: { collateralized: "https://mumbai.infy.network/subgraphs/name/infy-collateralized/subgraph", collateralFree: "https://mumbai.infy.network/subgraphs/name/infy-collateral-free/subgraph" }