@apillon/sdk
Version:
▶◀ Apillon SDK for NodeJS ▶◀
188 lines • 7.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NftCollection = void 0;
const nfts_1 = require("./../../types/nfts");
const apillon_api_1 = require("../../lib/apillon-api");
const apillon_logger_1 = require("../../lib/apillon-logger");
const common_1 = require("../../lib/common");
const nfts_2 = require("../../types/nfts");
const apillon_1 = require("../../lib/apillon");
class NftCollection extends apillon_1.ApillonModel {
/**
* Constructor which should only be called via Nft class.
* @param uuid Unique identifier of the NFT collection.
* @param data Data to populate the collection with.
*/
constructor(uuid, data) {
super(uuid);
/**
* Collection symbol.
*/
this.symbol = null;
/**
* Collection name
*/
this.name = null;
/**
* collection description.
*/
this.description = null;
/**
* Collection type. Defines the smart contract used.
*/
this.collectionType = null;
/**
* Max amount of NFTs that can get minted in this collection. 0 represents unlimited.
*/
this.maxSupply = null;
/**
* Base uri from which uri for each token is calculated from:
* Base uri + token id + base extension.
*/
this.baseUri = null;
/**
* Base extension from which uri for each token is calculated from:
* Base uri + token id + base extension.
*/
this.baseExtension = null;
/**
* If nft is transferable.
*/
this.isSoulbound = null;
/**
* If true, NFT token IDs are always sequential.
* If false, custom token IDs can be provided when minting.
*/
this.isAutoIncrement = null;
/**
* If collection owner can burn / destroy a NFT.
*/
this.isRevokable = null;
/**
* If this collection has drop (anyone can buy a nft directly from the smart contract) functionality enabled.
*/
this.drop = null;
/**
* Price per NFT if drop is active.
*/
this.dropPrice = null;
/**
* UNIX timestamp of when general buying of NFTs start.
*/
this.dropStart = null;
/**
* Amount of reserved NFTs that can't be bought by general public but can get minted by the collection owner.
*/
this.dropReserve = null;
/**
* Percentage amount of royalties fees.
*/
this.royaltiesFees = null;
/**
* Address to which royalties are paid.
*/
this.royaltiesAddress = null;
/**
* Status of the collection. From not deployed etc.
*/
this.collectionStatus = null;
/**
* Smart contract address (available after succesfull deploy).
*/
this.contractAddress = null;
/**
* Transaction hash of contract deploy.
*/
this.transactionHash = null;
/**
* Wallet address of deployer.
*/
this.deployerAddress = null;
/**
* Chain on which the smart contract was deployed.
*/
this.chain = null;
this.API_PREFIX = `/nfts/collections/${this.uuid}`;
this.populate(data);
}
/**
* @param {IMintNftData} params - NFT mint parameters
* @returns {INftActionResponse} - success status and transaction hash of the mint
*/
async mint(params) {
var _a;
if ((_a = params.idsToMint) === null || _a === void 0 ? void 0 : _a.length) {
params.quantity = params.idsToMint.length;
}
const data = await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/mint`, params);
apillon_logger_1.ApillonLogger.log(`${params.quantity} NFTs minted successfully to ${params.receivingAddress}`);
return data;
}
/**
* Mints new nfts directly to an existing nft.
* @warn This method is only available for nestable collections.
* @param parentCollectionUuid UUID of the collection we want to nest mint to.
* @param parentNftId ID of the nft in the collection we want to nest mint to.
* @param quantity Amount of nfts we want to mint.
* @returns Call status.
*/
async nestMint(parentCollectionUuid, parentNftId, quantity) {
if (this.collectionType != null &&
this.collectionType != nfts_2.CollectionType.NESTABLE) {
throw new Error('Collection is not nestable.');
}
const data = await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/nest-mint`, { parentCollectionUuid, parentNftId, quantity });
apillon_logger_1.ApillonLogger.log(`NFT nest minted successfully on NFT ${parentNftId}`);
return data;
}
/**
* Burns a nft.
* @warn Can only burn NFTs if the collection is revokable.
* @param tokenId Token ID of the NFT we want to burn.
* @returns Success status and transaction hash.
*/
async burn(tokenId) {
if (this.isRevokable != null && !this.isRevokable) {
throw new Error('Collection is not revokable.');
}
const data = await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/burn`, { tokenId });
apillon_logger_1.ApillonLogger.log(`NFT ${tokenId} burned successfully`);
return data;
}
/**
* Transfers ownership of this collection.
* @warn Once ownership is transferred you cannot call mint methods anymore since you are the
* owner and you need to the smart contracts call directly on chain.
* @param address Address to which the ownership will be transferred.
* @returns Collection data.
*/
async transferOwnership(address) {
const data = await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/transfer`, { address });
this.populate(data);
apillon_logger_1.ApillonLogger.log(`NFT collection transferred successfully to ${address}`);
return this;
}
/**
* Gets list of transactions that occurred on this collection through Apillon.
* @param params Filters.
* @returns {ITransaction[]} List of transactions.
*/
async listTransactions(params) {
const url = (0, common_1.constructUrlWithQueryParams)(`${this.API_PREFIX}/transactions`, params);
return await apillon_api_1.ApillonApi.get(url);
}
serializeFilter(key, value) {
const serialized = super.serializeFilter(key, value);
const enums = {
collectionType: nfts_2.CollectionType[serialized],
collectionStatus: nfts_2.CollectionStatus[serialized],
transactionType: nfts_2.TransactionType[serialized],
transactionStatus: nfts_1.TransactionStatus[serialized],
chain: nfts_2.EvmChain[serialized] || nfts_1.SubstrateChain[serialized],
chainId: nfts_2.EvmChain[serialized] || nfts_1.SubstrateChain[serialized],
};
return Object.keys(enums).includes(key) ? enums[key] : serialized;
}
}
exports.NftCollection = NftCollection;
//# sourceMappingURL=nft-collection.js.map