JavaScript SDK

El paquete @kabila-tech/kabila-sdk-js es un SDK de JavaScript/TypeScript que envuelve las REST APIs de Kabila en una interfaz simple y amigable para desarrolladores. En lugar de gestionar peticiones HTTP, autenticación y parseo de respuestas manualmente, el SDK se encarga de todo por ti.

@kabila-tech/kabila-sdk-js

A JavaScript SDK for Kabila
npm
v0.3.5MIT17 sept 2025
npm install @kabila-tech/kabila-sdk-js
cryptohederahashgraphkabilasdktypescript

📋 Table of Contents

🔧 Quick Navigation

📦 Installation

Bash
npm install @kabila-tech/kabila-sdk-js
📋 Alternative Installation Methods
Bash
# Using yarn
yarn add @kabila-tech/kabila-sdk-js

# Using pnpm
pnpm add @kabila-tech/kabila-sdk-js

🚀 Quick Start

🔓 Public Operations Examples

Get NFTs

Typescript
import { KabilaSdk } from '@kabila-tech/kabila-sdk-js';

const kabilaSdk = new KabilaSdk();

const result = await kabilaSdk.marketManager.nftItems.getItems(
  {
    limit: 10,
    skip: 0,
    orderBy: 'serialNumber',
    fields: ['tokenId', 'name', 'price', 'serialNumber', 'sellerId']
  },
  {
    tokenId: '0.0.2179656',
    filterAttributes: {
      Body: ['Green', 'X Ray'],
      Feet: ['Barefoot']
    }
  }
);

🔐 Authenticated Operations Examples

Login + Get Received Offers

Typescript
import { KabilaSdk, AuthUtils } from '@kabila-tech/kabila-sdk-js';
import { DAppConnector, SignMessageParams } from '@hashgraph/hedera-wallet-connect';

// ⚠️  IMPORTANT: Initialize your own DAppConnector instance
// const dAppConnector = new DAppConnector(...);
// await dAppConnector.init({ logger: 'error' });

/* 🔑 Step 1: Sign message */
const address = '0.0.1234';
const params: SignMessageParams = {
  signerAccountId: 'hedera:mainnet:' + address,
  message: AuthUtils.getKabilaAuthMessage()
};

const { signatureMap } = await dAppConnector.signMessage(params);

/* 🔐 Step 2: Login */
const {
  data: { token, publicKey }
} = await kabilaSdk.users.login(address, signatureMap);
kabilaSdk.setAuth(token);

/* 📋 Step 3: Get offers */
const result = await kabilaSdk.marketManager.userOffers.getOffersReceived(address, { limit: 10 });

Buy NFT (Get + Execute Tx)

Typescript
import { KabilaSdk } from '@kabila-tech/kabila-sdk-js';
import { DAppConnector, SignTransactionParams } from '@hashgraph/hedera-wallet-connect';
import { AccountAllowanceApproveTransaction, NftId, TokenId } from '@hashgraph/sdk';

const tokenId = '0.0.123';
const serialNumber = 155;

/* 🛒 Step 1: Get purchase transaction */
const { data: transaction } = await kabilaSdk.marketManager.nftItems.getNftItemsPurchaseTransaction([
  { tokenId, serialNumber }
]);

/* ✍️ Step 2: Sign transaction */
const params: SignTransactionParams = {
  signerAccountId: 'hedera:mainnet:' + address,
  transactionBody: transaction.transaction
};

const { signatureMap } = await dAppConnector.signTransaction(params);

/* ✅ Step 3: Execute transaction */
await kabilaSdk.marketManager.nftItems.executeNftItemsPurchaseTransaction(signatureMap);

List NFT

Typescript
import { KabilaSdk, WHBAR_TOKEN_ID, MARKET_ACCOUNT_ID } from '@kabila-tech/kabila-sdk-js';
import { DAppConnector, SignTransactionParams } from '@hashgraph/hedera-wallet-connect';

const nftItemsToList: NftItemCreation[] = [
  {
    tokenId: '0.0.2179656',
    serialNumber: 1000,
    allowOffers: true,
    currency: WHBAR_TOKEN_ID,
    minOfferPrice: 300,
    price: 500
  }
];

/* 🔐 Step 1: Give allowance to MARKET_ACCOUNT_ID */
const client = Client.forTestnet();
const signer = dAppConnector.getSigner(AccountId.fromString(buyerAccountId));

