apenft-js-tron
v2.1.2
Published
Javascript SDK for the APENFT
Downloads
7
Readme
APENFT SDK
What is apenft-js-tron?
"apenft-js-tron" is a SDK for APENFT marketplace base on TRON blockchain and TronLink wallet.
Table of Contents
- APENFT SDK
Installation
npm install apenft-js-tron
SDK relies on TronLink wallet for on-chain operations. You also need to install tronweb to run SDK on node.js. We recommend switching to Node.js version 16 and above.
npm install tronweb
TronWeb is a library that allows you to interact with TronNetwork.
Testnet
Shasta is the official Tron testnet. To use it use the following endpoint:
https://api.shasta.trongrid.io
Get some Shasta TRX at https://www.trongrid.io/shasta and play with it. Anything you do should be explorable on https://shasta.tronscan.org
Set Up
Initialize SDK
import sdk from "apenft-js-tron";
const { APENFTOrders, APENFTQuery, Network, AssetFactory } = sdk;
/* Initialize tronWeb */
/* For browser */
const { tronWeb } = window;
/* For node */
const tronWeb = new TronWeb({
fullHost: "https://api.shasta.trongrid.io",
privateKey: "xxxxx-xxxx-xxxxx-xxxxx-xxxxx",
});
/* Initialize SDK */
const networkName = Network.Shasta;
const sdk_orders = new APENFTOrders(tronWeb, { networkName });
const sdk_query = new APENFTQuery(tronWeb, { networkName });
Asset
/* Get asset factory from sdk_orders */
const sdk_fab = sdk_orders.assetFactory
/* or
new AssetFactory
*/
const sdk_fab = new AssetFactory(tronWeb, { networkName })
sdk_fab.createAsset721(...); // create smart contract
sdk_fab.mint721(...); // mint NFT
Create a Smart Contract
sdk_fab.createAsset721(name,symbol,baseUrl,options)
Instructions:
/**
* @param {string} name
* @param {string} symbol
* @param {string} baseUrl
* @param {object} [options] - optional,ref https://developers.tron.network/reference/tronweb-createsmartcontract
* @returns {Promise<{txHash,txSend}>}
*/
async createAsset721(name: string, symbol: string, baseUrl: string, options?: any)
Example:
const sdk_fab = ...
const createRes = await sdk_fab.createAsset721(
'MyNFTSymbol',
'MyNFTName',
'' // metadata json
)
const output = await createRes.txSend.catch((err) => console.log(err))
const nftContract = output.contract_address
Mint an NFT
sdk_fab.mint721(nftContract, toAddress,url)
Instructions:
/**
*
* @param {string} assetAddr
* @param {string} to
* @param {string} [url]
* @returns Promise
*/
async mint721(assetAddr, to, url)
Example:
const nftContract = ...
const to = ...
const url = 'https://gateway.btfs.io/btfs/QmVs42A8YqLffAC75kjQEMxRbzZDdQFKhRiM4agnwNX7u6/BTFS-GenesisNFT-Level-P'
const defer = await sdk_fab.mint721(nftContract, to, url)
defer.txSend
.on('confirmation', (r) => console.log('confirmation', r))
.on('error', (r) => console.log('error', r))
await defer.txSend
Query Assets
Query Assets Under an Account
APENFTQuery.getAssetsList(account,pagination)
Instructions:
/**
*
* @param {string} account
* * @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getAssetsList(account,pagination);
Example:
const assetsList = await sdk_query.getAssetsList(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("assetsList", assetsList);
Query Collections Under an Account
APENFTQuery.getCollections(account,pagination)
Instructions:
/**
*
* @param {string} account
* @returns Promise
*/
async APENFTQuery.getCollections(account,pagination);
Example:
const collectionsList = await sdk_query.getCollections(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("collectionsList", collectionsList);
Query NFT details
APENFTQuery.getAssetDetail(collection,id)
Instructions:
/**
*
* @param {string} collection
* @param {string} id
* @returns Promise
*/
async APENFTQuery.getAssetDetail(collection,id);
Example:
const assetDetail = await sdk_query.getAssetDetail(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ",
"1327"
);
console.log("assetDetail", assetDetail);
Query Currencies
APENFTQuery.getCurrencies()
Instructions:
async APENFTQuery.getCurrencies();
Example:
const currencies = await sdk_query.getCurrencies();
console.log("currencies", currencies);
Query All Assets
APENFTQuery.queryAllAssets({sort, pagination, filters});
Instructions:
async getAllAssets(params: {sort: AssetSortBy, pagination?: Pagination, filters?: AssetQueryFilters}): Promise<any>;
enum AssetSortBy {
HighestLastSale = 'HighestLastSale',
RecentlyListed = 'RecentlyListed',
PriceLowToHigh = 'PriceLowToHigh',
PriceHighToLow = 'PriceHighToLow',
RecentlyTransfer = 'RecentlyTransfer',
RecentlyCreated = 'RecentlyCreated',
RecentlySold = 'RecentlySold',
EndingSoon = 'EndingSoon',
}
interface Pagination {
first: number
cursor?: string
}
interface AssetQueryFilters {
search?: string
price?: PriceRangeFilter
statuses?: AssetStatus[]
collections?: string[]
user_account?: string
owners?: string[]
creators?: string[]
categories?: string[]
currencies?: string[]
is_recommend?: boolean
collection_types?: AssetListCollectionTypes[]
}
interface PriceRangeFilter {
min?: number | string
max?: number | string
currency: 'TRX' | 'USD'
}
enum AssetListCollectionTypes {
NORMAL = 'NORMAL',
MYSTERY_BOX = 'MYSTERY_BOX',
}
enum AssetStatus {
BUY_NOW = 'BUY_NOW',
ON_AUCTION = 'ON_AUCTION',
VERIFIED = 'VERIFIED',
HAS_OFFERS = 'HAS_OFFERS',
}
Example:
const currencies = await sdk_query.getCurrencies();
const trxAndUsdtAddresses = currencies
.filter((currency) => currency.symbol === "TRX" || currency.symbol === "USDT")
.map((currency) => currency.address);
const assets = await sdk_query.getAllAssets({
sort: AssetSortBy.PriceLowToHigh,
pagination: { first: 30 },
filters: {
statuses: [AssetStatus.BUY_NOW],
price: { min: 1, max: 100000, currency: "TRX" },
collections: ["TXb5avabU6Z2Dhhp4wV2WbX3JCX844PDAB"],
categories: [Category.ART, Category.COLLECTIBLES],
currencies: trxAndUsdtAddresses,
collection_types: [AssetListCollectionTypes.NORMAL],
},
});
console.log("assets", assets);
Query Ranking NFTs
APENFTQuery.getRankingNFTs({sort, sort_asc, categories, is_rank_disabled, has_listing_asset, pagination});
Instructions:
async APENFTQuery.getRankingNFTs(params: RankingDetailParams): Promise;
interface RankingDetailParams extends Partial<RankingDetailFilters> {
sort: CollectionSortBy
sort_asc: boolean
pagination: Pagination
}
interface RankingDetailFilters {
categories: Category[]
is_rank_disabled: boolean
has_listing_asset: boolean
}
enum CollectionSortBy {
Volume7d = "Volume7d",
Volume24h = "Volume24h",
Volume30d = "Volume30d",
VolumeTotal = "VolumeTotal",
}
enum Category {
ART = "art",
COLLECTIBLES = "collectibles",
VIRTUAL_WORLD = "virtual-world",
MUSIC = "music",
UTILITY = "utility",
SPORTS = "sports",
TRADING_CARDS = "trading-cards",
DOMAIN_NAMES = "domain-names",
}
interface Pagination {
first: number
cursor?: string
}
Example:
const rankingNFTs = await sdk_query.getRankingNFTs({
sort: CollectionSortBy.Volume7d,
sort_asc: false,
pagination: { first: 20 },
categories: [],
is_rank_disabled: false,
has_listing_asset: true,
});
console.log("rankingNFTs", rankingNFTs);
Order
Create an Order
Initialization:
import { APENFTOrders, APENFTQuery, initApprove } from "apenft-js-tron";
let sdk_orders = new APENFTOrders(window.tronWeb, { networkName });
const sdk_query = new APENFTQuery(window.tronWeb, { networkName });
- Permission Approval NFTs can be traded with the following methods: Fixed Price, Highest Bid, Buy Order, and Auction Order. The wallet address needs to call the approve function when being used for NFT trading for the first time. Every collection needs to be approved only once.
Instructions:
/**
*
* @param {object} APENFTOrders
* @param {string} orderType
* @param {object} orderParams
* @returns Promise
*/
async initApprove({ APENFTOrders, orderType, orderParams})
Example:
let orderType = "FixPriceOrder";
const params = {
collection: "TNy9UXCHeAa2jrRiG6CjUppiwKJ9vodfS9",
id: "67",
price: 20,
currency: "TRX",
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
buyerAddress: "",
}
let orderParams = await sdk_query.getFixPriceOrderParams(params);
try {
await initApprove({
APENFTOrders: sdk_orders,
orderType: orderType,
orderParams: orderParams,
});
let result = await sdk_orders.createSellOrder(orderParams);
console.log(result);
if (result && result.orderHash) {
console.log("FixPriceOrder Listing Successful!");
} else {
console.log("Failed");
}
} catch (e) {
console.log(e);
}
Fixed Price
Obtain input parameters:
APENFTQuery.getFixPriceOrderParams(params)
Instructions:
/**
*
* @param {object} params -
* {
* collection: string // collection address
* id: string // token id
* price: number
* currency: string
* expirationTime: number // timestamp, milliseconds
* buyerAddress?: string // buyer address, optional
* }
* @returns Promise
*/
async APENFTQuery.getFixPriceOrderParams(params);
Example:
const params = {
collection: "TNy9UXCHeAa2jrRiG6CjUppiwKJ9vodfS9",
id: "67",
price: 20,
currency: "TRX",
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
buyerAddress: "",
};
let orderParams = await sdk_query.getFixPriceOrderParams(params);
APENFTOrders.createSellOrder(orderParams);
Instructions:
/**
*
* @param {object} orderParams
* @returns Promise
*/
async APENFTOrders.createSellOrder(orderParams);
Example:
const orderType = "FixPriceOrder";
const params = {
collection: "TNy9UXCHeAa2jrRiG6CjUppiwKJ9vodfS9",
id: "67",
price: 20,
currency: "TRX",
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
buyerAddress: "",
};
let orderParams = await sdk_query.getFixPriceOrderParams(params);
await initApprove({
APENFTOrders: sdk_orders,
orderType: orderType,
orderParams: orderParams,
});
await sdk_orders.createSellOrder(orderParams);
Highest Bid
Obtain input parameters:
APENFTQuery.getEnglishAuctionOrderParams(params)
Instructions:
/**
*
* @param {object} params -
* {
* collection: string
* id: string
* bidPrice: number
* reservePrice: number
* currency: string
* expirationTime: number // timestamp, milliseconds
* }
* @returns Promise
*/
async APENFTQuery.getEnglishAuctionOrderParams(params);
Example:
const params = {
collection: "TQXKjXfTiy9j2qfRXNroZdrrAawu65b72Z",
id: "5",
bidPrice: 20,
reservePrice: 100,
currency: "USDT",
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
};
let orderParams = await sdk_query.getEnglishAuctionOrderParams(params);
APENFTOrders.createAuctionOrder(orderParams);
Instructions:
/**
*
* @param {object} orderParams
* @returns Promise
*/
async APENFTOrders.createAuctionOrder(orderParams);
Example:
const params = {
collection: "TQXKjXfTiy9j2qfRXNroZdrrAawu65b72Z",
id: "5",
bidPrice: 20,
reservePrice: 100,
currency: "USDT",
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
};
let orderParams = await sdk_query.getEnglishAuctionOrderParams(params);
await sdk_orders.createAuctionOrder(orderParams);
Buy Order
Obtain input parameters:
APENFTQuery.getMakeOfferOrderOrderParams(params)
Instructions:
/**
*
* @param {object} params -
* {
* collection: string
* id: string
* price: number
* currency: string
* expirationTime: number // timestamp, milliseconds
* }
* @returns Promise
*/
async APENFTQuery.getMakeOfferOrderOrderParams(params);
Example:
const params = {
collection: "TQFhpAACCPomuW4daSiGTh4SMCvUKtZyNs",
id: "105",
price: 110,
currency: "WTRX",
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
};
let orderParams = await sdk_query.getMakeOfferOrderOrderParams(params);
APENFTOrders.createBuyOrder(orderParams)
Instructions:
/**
*
* @param {object} orderParams
* @returns Promise
*/
async APENFTOrders.createBuyOrder(orderParams);
Example:
const params = {
collection: "TQFhpAACCPomuW4daSiGTh4SMCvUKtZyNs",
id: "105",
price: 110,
currency: "WTRX",
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
};
let orderParams = await sdk_query.getMakeOfferOrderOrderParams(params);
await sdk_orders.createBuyOrder(orderParams);
Auction Order
Obtain input parameters:
APENFTQuery.getEnglishAuctionBiddingOrderParams(params)
Instructions:
/**
*
* @param {object} params -
* {
* collection: string
* id: string
* price: number
* currency: string
* }
* @returns Promise
*/
async APENFTQuery.getEnglishAuctionBiddingOrderParams(params);
Example:
const params = {
collection: "TGvAiyw7uT27xVpqHaQ1NM6ZDquEEHQgso",
id: "9927",
price: 125,
currency: "WTRX",
};
let orderParams = await sdk_query.getEnglishAuctionBiddingOrderParams(params);
APENFTOrders.createBiddingOrder(orderParams);
Instructions:
/**
*
* @param {object} orderParams
* @returns Promise
*/
async APENFTOrders.createBiddingOrder(orderParams);
Example:
const params = {
collection: "TGvAiyw7uT27xVpqHaQ1NM6ZDquEEHQgso",
id: "9927",
price: 125,
currency: "WTRX",
};
let orderParams = await sdk_query.getEnglishAuctionBiddingOrderParams(params);
await sdk_orders.createBiddingOrder(orderParams);
Lower Price
Obtain input parameters:
APENFTQuery.getLowerPriceOrderParams(params)
Instructions:
/**
*
* @param {object} params -
* {
* collection: string
* id: string
* price: number
* }
* @returns Promise
*/
async APENFTQuery.getLowerPriceOrderParams(params);
Example:
const params = {
collection: "TL39x7unoU1ivqxac43umyUaFoGzEE2Ens",
id: "2",
price: 80,
};
let orderParams = await sdk_query.getLowerPriceOrderParams(params);
APENFTOrders.createLowerPriceOrder(orderParams)
Instructions:
/**
*
* @param {object} orderParams
* @returns Promise
*/
async APENFTOrders.createLowerPriceOrder(orderParams);
Example:
const params = {
collection: "TL39x7unoU1ivqxac43umyUaFoGzEE2Ens",
id: "2",
price: 80,
};
let orderParams = await sdk_query.getLowerPriceOrderParams(params);
await sdk_orders.createLowerPriceOrder(orderParams);
Accept an Order
Accept and Buy
Obtain the input parameters of the best ask order:
APENFTQuery.getAssetBestAskOrderInfo(params)
Instructions:
/**
*
* @param {string} collection
* @param {string} id
* @returns Promise
*/
async APENFTQuery.getAssetBestAskOrderInfo(collection,id);
Example:
let bestAskOrder = await sdk_query.getAssetBestAskOrderInfo(
"TDczyk1W3jNf62cfeZ5d7CasiVXfwy4xiY",
"252"
);
APENFTOrders.account.orderMatch({ buy, sell })
Instructions:
/**
*
* @param {object} buyOrder
* @param {object} sellOrder
* @returns Promise
*/
async APENFTOrders.account.orderMatch({ buyOrder, sellOrder });
Example:
let OrderSide = {
0: "Buy",
1: "Sell",
Buy: 0,
Sell: 1,
};
let bestAskOrder = await sdk_query.getAssetBestAskOrderInfo(
"TDczyk1W3jNf62cfeZ5d7CasiVXfwy4xiY",
"252"
);
const accountAddress = "XXXXXX";
const signedOrder = sdk_orders.orders.orderFromJSON(bestAskOrder);
let recipientAddress = "";
if (bestAskOrder.side === OrderSide.Sell) {
recipientAddress = accountAddress;
}
if (bestAskOrder.side === OrderSide.Buy) {
recipientAddress = bestAskOrder.maker;
}
const { buy, sell } = sdk_orders.orders.makeMatchingOrder({
signedOrder,
accountAddress: accountAddress,
recipientAddress,
});
await sdk_orders.account.orderMatch({ buy, sell });
Accept an Offer
Query Offers Received
APENFTQuery.getReceivedOffers(account,pagination)
Instructions:
/**
*
* @param {string} account
* @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getReceivedOffers(account,pagination);
Example:
let receivedOffers = await sdk_query.getReceivedOffers(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("receivedOffers", receivedOffers);
APENFTOrders.account.orderMatch({ buy, sell })
Instructions:
/**
*
* @param {object} buyOrder
* @param {object} sellOrder
* @returns Promise
*/
async APENFTOrders.account.orderMatch({ buyOrder, sellOrder });
Example:
let OrderSide = {
0: "Buy",
1: "Sell",
Buy: 0,
Sell: 1,
};
// Gets a list of bids received
const receivedOffers = await sdk_query.getReceivedOffers(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
// Choose to accept the NTH bid (a price for an NFT)
// You can filter an NFT yourself based on the returned data
const n = 0;
let bestBidOrder = receivedOffers?.items?.[n]?.bestBidOrder;
// Current wallet address
const accountAddress = "XXXXXX";
const signedOrder = sdk_orders.orders.orderFromJSON(bestBidOrder);
let recipientAddress = "";
if (bestBidOrder.side === OrderSide.Sell) {
recipientAddress = accountAddress;
}
if (bestBidOrder.side === OrderSide.Buy) {
recipientAddress = bestBidOrder.maker;
}
const { buy, sell } = sdk_orders.orders.makeMatchingOrder({
signedOrder,
accountAddress: accountAddress,
recipientAddress,
});
await sdk_orders.account.orderMatch({ buy, sell });
Cancel an Order
Cancel a Listing
Obtain the input parameters of the best ask order:
APENFTQuery.getAssetBestAskOrderInfo(collection,id)
Instructions:
/**
*
* @param {string} collection
* @param {string} id
* @returns Promise
*/
async APENFTQuery.getAssetBestAskOrderInfo(collection,id);
Example:
const order = await sdk_query.getAssetBestAskOrderInfo(
"TL39x7unoU1ivqxac43umyUaFoGzEE2Ens",
"2"
);
APENFTOrders.account.orderCancel(order)
Instructions:
/**
*
* @param {object} order
* @returns Promise
*/
async APENFTOrders.account.orderCancel(order);
Example:
const order = await sdk_query.getAssetListingInfo(
"TL39x7unoU1ivqxac43umyUaFoGzEE2Ens",
"2"
);
const _order = sdk_orders.orders.orderFromJSON(order);
await sdk_orders.account.orderCancel(_order);
Cancel an Offer
Query offers sent:
APENFTQuery.getSentOffers(account,pagination)
Instructions:
/**
*
* @param {string} account
* @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getSentOffers(account,pagination);
Example:
const sentOffers = await sdk_query.getSentOffers(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("sentOffers", sentOffers);
APENFTOrders.account.orderCancel(order)
Instructions:
/**
*
* @param {object} order
* @returns Promise
*/
async APENFTOrders.account.orderCancel(order);
Example:
// Get sent offers
const sentOffers = await sdk_query.getSentOffers(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("sentOffers", sentOffers);
// Cancel the Nth NFT offer
const n = 0;
let order = sentOffers?.items?.[n];
const _order = sdk_orders.orders.orderFromJSON(order);
await sdk_orders.account.orderCancel(_order);
Transfer Assets
Obtain input parameters:
APENFTQuery.getTransferParams(collection,id)
Instructions:
/**
*
* @param {string} collection
* @param {string} id
* @returns Promise
*/
async APENFTQuery.getTransferParams(collection,id);
Example:
const { metadata, assetData } = await sdk_query.getTransferParams(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ",
"1327"
);
APENFTOrders.account.assetTransfer(metadata, to)
Instructions:
/**
*
* @param {object} metadata
* @param {string} to
* @returns Promise
*/
async APENFTOrders.account.assetTransfer(metadata, to)
Example:
const { metadata, assetData } = await sdk_query.getTransferParams(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ",
"1327"
);
const { newAsset } = await sdk_orders.getAssetOrderVersion(assetData);
if (metadata?.asset) {
metadata.asset.data = newAsset || "";
}
let to = "TQzRKbEgp7iSj9fpXX5ghdBHHoh3tEtgwU";
await sdk_orders.account.assetTransfer(metadata, to);
Query Orders
Query the Listed Prices of an NFT
Query the Listed Prices of an NFT:
APENFTQuery.getAssetListingOrders(collection,id,pagination)
Instructions:
/**
*
* @param {string} collection
* @param {string} id - id
* @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getAssetListingOrders(collection,id,pagination);
Example:
const listingData = await sdk_query.getAssetListingOrders(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ",
"1327",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("listingData", listingData);
Query the Offer List of an NFT
APENFTQuery.getAssetOffers(collection,id,pagination)
Instructions:
/**
*
* @param {string} collection
* @param {string} id - id
* @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getAssetOffers(collection,id,pagination);
Example:
const offersData = await sdk_query.getAssetOffers(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ",
"1327",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("offersData", offerData);
Query the Trading History of an NFT
APENFTQuery.getAssetTradingHistory(collection,id,pagination)
Instructions:
/**
*
* @param {string} collection
* @param {string} id - id
* @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getAssetTradingHistory(collection,id,pagination);
Example:
const assetTradingHistory = await sdk_query.getAssetTradingHistory(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ",
"1327",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("assetTradingHistory", assetTradingHistory);
Query Offers Received
APENFTQuery.getReceivedOffers(account,pagination)
Instructions:
/**
*
* @param {string} account
* @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getReceivedOffers(account,pagination);
Example:
const receivedOffers = await sdk_query.getReceivedOffers(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("receivedOffers", receivedOffers);
Query Offers Sent
APENFTQuery.getSentOffers(account,pagination)
Instructions:
/**
*
* @param {string} account
* * @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getSentOffers(account,pagination);
Example:
const sentOffers = await sdk_query.getSentOffers(
"TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("sentOffers", sentOffers);
Collection
Query Collections
Query the NFT List Under a Collection
APENFTQuery.getCollectionAssetsList(collection,pagination)
Instructions:
/**
*
* @param {string} collection
* @param {object} pagination
* @returns Promise
*/
async APENFTQuery.getCollectionAssetsList(collection,pagination);
Example:
const collectionAssetsList = await sdk_query.getCollectionAssetsList(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ",
{
first: 100, // min:1 max:100
cursor: "",
}
);
console.log("collectionAssetsList", collectionAssetsList);
Query Single Collection Info
APENFTQuery.getSingleCollectionInfo(collection)
Instructions:
/**
*
* @param {string} collection
* @returns Promise
*/
async APENFTQuery.getSingleCollectionInfo(collection);
Example:
const singleCollectionInfo = await sdk_query.getSingleCollectionInfo(
"TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ"
);
console.log("singleCollectionInfo", singleCollectionInfo);
Query Single Collection Attributes
APENFTQuery.getSingleCollectionAttributes(collection)
Instructions:
/**
* @param {string} collection
* @returns Promise
*/
async APENFTQuery.getSingleCollectionAttributes(collection: string): Promise;
Example:
const singleCollectionAttributes = await sdk_query.getSingleCollectionAttributes("TQfujfp9LNU4yRYcAiXcLRmjDuVKQ8U3AJ");
console.log("singleCollectionAttributes", singleCollectionAttributes);
Query All Collections
APENFTQuery.getAllCollections({sort, pagination, filters});
Instructions:
async APENFTQuery.getAllCollections(params: {sort?: CollectionSortBy, pagination?: Pagination, filters?: CollectionListFilterObj}): Promise;
enum CollectionSortBy {
Volume7d = "Volume7d",
Volume24h = "Volume24h",
Volume30d = "Volume30d",
VolumeTotal = "VolumeTotal",
}
interface Pagination {
first: number
cursor?: string
}
interface CollectionListFilterObj {
search?: string
owners?: string[]
}
Example:
const collections = await sdk_query.getAllCollections({
sort: CollectionSortBy.Volume7d,
pagination: { first: 20 },
filters: {
search: "test",
owners: ["TFrBnJPgZEfXtvauVG9XVLaDEDDo5jtMWV"],
},
});
console.log("collections", collections);
Query Hot Collections
APENFTQuery.getHotCollections({chain, is_recommend})
Instructions:
async APENFTQuery.getHotCollections(params: {chain: string, is_recommend: boolean}): Promise;
Example:
const hotCollections = await sdk_query.getHotCollections({chain: "tron", is_recommend: true});
console.log("hotCollections", hotCollections);
Query Collection Trade Trend
APENFTQuery.getCollectionTradeTrend({ days, collection })
Instructions:
async APENFTQuery.getCollectionTradeTrend(params: {days?: CollectionTradeTrendFilterDays, collection: string}): Promise;
enum CollectionTradeTrendFilterDays {
Days_7 = 'Days_7',
Days_14 = 'Days_14',
Days_30 = 'Days_30',
Days_60 = 'Days_60',
Days_90 = 'Days_90',
Days_365 = 'Days_365',
Days_All = 'Days_All',
}
interface CollectionTradeTrendParams {
days?: CollectionTradeTrendFilterDays
collection: string
}
Example:
const collectionTradeTrend = await sdk_query.getCollectionTradeTrend({
days: CollectionTradeTrendFilterDays.Days_7,
collection: "TLLyoedhRyoJdxYYPvHKr3pMgiBQxayn5c",
});
console.log("collectionTradeTrend", collectionTradeTrend);
Query Collection Trading History
APENFTQuery.getCollectionTradingHistory({ pagination, event_types, currencies, collections, user })
Instructions:
async APENFTQuery.getCollectionTradingHistory(params: CollectionTradingHistoryParams): Promise<any>;
enum EventType {
Transfer = 'Transfer',
Offer = 'Offer',
Listing = 'Listing',
CancelOffer = 'CancelOffer',
CancelListing = 'CancelListing',
Mint = 'Mint',
Burn = 'Burn',
Sale = 'Sale',
}
interface Pagination {
first: number
cursor?: string
}
interface CollectionTradingHistoryParams {
pagination?: Pagination
event_types: EventType[]
currencies: string[]
collections: string[]
user: string
}
Example:
const currencies = await sdk_query.getCurrencies();
const trxAndUsdtAddresses = currencies
.filter((currency) => currency.symbol === "TRX" || currency.symbol === "USDT")
.map((currency) => currency.address);
const collectionTradingHistory = await sdk_query.getCollectionTradingHistory({
collections: ["TLLyoedhRyoJdxYYPvHKr3pMgiBQxayn5c"],
pagination: { first: 20 },
event_types: [EventType.Sale, EventType.Transfer],
currencies: trxAndUsdtAddresses,
});
console.log("collectionTradingHistory", collectionTradingHistory);