streamnft-stellar
v0.0.2
Published
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 pa
Downloads
112
Readme
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 i test-multichain-sdk
[Usage]
const {
initPool,
initManager,
initRent,
processLoan,
processRent,
repayLoan,
expireLoan,
expireRent,
cancelManager,
cancelRent,
getAssetManager,
getBidManager,
getUserAssets,
getBidPool,
getProvider,
getSigner,
getWalletSigner,
getHederaSigner,
getHederaProvider,
getBidPoolLength,
getBidManagerLength,
} = require("test-multichain-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 bid pool length
getBidPoolLength(
"hedera",
provider
)
Get bid manger length for bid pool index
getBidManagerLength(
bidPoolIndex: number,
"hedera",
provider
)
Get provider
getProvider(
chainId: number
)
Get signer
getSigner(
chainId: number,
privateKey: string
)
Get hedera provider topic from hashconnect hashpack wallet
getHederaProvider(
topic : object
accountID : string
)
Get hedera signer
getHederaSigner(
topic : object
accountID : 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 runningnpm 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
- Polygon
// Set your Ethereum network
const chainId = 137;
const provider = getProvider(chainId);
const signer = getSigner(chainId, "PRIVATE_KEY");
- Mantle
// Set your Ethereum network
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"; // ERC721 Token address
const loanDurationInMinutes = 60;
const gracePeriodInMinutes = 10;
const interestRateLender = 5; // in percentage
initPool(
tokenAddress,
loanDurationInMinutes,
gracePeriodInMinutes,
interestRateLender,
chainId,
signer
)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Create a bid manager:
const bidPoolIndex = 0; // Index of the bid pool
const bidAmount = 100; // Amount of the bid
const totalBids = 10; // Total number of bids
initManager(bidPoolIndex, bidAmount, totalBids, chainId, signer)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Process a loan:
const bidPoolIndex = 0; // Index of the bid pool
const bidManagerIndex = 0; // Index of the bid manager
const tokenId = "TOKEN_ID";
processLoan(bidPoolIndex, bidManagerIndex, tokenId, chainId, signer)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Repay a loan:
const userAssetIndex = 0; // Index of the user asset
repayLoan(userAssetIndex, chainId, signer)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Expire a loan:
const userAssetIndex = 0; // Index of the user asset
expireLoan(userAssetIndex, chainId, signer)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Cancel a bid manager:
const bidPoolIndex = 0; // Index of the bid pool
const bidManagerIndex = 0; // Index of the bid manager
cancelManager(bidPoolIndex, bidManagerIndex, chainId, signer)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the 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; // in percentage
const whitelist = []; // Array of whitelisted addresses
initRent(
tokenAddress,
tokenId,
ratePerMinute,
validityMinutes,
isFixed,
fixedMinutes,
ownerShare,
whitelist,
chainId,
signer
)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the 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) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Expire a rent for a specific asset:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
expireRent(tokenAddress, tokenId, chainId, signer)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Cancel a rent for a specific asset:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
cancelRent(tokenAddress, tokenId, chainId, signer)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Get bid pool details:
const bidPoolIndex = 0; // Index of the bid pool
getBidPool(bidPoolIndex, chainId, provider)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Get bid manager details:
const bidPoolIndex = 0; // Index of the bid pool
const bidManagerIndex = 0; // Index of the bid manager
getBidManager(bidPoolIndex, bidManagerIndex, chainId, provider)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Get asset manager details:
const tokenAddress = "TOKEN_ADDRESS";
const tokenId = "TOKEN_ID";
getAssetManager(tokenAddress, tokenId, chainId, provider)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the error
});
Get user asset details:
const userAddress = "USER_PUBLIC_KEY";
const userAssetIndex = 0; // Index of the user asset
getUserAssets(userAddress, userAssetIndex, chainId, provider)
.then((result) => {
// Handle the result
})
.catch((error) => {
// Handle the 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.