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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rentero/sdk-js

v0.1.3

Published

JS SDK For Integrating Rentero Protocol

Downloads

3

Readme

Rentero-SDK-JS

JS SDK For Integrating Rentero Protocol, allowing application developers easily query renter's NFTs info and use Rentero Protocol.

Installation

yarn add @rentero/sdk-js

Usage

SDK currently supports chains includes: 'mainnet' | 'rinkeby' | 'bsc' | 'bsctestnet'

import { RenteroNFT, Rentero } from '@rentero/sdk-js'

const contractAddress = '0x317caEc5AFd5d43B205683318eC35ed8B063d131'

const renterAddress = '0x431b4ca18e269fc7e1f5af49b9f4e2af683f6207'
const lenderAddress = '0x576687d59d191A9B20110FB3e126Dbf27D8E42e0'

const renteroNFT = new RenteroNFT('bsctestnet', [contractAddress])

const result1 = await renteroNFT.getRentNFTsByAddress(renterAddress)

const result2 = await renteroNFT.getRentInfoById(
  '0x317caEc5AFd5d43B205683318eC35ed8B063d131',
  572
)

const result3 = await renteroNFT.getLendNFTsByAddress(lenderAddress)

const result4 = await renteroNFT.getAllNFTsInMarket()

APIs

Rentero SDK mainly divide into two part: RenteroNFT and Rentero.

  • RenteroNFT class contains query rental NFT info from thegraph data, such as expires time, renting NFTs, lending NFTs, etc.

  • Rentero class contains Rentero Protocol core functions, such as lending、rending、redemption.


1. RenteroNFT

Pass in the blockchain network and NFT contracts, instantiate the object

new RenteroNFT(network: SUPPORT_NETWORK, targetContracts: string[])

1.1 getRentNFTsByAddress

Query all lease NFTs under the renter address

const getRentNFTsByAddress: ( renterAddress: string) => Promise<any>

1.2 getRentInfoById

Query the rent NFT info of the specified NFT

const getRentInfoById: (contractAddress: string, nftId: number) => Promise<any>

Example result:

{
  "lease": {
    "renter": "0x0000000000000000000000000000000000000000",
    "lender": "0x576687d59d191a9b20110fb3e126dbf27d8e42e0",
    "expires": "0"
  }
}

TIP: If the expires time is greater than the current time, it is in the rental state, otherwise it is in the market listing state.

1.3 getLendNFTsByAddress

Query lend NFTs list by lender address

const getLendNFTsByAddress: (lendAddress: string) => Promise<any>

1.4 getAllNFTsInMarket

Query all NFTs in Rentero Market by the passed NFT Collections


2 Rentero

Rentero class contains Rentero protocol core functions, user could lend、rent、redeem、return, etc by Rentero instance.

new Rentero(signer, config)

Params

  • signer: ethers.Signer
    • sign messages and transactions and send signed transactions to network to execute state changing operations. more details
  • renteroConfig: {targetChain: SUPPORT_NETWORK, renteroType: RENTERO_MODE, marketAddress?: string}
    • targetChain: current support chain 'mainnet' | 'rinkeby' | 'bsc' | 'bsctestnet'
    • renteroType: current only support installment
    • marketAddress (optional): specify market contract address to override the above configuration
// example used in dapp
const { data: signer } = useSigner()

const rentero = useMemo(() => {
  if (!signer) return

  return new Rentero(signer, {
    targetChain: 'bsctestnet',
    renteroType: 'installment',
  })
}, [signer])

full usage example see demo

2.1 lendNFT

lend user NFT to market

Rentero.lendNFT(nftAddress: string, tokenId: number, erc20Address: string, whitelist: string, deposit: BigNumber, dailyPrice: BigNumber, paymentCycle: number, minRentalDays: number, maxRentalDays: number) => Promise<any>

Params

  • nftAddress: string
    • lend NFT Collection address
  • tokenId: number
    • NFT token id
  • erc20Address: string
    • payment token contract address
  • whitelist: string
    • whitelist address, only whitelist user could rent this NFT, only support one whitelist address, if don't need whitelist, please pass zero address: 0x0000000000000000000000000000000000000000
  • deposit: ethers.BigNumber
    • the deposit amount of lend NFT
  • dailyPrice: ethers.BigNumber
    • the daily price of renting NFT
  • paymentCycle: number
    • payment cycle for renting NFT
  • minRentalDays: number
    • min rental days of current NFT (Min suuport value: 1)
  • maxRentalDays: number
    • max rental days of current NFT (Max support value: 65535)
const result = await rentero?.lendNFT(
  SHIP_ADDRESS,
  573,
  '0x304af20ef7a8497aeed4a4a6ba4601988d5b11f6',
  '0x0000000000000000000000000000000000000000',
  ethers.utils.parseUnits('1.2', 18),
  ethers.utils.parseUnits('1.2', 18),
  3,
  1,
  365
)
console.log(result)

2.2 reLendNFT

update lend NFT order info in market. (Can only be called when listing not rented)

Rentero.reLendNFT(nftAddress: string, tokenId: number, erc20Address: string, whitelist: string, deposit: BigNumber, dailyPrice: BigNumber, paymentCycle: number, minRentalDays: number, maxRentalDays: number) => Promise<any>

Params

Same to lendNFT params

const result = await rentero?.reLendNFT(
  SHIP_ADDRESS,
  573,
  '0x304af20ef7a8497aeed4a4a6ba4601988d5b11f6',
  '0x0000000000000000000000000000000000000000',
  ethers.utils.parseUnits('2.4', 18),
  ethers.utils.parseUnits('2.4', 18),
  5,
  1,
  365
)
console.log(result)

2.3 rentNFT

rent NFT in market

Rentero.rentNFT(contractAddress: string, tokenId: number, rentDays: number) => Promise<any>

Params

  • contractAddress: string
    • NFT contract address
  • tokenId: string
    • NFT token ID
  • rentDays: number
    • rent days (Min:1 ~ Max:65535)
const SHIP_ADDRESS = '0x317caEc5AFd5d43B205683318eC35ed8B063d131'
const TOKEN_ID = 574
const result = await rentero?.rentNFT(SHIP_ADDRESS, TOKEN_ID, 10)
console.log(result)

2.4 earlyReturn

renter early return rented NFT

Rentero.earlyReturn(contractAddress: string, tokenId: number) => Promise<any>

Params

  • contractAddress: string
    • NFT contract address
  • tokenId: string
    • NFT token ID
const SHIP_ADDRESS = '0x317caEc5AFd5d43B205683318eC35ed8B063d131'
const TOKEN_ID = 575
const result = await rentero?.earlyReturn(SHIP_ADDRESS, TOKEN_ID)
console.log(result)

2.5 redeemNFT

lender early redeem NFT

Rentero.redeemNFT(contractAddress: string, tokenId: number) => Promise<any>

Params

  • contractAddress: string
    • NFT contract address
  • tokenId: string
    • NFT token ID
const SHIP_ADDRESS = '0x317caEc5AFd5d43B205683318eC35ed8B063d131'
const TOKEN_ID = 573
const result = await rentero?.redeemNFT(SHIP_ADDRESS, TOKEN_ID)
console.log(result)