const allowanceTx = new AccountAllowanceApproveTransaction()
  .approveTokenNftAllowance(
    new NftId(TokenId.fromString(nftItemsToList[0].tokenId), nftItemsToList[0].serialNumber),
    AccountId.fromString(buyerAccountId),
    AccountId.fromString(MARKET_ACCOUNT_ID)
  )
  .setTransactionId(TransactionId.generate(accountId))
  .setNodeAccountIds([<nodeAccountId>])
  .freeze();

const allowanceTxSigned = await signer.signTransaction(allowanceTx);
await allowanceTxSigned.execute(client);

/* 📋 Step 2: List NFT */
const { data: nftItemsListed } = await kabilaSdk.marketManager.nftItems.listNftItem(nftItemsToList);

🔐 Signature Authentication for Sensitive Operations

Some methods require an additional signature for sensitive operations. Use AuthUtils.getKabilaAuthMessage5min() to get the authentication message:

⚠️ Important: The getKabilaAuthMessage5min() method generates a time-based message that expires every 5 minutes. This provides additional security for sensitive operations.

Typescript
import { AuthUtils } from '@kabila-tech/kabila-sdk-js';

/* 🔑 Get signature for sensitive operations */
const params: SignMessageParams = {
  signerAccountId: 'hedera:mainnet:' + address,
  message: AuthUtils.getKabilaAuthMessage5min()
};

const { signatureMap } = await dAppConnector.signMessage(params);
const signature = signatureMap; // Use this signature in the methods below

🔐 Signature Required Operations Examples

NFT Management Operations

Typescript
/* 🏷️ Update NFT price */
const priceUpdate = {
  signature: signatureMap,
  price: 100,
  currency: WHBAR_TOKEN_ID,
  allowOffers: true,
  minOfferPrice: 50
};
await kabilaSdk.marketManager.nftItems.updateNftItemPrice(tokenId, serialNumber, priceUpdate);

/* 🗑️ Delist NFT */
const delistData = {
  signature: signatureMap,
  nftItems: [{ tokenId, serialNumber }]
};
await kabilaSdk.marketManager.nftItems.delistNftItem(delistData);

/* 💰 Update offer */
// Buyer updates offer (requires allowance, no signature)
const buyerOfferUpdate = {
  price: 80,
  signature: undefined
};
await kabilaSdk.marketManager.nftItemsOffers.updateNftItemOffer(offerId, buyerOfferUpdate);

// Seller updates offer (requires signature, no allowance)
const sellerOfferUpdate = {
  price: 90,
  signature: signatureMap
};
await kabilaSdk.marketManager.nftItemsOffers.updateNftItemOffer(offerId, sellerOfferUpdate);

📝 RequestOptions Examples

🔧 Configuration Options
Typescript
// Basic pagination
const basicOptions: Partial<RequestOptions> = {
  limit: 10,
  skip: 0
};

// Pagination with ordering
const orderedOptions: Partial<RequestOptions> = {
  limit: 20,
  skip: 10,
  orderBy: 'price',
  orderDir: 'desc'
};

// Multiple ordering fields
const multiOrderOptions: Partial<RequestOptions> = {
  limit: 25,
  orderBy: ['price', 'createdAt'],
  orderDir: ['desc', 'asc']
};

📘 Full Documentation

👤 Users API

MethodDescriptionReturns
login(accountId, signature)Authenticate user with signatureApiResult<{ token: string; publicKey: string }>
Typescript
login(accountId: string, signature: string): ApiResult<{ token: string; publicKey: string }>

🏢 Market Manager API

📖 Full API Documentation: Kabila Market Manager Docs

🎨 NFT Items

MethodDescriptionReturnsRequirements
getItems()Get NFTs with filtering optionsApiResult-
getItemById()Get specific NFT by IDApiResult-
getNftItemsPurchaseTransaction()Get purchase transactionApiResult<{ transaction: string }>-
executeNftItemsPurchaseTransaction()Execute purchase transactionApiResult-
listNftItem()List NFTs for saleApiResultapproveTokenNftAllowance()
delistNftItem()Remove NFTs from saleApiResultsignature
updateNftItemPrice()Update NFT priceApiResultsignature
📋 Detailed Method Signatures
Typescript
// Get NFTs with filtering
getItems(requestOptions?: RequestOptions, extraFilters?: Object): ApiResult<NftItem[]>

// Get specific NFT
getItemById(tokenId: string, serialNumber: number, requestOptions?: RequestOptions): ApiResult<NftItem>

// Purchase flow
getNftItemsPurchaseTransaction(nftItemIds: NftItemId[], requestOptions?: RequestOptions, extraOptions?: Object): ApiResult<{ transaction: string }>
executeNftItemsPurchaseTransaction(signatureMap: string, requestOptions?: RequestOptions): ApiResult<void>

