Comment on page
Integration - Escrow Rental Mode
When an asset owner lists or de-lists or there is a rental transaction completed (i.e. event) on the NFT Rental Marketplace, smart contract triggers an event emitter for the associated event. Game platform servers need to listen and handle the event emitter appropriately.
Please see file
abi.json
BSC Testnet:
0xe9D5B350b77D80f6CBe4D2638FA067FEDdB15Ec6
event NFTListRental(
address indexed nftAddress,
uint256 indexed tokenId,
address indexed ownerAddress,
uint256 minTime,
uint256 maxTime,
uint256 pricePerHour,
uint256 createdAt
)
When the asset owner lists the NFT on the marketplace for rental, the event emitter returns these parameters:
tokenId
: id of nftownerAddress
: the wallet address of the asset ownerminTime
: minimum rental time (in seconds)maxTime
: maximum rental time (in seconds)pricePerHour
: rental fee over 1 hour
Sample code to listen for this event emitter:
// In Node.js
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8546');
const lendingNFTContract = new web3.eth.Contract(LENDING_NFT_CONTRACT_ABI, LENDING_NFT_CONTRACT_ADDRESS);
// contract abi and address see above
async function getContractEvent() {
const pastLentEvents = await lendingNFTContract.getPastEvents('Lent', {
filter: {
nftAddress: // your game nft
},
fromBlock: blockNumber,
toBlock: lastBlockNumber
});
for (let i = 0; i < pastLentEvents.length; i++) {
const event = pastLentEvents[i];
const { tokenId, lenderAddress, minTime, maxTime, pricePerHour } = event.returnValues;
// your logic code
}
}
DelistRental:
event DelistRental(
address indexed nftAddress,
uint256 indexed tokenId,
uint256 createdAt
)
When the asset owner de-lists the NFT from the marketplace for rental, the event emitter returns these parameters:
tokenId
: id of nft
Sample code to listen for this event emitter:
// In Node.js
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8546');
const lendingNFTContract = new web3.eth.Contract(LENDING_NFT_CONTRACT_ABI, LENDING_NFT_CONTRACT_ADDRESS);
// contract abi and address see above
async function getContractEvent() {
const pastStoppedEvents = await lendingNFTContract.getPastEvents('DelistRetal', {
filter: {
nftAddress: // your game nft
},
fromBlock: blockNumber,
toBlock: lastBlockNumber
});
for (let i = 0; i < pastRentedEvents.length; i++) {
const event = pastRentedEvents[i];
const { tokenId } = event.returnValues;
// your logic code
}
}
event RentalCompleted(
address indexed nftAddress,
uint256 indexed tokenId,
address indexed renterAddress,
uint256 rentDuration,
uint256 rentedAt,
uint256 price,
uint256 createdAt
)
When a marketplace user (renter) rents the NFT from the marketplace, the event emitter returns these parameters:
tokenId
: id of nftrenterAddress
: renter's wallet addressrentDuration
: rental time (in seconds)rentedAt
: transaction time (timestamp)
Sample code to listen for this event emitter:
// In Node.js
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8546');
const lendingNFTContract = new web3.eth.Contract(LENDING_NFT_CONTRACT_ABI, LENDING_NFT_CONTRACT_ADDRESS);
// contract abi and address see above
async function getContractEvent() {
const pastRentedEvents = await lendingNFTContract.getPastEvents('RentalCompleted', {
filter: {
nftAddress: // your game nft
},
fromBlock: blockNumber,
toBlock: lastBlockNumber
});
for (let i = 0; i < pastRentedEvents.length; i++) {
const event = pastRentedEvents[i];
const { tokenId, renterAddress, rentDuration, rentedAt } = event.returnValues;
// your logic code
}
}
event RentalReturn(
address indexed nftAddress,
uint256 indexed tokenId,
address indexed ownerAddress,
address renterAddress,
uint256 createdAt
)
When the renter returns the NFT to the marketplace, the event emitter returns these parameters:
tokenId
: id of nft
Sample code for get this event:
// In Node.js
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8546');
const lendingNFTContract = new web3.eth.Contract(LENDING_NFT_CONTRACT_ABI, LENDING_NFT_CONTRACT_ADDRESS);
// contract abi and address see above
async function getContractEvent() {
const pastReturnEvents = await lendingNFTContract.getPastEvents('RentalReturn', {
filter: {
nftAddress: // your game nft
},
fromBlock: blockNumber,
toBlock: lastBlockNumber
});
for (let i = 0; i < pastRentedEvents.length; i++) {
const event = pastRentedEvents[i];
const { tokenId } = event.returnValues;
// your logic code
}
}