Help NFT owners to rent their digital asset to earn some passive income.
We have only two actors, the NFT owner, and the renter. The owner should set the renter and transfer the token ownership. The renter should pay the rent at a specific interval, and he can pay in advance. The Nft owner could claim rent any time after the deadline. If the renter pay, he will receive his tokens; otherwise, he will return the NFT.
-
NFT owner submit
rentNFT
transaction with the following data:- NFT id
- Renter address
- Rent amount
- payments dates in timestamp ex:[1647691061,1647691261,1647699061]
What will happen then?
- Check if the caller is the owner of the NFT.
- Store renting info:
rentedNfts[nftId] = { owner, renter, rentAmount, paymentDates, };
- Transfer ownership (Override approve methods so only the smart contract can transfer ownership or set other approval).
- Set payments period
for(let i = 0; i < paymentDates.length;paymentDates.length){ rentersPayment[paymentDates[i]] = { nftId, renter, rentAmount, hasPayed: false, }; }
- Renter submit
payRent
transaction with the following data:- Payment date
- NFT Id
- Rent Amount
What will happen then?
- isRenter:
renter === rentedNfts[nftId].renter
- Pay
rentAmount
to the smart contract. - Set renter payment status:
rentersPayment[paymentDate].map((rent) =>{ if(rent.tokenID === tokenID && rent.renter === renter){ return rent.hasPayed = true; } })
- NFT owner submit
claimRent
withnftId
What will happen then?- isOwner:
caller === rentedNfts[nftId].owner
- Get payments date
rentedNfts[nftId].paymentDates
- Claim or transfer ownership:
- isOwner:
const todayInMillisecond = Date.now().getTime()*1000;
for(let i = 0; i < rentedNfts[nftId].paymentDates.length;i++){
if(todayInMillisecond > rentedNfts[nftId].paymentDates[i]){
if(rentersPayments[rentedNfts[nftId].paymentDates[i]].hasPayed)
pay(rentersPayments[rentedNfts[nftId].paymentDates[i]].rentAmount)
}else{
transferOwnership(rentedNfts[nftId].owner)
}
}
Choose connection type to assume you will use Algo Devnet.
export REACH_CONNECTOR_MODE=ALGO-devnet
Compile
./reach compile
Run
./reach run