// Listing management
listNftItem(newNftItems: NftItemCreation[], requestOptions?: RequestOptions): ApiResult<NftItemId[]>
delistNftItem(nftItem: NftItemDelist, requestOptions?: RequestOptions): ApiResult<void>
updateNftItemPrice(tokenId: string, serialNumber: number, updatedNftItem: NftItemPriceEdition, requestOptions?: RequestOptions): ApiResult<void>

🎨 NFT Collections

MethodDescriptionReturns
getCollectionById()Get collection by token IDApiResult
getCollections()Get collectionsApiResult
getCollectionsListed()Get listed collectionsApiResult
getCollectionsAttributesStats()Get collection attributes statisticsApiResult
getCollectionAttributes()Get collection attributesApiResult
getCollectionNftItemsRarityMap()Get NFT rarity mapApiResult

🎨 NFT Items Offers

MethodDescriptionReturnsRequirements
getNftItemsOffers()Get all NFT offersApiResult-
getNftItemOffers()Get offers for specific NFTApiResult-
createNftItemOffers()Create new offersApiResultapproveHbarAllowance()
updateNftItemOffer()Update offer priceApiResult<{ data: NftItemOfferEdition[]; modifiedCount: number }>approveHbarAllowance() (buyer only) + signature (seller only)
deleteNftItemOffer()Delete offerApiResult-
getNftItemOfferTransaction()Get offer transactionApiResult<{ transaction: string }>-
executeNftItemOfferTransaction()Execute offer transactionApiResult-

🏷️ NFT Collection Offers

MethodDescriptionReturnsRequirements
getNftCollectionsOffers()Get collection offersApiResult-
createNftCollectionOffers()Create collection offersApiResultapproveHbarAllowance()
getNftCollectionsOffersPrice()Get total offer priceApiResult<{ total: number }>-
deleteNftCollectionOffer()Delete collection offerApiResult-
gettNftCollectionOfferTransaction()Get collection offer transactionApiResult<{ transaction: string }>-
executeNftCollectionOfferTransaction()Execute collection offer transactionApiResult<{ _id: string }[]>-

👤 User Offers

MethodDescriptionReturns
getOffersMade()Get offers made by userApiResult
getOffersReceived()Get offers received by userApiResult
getAmountOffersMade()Get total amount of offers madeApiResult

📊 Market Analytics API

📖 Full API Documentation: Kabila Market Analytics Docs

🎨 Activity

MethodDescriptionReturns
getActivity()Get NFT items activityApiResult
Typescript
getActivity(requestOptions?: RequestOptions, extraFilters?: Object): ApiResult<NftItemActivity[]>

💱 Supported Currency

Typescript
WHBAR_TOKEN_ID = '0.0.1062664';

🔐 Required Allowances & Signatures

Spender: MARKETPLACE_ACCOUNT_ID = '0.0.4824758'

Allowances

FunctionRequired AllowanceDescription
listNftItem()approveTokenNftAllowance()Allow marketplace to transfer your NFTs
createNftItemOffers()approveHbarAllowance()Allow marketplace to spend your HBAR
updateNftItemOffer()approveHbarAllowance() (buyer only)Allow marketplace to spend your HBAR when buyer updates offer
createNftCollectionOffers()approveHbarAllowance()Allow marketplace to spend your HBAR

Signature Requirements

FunctionRequired SignatureDescription
marketManager.nftItems.delistNftItem()signatureRemove NFTs from sale
marketManager.nftItems.updateNftItemPrice()signatureUpdate NFT prices
marketManager.nftItemsOffers.updateNftItemOffer()signature (seller only)Update offer prices when acting as seller

🧱 Data Models

💡 Tip: Use these data models for full TypeScript support and type safety.

🎨 Core Types

ApiResult

Generic wrapper for all API responses.

Typescript
interface ApiResult<T> {
  data: T; // The actual response data
  status: number; // HTTP status code
  statusText: string; // HTTP status text
  headers: {}; // Response headers
}

RequestOptions

Configuration options for API requests including pagination, filtering, and authentication.

Typescript
interface RequestOptions {
  limit: number; // Number of items to return
  skip: number; // Number of items to skip (for pagination)
  fields: string[]; // Specific fields to return
  search: string; // Search term for filtering
  orderBy: string | string[]; // Field(s) to order by
  orderDir: string | string[]; // Order direction ('asc' or 'desc')
  format: Format; // Response format
  auth: string; // Authentication token (Bearer token)
}

Format

Enum for response format options.

