const {LedgerClientFactory, Address} = require('@signumjs/core')
const {ContractDataView} = require('@signumjs/contracts')
const NftContractDataIndex = {
Owner: 0,
Status: 1,
CurrentPrice: 2,
PlatformAddress: 3,
PlatformFee: 4,
RoyaltiesFee: 5,
RoyaltiesOwner: 6,
HighestBidder: 19,
TotalTimesSold: 27,
TotalBidsReceived: 28,
TotalRoyaltiesFee: 29,
TotalPlatformFee: 30,
TotalLikes: 31,
}
class NftDataView {
constructor(contract) {
this.id = contract.at;
this.view = new ContractDataView(contract);
}
getId() {
return this.id;
}
getOwnerId() {
return this.view.getVariableAsDecimal(NftContractDataIndex.Owner);
}
}
function asAddress(id, prefix){
return Address.fromNumericId(id, prefix).getReedSolomonAddress()
}
async function showNftData(nftAddress) {
try {
const ledger = LedgerClientFactory.createClient({
nodeHost: "https://europe.signum.network"
});
const nftId = Address.create(nftAddress).getNumericId()
const nftContract = await ledger.contract.getContract(nftId)
const nftDataView = new NftDataView(nftContract)
console.info(`Stats of NFT '${asAddress(nftId)}'`)
console.info('----------------------------------------')
console.info('Creator:', nftContract.creatorRS)
console.info('Current Owner:', asAddress(nftDataView.getOwnerId(),prefix))
console.info('Current Price:', nftDataView.getCurrentPrice().getSigna(), 'SIGNA')
console.info('Current Status:', nftDataView.getStatus())
console.info('Number of Sales:', nftDataView.getTotalTimesSold())
console.info('Likes:', nftDataView.getTotalLikes())
} catch (e) {
handleError(e);
}
}
(async () => {
await showNftData("S-PWUR-HWPD-3GRX-8N86V");
})();