STREAM NFT
This SDK provides an extension to integrate the STREAM NFT (https://www.streamnft.tech) smart contract to your application. STREAM NFT is an cross-chain scalability layer for NFT liquidity. This can be used to unlock features like rental, loan, buy now pay later for your utilitarian NFT.
[Instalation]
npm install streamnft-sdk
[Usage]
const {
initPool,
initManager,
initRent,
processLoan,
processRent,
repayLoan,
expireLoan,
expireRent,
cancelManager,
cancelRent,
getAssetManager,
getBidManager,
getUserAssets,
getBidPool,
getProvider,
getSigner,
getWalletSigner,
getContractAddress,
getURL
} = require("streamnft-sdk");
[Chains]
- Polygon - 137
- Telos - 41
- Mantle - 5001
[Methods]
Initializes bidding pool
initPool(
tokenAddress: address,
loanDurationInMinutes: number,
gracePeriodInMinutes: number,
interestRateLender: number,
chainId: number,
signer
)
Initializes bid manager
initManager(
bidPoolIndex: number,
bidAmount: number,
totalBids: number,
chainId: number,
signer
)
Initializes rent
initRent(
tokenAddress: address,
tokenId: number,
ratePerMinute: number,
validityMinutes: number,
isFixed: bool,
fixedMinutes: number,
ownerShare: number,
whitelist: address,
chainId: number,
signer
)
Processes loan
processLoan(
bidPoolIndex: number,
bidManagerIndex: number,
tokenAddress: address,
tokenId: number,
chainId: number,
signer
)
Processes rent
processRent(
tokenAddress: address,
tokenId: number,
durationMinutes: number,
chainId: number,
signer
)
Repays loan
repayLoan(
userAssetIndex: number,
chainId: number,
signer
)
Expire loan
expireLoan(
userAssetIndex: number,
chainId: number,
signer
)
Expire Rent
expireRent(
tokenAddress: address,
tokenId: number,
chainId: number,
signer
)
Cancel bid manager
cancelManager(
bidPoolIndex: number,
bidManagerIndex: number,
chainId: number,
signer
)
Cancel rent
cancelRent(
tokenAddress: address,
tokenId: number,
chainId: number,
signer
)
Get asset manager
getAssetManager(
tokenAddress: address,
tokenId: number,
chainId: number,
provider
)
Get bid manager
getBidManager(
bidPoolIndex: number,
bidManagerIndex: number,
chainId: number,
provider
)
Get user assets
getUserAssets(
userAddres: address,
userAssetIndex: number,
chainId: number,
provider
)
Get bid pool
getBidPool(
bidPoolIndex: number,
chainId: number,
provider
)
Get provider
getProvider(
chainId: number
)
Get signer
getSigner(
chainId: number,
privateKey: string
)
Get metamask signer
getMetaMaskSigner()
Get contract address
getContractAddress(
chainId: number
)
Get RPC URL
getURL(
chainId: number
)
[How to use - Polygon]
-
Install the necessary dependencies:
- Make sure you have Node.js installed on your machine.
- Create a new directory for your project and navigate to it using the command line.
- Run
npm init -y
to initialize a new Node.js project. - Install the
ethers
package by running npm install ethers
.
-
Create a new file in your project directory, e.g., app.js
, and copy the provided SDK code into it.
-
Import the necessary modules and instantiate the required variables in your app.js
file:
const { ethers } = require("ethers");
const {
initPool,
initManager,
initRent,
processLoan,
processRent,
repayLoan,
expireLoan,
expireRent,
cancelManager,
cancelRent,
getAssetManager,
getBidManager,
getUserAssets,
getBidPool,
getProvider,
getSigner,
getWalletSigner,
getContractAddress,
getURL
} = require("streamnft-sdk");
- Setup Provider and Signer
const chainId = 137;
const provider = getProvider(chainId);
const signer = getSigner(chainId, "PRIVATE_KEY");
const network = 5001;
const provider = getProvider(chainId);
const signer = getSigner(chainId, "PRIVATE_KEY");
- Use the SDK functions in your application as needed.
Initialize a bid pool:
const tokenAddress = "TOKEN_ADDRESS";
const loanDurationInMinutes = 60;
const gracePeriodInMinutes = 10;
const interestRateLender = 5;
initPool(
tokenAddress,
loanDurationInMinutes,
gracePeriodInMinutes,
interestRateLender,
chainId,
signer
)
.then((result) => {
})
.catch((error) => {
});
Create a bid manager:
const bidPoolIndex = 0;
const bidAmount = 100;
const totalBids = 10;
initManager(bidPoolIndex, bidAmount, totalBids, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Process a loan:
const bidPoolIndex = 0;
const bidManagerIndex = 0;
const tokenId = "TOKEN_ID";
processLoan(bidPoolIndex, bidManagerIndex, tokenId, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Repay a loan:
const userAssetIndex = 0;
repayLoan(userAssetIndex, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Expire a loan:
const userAssetIndex = 0;
expireLoan(userAssetIndex, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Cancel a bid manager:
const bidPoolIndex = 0;
const bidManagerIndex = 0;
cancelManager(bidPoolIndex, bidManagerIndex, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Initialize a rent for a specific asset:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
const ratePerMinute = 10;
const validityMinutes = 60;
const isFixed = false;
const fixedMinutes = 0;
const ownerShare = 80;
const whitelist = [];
initRent(
tokenAddress,
tokenId,
ratePerMinute,
validityMinutes,
isFixed,
fixedMinutes,
ownerShare,
whitelist,
chainId,
signer
)
.then((result) => {
})
.catch((error) => {
});
Process a rent for a specific asset:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
const durationMinutes = 120;
processRent(tokenAddress, tokenId, durationMinutes, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Expire a rent for a specific asset:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
expireRent(tokenAddress, tokenId, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Cancel a rent for a specific asset:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
cancelRent(tokenAddress, tokenId, chainId, signer)
.then((result) => {
})
.catch((error) => {
});
Get bid pool details:
const bidPoolIndex = 0;
getBidPool(bidPoolIndex, chainId, provider)
.then((result) => {
})
.catch((error) => {
});
Get bid manager details:
const bidPoolIndex = 0;
const bidManagerIndex = 0;
getBidManager(bidPoolIndex, bidManagerIndex, chainId, provider)
.then((result) => {
})
.catch((error) => {
});
Get asset manager details:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
getAssetManager(tokenAddress, tokenId, chainId, provider)
.then((result) => {
})
.catch((error) => {
});
Get user asset details:
const userAddress = "USER_PUBLIC_KEY";
const userAssetIndex = 0;
getUserAssets(userAddress, userAssetIndex, chainId, provider)
.then((result) => {
})
.catch((error) => {
});
Remember to replace the placeholders (TOKEN_ADDRESS
, TOKEN_ID
, USER_PUBLIC_KEY
, etc.) with the actual values specific to your use case.
These examples demonstrate how to use the SDK functions to interact with the smart contract. You can integrate them into your application logic and handle the results and errors accordingly.