Typescript
enum Format {
  WITH_PAGINATION = 'WITH_PAGINATION', // Include pagination metadata
  NO_PAGINATION = 'NO_PAGINATION' // Return only data without pagination
}

🎨 NFT Models

NftItem

Complete NFT item information.

Typescript
interface NftItem {
  _id?: string; // Database ID
  allowOffers: boolean; // Whether offers are allowed
  attributes?: {
    // NFT attributes/traits
    traitType: string; // Attribute category
    value: string; // Attribute value
  };
  buyerId?: string; // Current buyer ID
  createdAt: Date; // Listing creation date
  currency: string; // Currency token ID
  description?: string; // NFT description
  endDate?: Date; // Auction end date
  imageCid?: string; // Image CID
  imageType?: string; // Image MIME type
  metadataCid?: string; // Metadata CID
  minOfferPrice?: number; // Minimum offer price
  name?: string; // NFT name
  price: number; // Current price
  rarity?: {
    // Rarity information
    rank?: number; // Rarity rank
    rarityScore?: number; // Rarity score
  };
  sellerId: string; // Seller account ID
  serialNumber: number; // NFT serial number
  status?: string; // Current status
  statusDate: Date; // Status update date
  tokenId: string; // Token ID
}

NftItemCreation

Data required to create a new NFT listing.

Typescript
interface NftItemCreation {
  allowOffers: boolean; // Whether offers are allowed
  currency: string; // Currency token ID
  minOfferPrice: number; // Minimum offer price
  price: number; // Listing price
  serialNumber: number; // NFT serial number
  tokenId: string; // Token ID
}

NftItemId

Unique identifier for an NFT.

Typescript
interface NftItemId {
  serialNumber: number; // NFT serial number
  tokenId: string; // Token ID
}

NftItemPriceEdition

Data for updating NFT price information.

Typescript
interface NftItemPriceEdition {
  signature: string; // Required signature for price updates
  allowOffers: boolean; // Whether offers are allowed
  currency: string; // Currency token ID
  minOfferPrice?: number; // Minimum offer price
  price: number; // New price
}

NftItemDelist

Data for removing NFTs from sale.

Typescript
interface NftItemDelist {
  signature: string; // Required signature for delisting
  nftItems: NftItemId[]; // Array of NFTs to delist
}

🎨 Collection Models

NftCollection

Complete NFT collection information.

Typescript
interface NftCollection {
  _id?: string; // Database ID
  attributes?: Attribute[]; // Collection attributes
  createdAt?: Date; // Creation date
  creatorId?: string; // Creator account ID
  creatorName?: string; // Creator name
  description?: string; // Collection description
  highestCollectionOffer?: number; // Highest offer received
  holders?: number; // Number of holders
  imageCid: string; // Collection image CID
  imageType: string; // Image MIME type
  mainTag?: string; // Main category tag
  minPrice?: number; // Minimum price in collection
  minted?: number; // Number of minted NFTs
  name?: string; // Collection name
  networkVolume?: number; // Total trading volume
  nftsListed?: number; // Number of listed NFTs
  salesVolume: NftCollectionSalesVolume; // Network sales volume
  slug?: string; // Collection slug
  socialNetworks?: Array<string>; // Social media links
  supply?: number; // Total supply
  tokenId?: string; // Token ID
  verificationType?: number; // Verification status
}
🎨 Verification Types
ValueStatus
-1SCAM
0NONE
2RRSS
4DOXXED
6FEATURED
8FEATURED_HOME
10VERIFIED

Attribute

Individual attribute/trait information.

Typescript
interface Attribute {
  count: number; // Number of NFTs with this attribute
  currency?: string; // Currency for pricing
  minPrice?: number; // Minimum price for this attribute
  rarityPct?: number; // Rarity percentage
  total?: number; // Total count
  traitType: string; // Attribute category
  value: string; // Attribute value
}

Attributes

Collection of attributes.

Typescript
interface Attributes {
  attribute: Array<Attribute>; // Array of attributes
}

NftCollectionNftItemsRarity

Rarity mapping for collection NFTs.

Typescript
interface NftCollectionNftItemsRarity {
  _id?: string; // Database ID
  nftItemsRarityMap?: NftItemsRarityMap[]; // Rarity mappings
  tokenId?: string; // Token ID
}

NftItemsRarity

Individual NFT rarity information.

Typescript
interface NftItemsRarity {
  rank: number; // Rarity rank
  rarityScore: number; // Rarity score
}

NftItemsRarityMap

Mapping of serial numbers to rarity data.

