STREAM NFT
This SDK provides an extension to integrate the STREAM NFT (https://www.streammoney.finance/) smart contract to your application. STREAM NFT is an on-chain "solana" smart contract that enables the real-time borrowing/renting of NFTs.
import {
queryTokenState,
config,
sendTransaction,
withdrawTx,
rentTx,
initNFTEscrowTx,
findAssociatedTokenAddress,
cancelEscrowTx,
getWalletTokens,
QueryWalletTokensStatus,
getAllListedTokens,
} from "stream-nft-sdk";
STREAM NFT flow consists of 5 major flows: Initialize, Rent, Withdraw, Cancel, Query
Initializes NFT on STREAM NFT protocol, making it available for users to browse and rent.
initNFTEscrowTx({
owner: Wallet,
token,
rate: BigNumber
minBorrowTime: BigNumber
maxBorrowTime: BigNumber
connection,
newAccount: PublicKey
ownerTokenAccount: await findAssociatedTokenAddress(
wallet.publicKey,
token
),
programId: config.DEVNET_PROGRAM_ID,
});
Users can borrow the NFT utility adhering to the contract constraints of rate, min_duration, and max_duration. This is will change the contract state, changing conditional ownership to the borrower.
rentTx({
borrower: Wallet,
token,
programId: config.DEVNET_PROGRAM_ID,
amount: BigNumber
time: BigNumber
connection,
});
As per the duration set by the user, the NFT utility would expire. NFT could be withdrawn by anyone upon expiration, and get incentivised. This flow returns NFT back to the available state for renting.
withdrawTx({
token,
programId: config.DEVNET_PROGRAM_ID,
connection,
});
NFT owners can cancel the smart contract, thus claiming back the ownership of NFT. This closes the temporary PDA and settles all PDA balances to the owner.
cancelEscrowTx({
owner: Wallet,
token,
programId: config.DEVNET_PROGRAM_ID,
connection,
ownerTokenAddress: await findAssociatedTokenAddress(
wallet.publicKey,
token
),
});
Any service/user can invoke the query function to get the current on-chain PDA state for a provided NFT.
queryTokenState({
programId: config.DEVNET_PROGRAM_ID,
tokenAddress: PublicKey
connection,
});
};
service/user can get all their listed and borrowed tokens present on stream-nft platform using the following methods
- get all listed tokens for a wallet
await getWalletTokens({
connection,
programId: config.DEVNET_PROGRAM_ID,
owner: wallet,
type: QueryWalletTokensStatus.LISTED,
})
- get all borrowed tokens for a wallet
await getWalletTokens({
connection,
programId: config.DEVNET_PROGRAM_ID,
owner: wallet,
type: QueryWalletTokensStatus.BORROWED,
})
get all tokens listed on the stream-nft platform
await getAllListedTokens({
connection,
programId: config.DEVNET_PROGRAM_ID,
})
Please check out the detailed integration at https://github.com/rahul0tripathi/sol_rent_demo and examples are available at https://github.com/rahul0tripathi/nft_rent_sdk/tree/master/examples
Stream NFT is soon expanding to other chains as well.. stay tuned :)