Typescript
interface NftItemsRarityMap {
  serialNumber: NftItemsRarity; // Serial number mapped to rarity
}

NftStatusMap

Boolean mapping for NFT status.

Typescript
interface NftStatusMap {
  [key: number]: boolean; // Serial number to status mapping
}

NftCollectionSalesVolume

Network sales volume information for an NFT collection.

Typescript
interface NftCollectionSalesVolume {
  updatedAt: Date; // Last update date
  last24h: number; // Sales volume in the last 24 hours
  previous24h: number; // Sales volume in the previous 24 hours
  last7d: number; // Sales volume in the last 7 days
  previous7d: number; // Sales volume in the previous 7 days
  last30d: number; // Sales volume in the last 30 days
  previous30d: number; // Sales volume in the previous 30 days
}

🎨 Offer Models

NftItemOffer

Complete NFT item offer information.

Typescript
interface NftItemOffer {
  _id?: string; // Database ID
  buyerId: string; // Buyer account ID
  buyerPrice: number; // Buyer's offer price
  createdAt: Date; // Offer creation date
  currency: string; // Currency token ID
  initialPrice: number; // Initial offer price
  lastBidder: 'BUYER' | 'SELLER'; // Who made the last bid
  nftItem?: {
    // Associated NFT information
    imageCid: string; // NFT image CID
    imageType: string; // Image MIME type
    name: string; // NFT name
  };
  sellerId?: string; // Seller account ID
  sellerPrice?: number; // Seller's counter-offer
  serialNumber: number; // NFT serial number
  tokenId: string; // Token ID
  updatedAt: Date; // Last update date
}

NftItemOfferCreation

Data required to create a new NFT offer.

Typescript
interface NftItemOfferCreation {
  currency: string; // Currency token ID
  price: number; // Offer price
  serialNumber: number; // NFT serial number
  tokenId: string; // Token ID
}

NftItemOfferEdition

Data for updating an existing offer.

Typescript
interface NftItemOfferEdition {
  buyerId: string; // Buyer account ID
  buyerPrice: number; // Buyer's offer price
  currency: string; // Currency token ID
  sellerId: string; // Seller account ID
  sellerPrice: number; // Seller's counter-offer
  tokenId: string; // Token ID
}

Note: The updateNftItemOffer() method accepts { price: number; signature: string | undefined } as parameter:

  • Buyer updates: Requires approveHbarAllowance() but no signature
  • Seller updates: Requires signature but no allowance

NftCollectionOffer

Collection offer information.

Typescript
interface NftCollectionOffer {
  _id?: string; // Database ID
  buyerId: string; // Buyer account ID
  tokenId: string; // Token ID
  price: number; // Offer price
  currency: string; // Currency token ID
  createdAt: string; // Creation date
  status?: string; // Offer status
  statusDate?: string; // Status update date
}

NftCollectionOfferCreation

Data required to create a collection offer.

Typescript
interface NftCollectionOfferCreation {
  tokenId: string; // Token ID
  price: number; // Offer price
  currency: string; // Currency token ID
}

NftCollectionOfferAcceptance

Data for accepting collection offers.

Typescript
interface NftCollectionOfferAcceptance {
  id: string; // Offer ID
  serialNumber: number; // NFT serial number
}

UserOffer

Extended offer information including NFT details.

Typescript
interface UserOffer extends NftItemOffer {
  totalBuyerPrice: number; // Total price from buyer
  nftItemListed: NftItem; // Associated NFT item
}

UserOfferPrice

Summary of user's offer prices.

Typescript
interface UserOfferPrice {
  totalPriceCollectionsOffers: number; // Total collection offers
  totalPriceNftItemsOffers: number; // Total NFT item offers
  totalPrice: number; // Combined total
}

📊 Market Analytics Models

NftItemActivity

Typescript
interface NftItemActivity {
  tokenId: string; // Token ID
  serialNumber: number; // Serial number
  collectionName: string; // Collection name
  verificationType: number; // Verification type
  name: string; // NFT name
  imageCid: string; // Image CID
  imageType: string; // Image type
  rank: number; // Rarity rank
  activityType: string; // Activity type
  subactivityType: string; // Sub-activity type
  price: number; // Price
  currency: string; // Currency
  priceUsd: number; // Price in USD
  buyerId: string; // Buyer ID
  sellerId: string; // Seller ID
  createdAt: string; // Creation date
  listedAt: string; // Listing date
  additionalId: number; // Additional ID
  transactionId: string; // Transaction ID
}

Made with ❤️ by the Kabila Team

📖 Documentation🐛 Report Issues💬 Community

¿Te resultó útil esta página?