### Example Variables for DEX Overview Query (JSON) Source: https://docs.kadindexer.io/guides/defi/dex-metrics Provides an example JSON object for the variables required by the `DexOverview` GraphQL query. This includes setting a start date, end date, and optionally a protocol address to filter the results. ```json { "startDate": "2025-09-01T00:00:00Z", "endDate": "2025-10-01T00:00:00Z" } ``` -------------------------------- ### Coin Module Examples Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection Provides example Pact queries for interacting with the Coin module. ```APIDOC ## POST /graphql ### Description Executes various Pact queries related to the Coin module. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **pactQuery** (array of PactQuery objects) - Required - An array of Pact queries to execute. ### Request Example ```json [ { "code": "(coin.details \"k:account\")", "chainId": "0" }, { "code": "(coin.supply)", "chainId": "0" }, { "code": "(coin.precision)", "chainId": "0" } ] ``` ### Response #### Success Response (200) - **data** (object) - Contains the results of the pact queries. - **pactQuery** (array of PactQueryResult objects) - Results for each query. #### Response Example ```json { "data": { "pactQuery": [ { "chainId": "0", "status": "success", "result": { "balance": "100.0", "decimals": 12, "name": "KDA" }, "error": null }, { "chainId": "0", "status": "success", "result": "1000000000000.0", "error": null }, { "chainId": "0", "status": "success", "result": 12, "error": null } ] } } ``` ``` -------------------------------- ### Coin Module Example Queries Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection This array of JSON objects provides examples of Pact queries for the Coin module. Each object specifies the code to execute and the chainId. Examples include fetching coin details, total supply, and precision. ```json [ { "code": "(coin.details \"k:account\")", "chainId": "0" }, { "code": "(coin.supply)", "chainId": "0" }, { "code": "(coin.precision)", "chainId": "0" } ] ``` -------------------------------- ### Kaddex Token Module Examples Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection Provides example Pact queries for interacting with the Kaddex Token module. ```APIDOC ## POST /graphql ### Description Executes various Pact queries related to the Kaddex Token module. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **pactQuery** (array of PactQuery objects) - Required - An array of Pact queries to execute. ### Request Example ```json [ { "code": "(describe-module \"kaddex.token\")", "chainId": "1" }, { "code": "(kaddex.token.details \"token-id\")", "chainId": "1" } ] ``` ### Response #### Success Response (200) - **data** (object) - Contains the results of the pact queries. - **pactQuery** (array of PactQueryResult objects) - Results for each query. #### Response Example ```json { "data": { "pactQuery": [ { "chainId": "1", "status": "success", "result": { "functions": [ { "name": "details", "args": [{"name": "token-id", "type": "string"}] } ] }, "error": null }, { "chainId": "1", "status": "success", "result": { "name": "Example Token", "symbol": "EX", "total-supply": "1000000.0" }, "error": null } ] } } ``` ``` -------------------------------- ### Pact Query Optimization Example Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection This snippet illustrates how to optimize Pact queries by keeping them simple and focused. The 'Good' example shows a single, direct query, while the 'Avoid' example demonstrates a less efficient multi-step query that should be refactored. ```pact ;; ✅ Good: Simple, focused query (coin.details "k:account") ;; ❌ Avoid: Complex multi-step queries (let ((account "k:account")) (coin.details account) (coin.balance account)) ``` -------------------------------- ### Custom DeFi Contracts Examples Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection Provides an example Pact query for interacting with custom DeFi contracts. ```APIDOC ## POST /graphql ### Description Executes a Pact query for a custom DeFi contract. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **pactQuery** (array of PactQuery objects) - Required - An array of Pact queries to execute. - **data** (object) - Optional - Additional data parameters for the query. ### Request Example ```json [ { "code": "(my-defi.get-pool-info)", "chainId": "2", "data": [ { "key": "pool-id", "value": "\"kda-usdc-pool\"" } ] } ] ``` ### Response #### Success Response (200) - **data** (object) - Contains the results of the pact queries. - **pactQuery** (array of PactQueryResult objects) - Results for each query. #### Response Example ```json { "data": { "pactQuery": [ { "chainId": "2", "status": "success", "result": { "reserveA": "10000.0", "reserveB": "5000.0", "totalLiquidity": "15000.0" }, "error": null } ] } } ``` ``` -------------------------------- ### Minimal GraphQL Subscription for New Blocks Source: https://docs.kadindexer.io/guides/realtime/subscriptions This GraphQL subscription fetches the hash and height of new blocks on a specified chain. It's a basic example demonstrating how to start receiving realtime block data. ```graphql subscription { newBlocks(chainIds: ["0"]) { hash height } } ``` -------------------------------- ### Kaddex Token Module Example Queries Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection This JSON array contains example queries for the Kaddex Token module. It includes a query to describe the module and another to retrieve specific token details, each associated with a chainId. ```json [ { "code": "(describe-module \"kaddex.token\")", "chainId": "1" }, { "code": "(kaddex.token.details \"token-id\")", "chainId": "1" } ] ``` -------------------------------- ### Pact: Example Contract Read Function Call Source: https://docs.kadindexer.io/apis/queries/pactQuery This Pact code example demonstrates calling a contract read function, specifically `coin.get-details`, to retrieve information about a given account. This is a typical use case for the `pactQuery` feature. ```pact (coin.get-details \"k:abcdef123456...\") ``` -------------------------------- ### Pact: Example Arithmetic Expression Source: https://docs.kadindexer.io/apis/queries/pactQuery This is an example of a simple Pact arithmetic expression that can be executed using the `pactQuery` functionality. It adds two numbers together. ```pact (+ 1 2) ``` -------------------------------- ### Example Variables for Global Token Transfer Volume Source: https://docs.kadindexer.io/guides/analytics/transaction-monitoring Example JSON variables for the 'Transfers' GraphQL query. This demonstrates querying for the 'coin' token with a limit of 1 transfer. ```json { "fungibleName": "coin", "first": 1 } ``` -------------------------------- ### Example Response for Account Balances (JSON) Source: https://docs.kadindexer.io/guides/accounts/balance-tracking Example JSON response for the `coinBalances` GraphQL query, detailing the balance and associated guard information for a specific Kadena account on a given chain. The structure facilitates displaying chain-specific balances. ```json { "data": { "coinBalances": [ { "balance": 0.0001, "chainId": "16", "guard": { "keys": [ "fc0c4b9e0b1c2df1a50694f5dbeb2faf7e637018e74f6046da1eb7e8e32e3d30" ], "predicate": "keys-all" } }, { "balance": 0.0001, "chainId": "17", "guard": { "keys": [ "fc0c4b9e0b1c2df1a50694f5dbeb2faf7e637018e74f6046da1eb7e8e32e3d30" ], "predicate": "keys-all" } } ] } } ``` -------------------------------- ### Example Response for Last Token Price in KDA (JSON) Source: https://docs.kadindexer.io/guides/defi/token-prices An example JSON response structure for the `lastTokenPriceInKda` query. It shows the retrieved price as a string value under the `data.lastTokenPriceInKda` field. This format is crucial for parsing and displaying token prices in applications. ```json { "data": { "lastTokenPriceInKda": "2.735669235344" } } ``` -------------------------------- ### GraphQL Subscriptions Source: https://docs.kadindexer.io/guides/realtime/subscriptions Examples of using GraphQL subscriptions to receive real-time data, including minimal and filtered approaches. ```APIDOC ## GraphQL Subscriptions ### Minimal Subscription Example ```graphql subscription { newBlocks(chainIds: ["0"]) { hash height } } ``` ### Filtered Subscription Example ```graphql # Filtered (targeted) subscription { events( qualifiedEventName: "coin.TRANSFER" chainId: "0" minimumDepth: 5 ) { parameterText } } ``` ### Missing Initial Data Solution To get recent data on connection, use the `quantity` parameter. ```graphql subscription { newBlocks(chainIds: ["0"], quantity: 20) { hash height } } ``` ``` -------------------------------- ### Custom DeFi Contract Example Query Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection This JSON object demonstrates querying a custom DeFi contract. It includes the Pact code to get pool information, the relevant chainId, and additional data parameters, such as the pool ID, passed to the function. ```json [ { "code": "(my-defi.get-pool-info)", "chainId": "2", "data": [ { "key": "pool-id", "value": "\"kda-usdc-pool\"" } ] } ] ``` -------------------------------- ### Troubleshooting Realtime Events Source: https://docs.kadindexer.io/guides/realtime/subscriptions Common issues and solutions when working with Kadindexer.io realtime events. ```APIDOC ## Troubleshooting Realtime Events ### Not Receiving Events **Check:** - Event name spelling (case-sensitive) - Chain ID matches event location - `minimumDepth` not too high - Connection still active - Subscription within tier limits ### High Latency **Solutions:** - Reduce requested fields - Apply more restrictive filters - Check network latency - Verify keepAlive configuration ### Missing Initial Data **Solution:** Use `quantity` parameter to get recent data on connection: ```graphql subscription { newBlocks(chainIds: ["0"], quantity: 20) { hash height } } ``` ``` -------------------------------- ### GraphQL Response Examples for Transfers (JSON) Source: https://docs.kadindexer.io/guides/accounts/transaction-history These JSON structures show the expected response from the GraphQL 'Transfers' query. The 'Most Recent' example illustrates the format for a recently fetched transaction, including details like amount, accounts, and timestamps. The 'Oldest Transaction' example demonstrates the response for a historical transfer, highlighting the data structure consistency. ```json { "data": { "transfers": { "edges": [ { "node": { "amount": "0.277", "senderAccount": "k:03f7f0029bd3abbda30d928f4ed49f9704238d93119bdd53166b8dd5cb49c667", "receiverAccount": "k:fc0c4b9e0b1c2df1a50694f5dbeb2faf7e637018e74f6046da1eb7e8e32e3d30", "crossChainTransfer": null, "requestKey": "TRuUdncV-2Y_5LxHyUhNl0X1sp58KX1HvK0Hg9UZqCU", "creationTime": "2025-08-19T02:38:15.321Z", "block": { "height": 6102691, "chainId": 1 } } } ] } } } ``` ```json { "data": { "transfers": { "edges": [ { "node": { "amount": "63.030529544427", "senderAccount": "k:cf415c73edb4666a967933bddc2e6c4a6e13b8ec0566e612b9f3cbe4a4d8506e", "receiverAccount": "k:fc0c4b9e0b1c2df1a50694f5dbeb2faf7e637018e74f6046da1eb7e8e32e3d30", "crossChainTransfer": null, "requestKey": "qMZtzZ9m8-Ao5B8jY09OWA88H2c2d6utE2RvzaE_QOQ", "creationTime": "2023-04-17T09:56:56.000Z", "block": { "height": 3643154, "chainId": 1 } } } ] } } } ``` -------------------------------- ### Set Up Node.js Project for Kadindexer API Source: https://docs.kadindexer.io/guides/node-js Initializes a Node.js project, installs the `dotenv` package for environment variable management, and sets up a `.env` file for API credentials and endpoint configuration. Node.js v18+ is recommended. ```bash mkdir kadindexer-node && cd kadindexer-node npm init -y npm i dotenv ``` ```env KADINDEXER_HTTP=https://api.mainnet.kadindexer.io/v1 KADINDEXER_API_KEY=YOUR_API_KEY_HERE ``` -------------------------------- ### Example Response for Global Token Transfer Volume Source: https://docs.kadindexer.io/guides/analytics/transaction-monitoring Example JSON response structure for the 'Transfers' GraphQL query. It shows the transfer amount for the specified token. ```json { "data": { "transfers": { "edges": [ { "node": { "amount": "0.938634" } } ] } } } ``` -------------------------------- ### Pact: List All Functions in a Module Source: https://docs.kadindexer.io/guides/smart-contracts/contract-inspection This Pact code snippet shows how to list all available functions within a specified module, using `describe-module` and querying the 'coin' module as an example. ```pact ;; List all functions in a module (describe-module "coin") ``` -------------------------------- ### Example Response for Filtered Transactions Source: https://docs.kadindexer.io/guides/analytics/transaction-monitoring Example JSON response structure for the 'Transactions' GraphQL query when filtering for the 'coin' token. It includes pagination information and details for a list of transactions. ```json { "data": { "transactions": { "pageInfo": { "endCursor": "MTc1OTIzNTQzMjozMjUzMDAwMTI=", "hasNextPage": true, "hasPreviousPage": false, "startCursor": "MTc1OTIzNTQ3NDozMjUzMDAwNTI=" }, "edges": [ { "node": { "hash": "LuzGbxsqYpJ0289JEKpAro2gbo5s2ALF1erSW4jZves", "cmd": { "meta": { "gasLimit": "15000", "chainId": 0, "creationTime": "2025-09-30T12:31:14.000Z", "gasPrice": "0.0000001", "sender": "k:db95bb27f743392abbefd67119281e78f2679cf5970da20bca704e447086db38" }, "payload": { "code": "\"(free.radio02.close-send-receive \\\"k:f99185285730c5414c0a1ec68924598b175827890fad20c18548a9b27d79ce2a\\\" [{\\\"address\\\":\\\"k:dbe05f8ad7963277b60ed7ca548a44b7b4d0fcf49c2319c55a02e0c3a3e83758\\\",\\\"gatewayId\\\":\\\"e45f01fffe7db23a\\\",\\\"mic\\\":\\\"c05e1687\\\"}] [] )\"" } }, "result": { "badResult": null, "gas": "1734", "block": { "height": 6224775, "canonical": true } } }, "cursor": "MTc1OTIzNTQ3NDozMjUzMDAwNTI=" }, { "node": { "hash": "qFgR_NaQUlDK4Jln-WCDBmEL4eCvAPxNTr-FxKh390Y", "cmd": { "meta": { "gasLimit": "3000", "chainId": 0, "creationTime": "2025-09-30T12:30:48.000Z", "gasPrice": "0.00001", "sender": "k:412695c549b11c7794ad1dbc901fe0be156db393b943464a03d1777cbd4e5392" }, "payload": { "code": "\"(coin.transfer \\\"k:412695c549b11c7794ad1dbc901fe0be156db393b943464a03d1777cbd4e5392\\\" \\\"k:7cfe3761add000c3e711fdd3316d625365ab7b9ed97a8a814acabff0359d8e10\\\" 0.48336000)"" } }, "result": { "badResult": null, "gas": "240", "block": { "height": 6224775, "canonical": true } } }, "cursor": "MTc1OTIzNTQ0ODozMjUzMDAwMjQ=" } ] } } } ``` -------------------------------- ### JSON Response for Portfolio Summary Source: https://docs.kadindexer.io/guides/defi/liquidity-analytics Example JSON response from the Portfolio Summary GraphQL query, detailing liquidity positions with their values, APRs, and associated token pairs. ```json { "data": { "liquidityPositions": { "edges": [ { "node": { "id": "1", "valueUsd": 42500.75, "apr24h": 45.2, "pair": { "token0": { "name": "coin" }, "token1": { "name": "KDX" } } } }, { "node": { "id": "2", "valueUsd": 18750.50, "apr24h": 32.8, "pair": { "token0": { "name": "coin" }, "token1": { "name": "FLUX" } } } }, { "node": { "id": "3", "valueUsd": 12000.00, "apr24h": 28.5, "pair": { "token0": { "name": "KDX" }, "token1": { "name": "FLUX" } } } } ], "totalCount": 3 } } } ``` -------------------------------- ### Example Variables for Filtered Transactions Source: https://docs.kadindexer.io/guides/analytics/transaction-monitoring Example JSON variables to be used with the 'Transactions' GraphQL query. This set demonstrates filtering for the 'coin' token on chain ID '0' with a limit of 25 transactions. ```json { "first": 25, "chainId": "0", "fungibleName": "coin" } ``` -------------------------------- ### Prefetch Static Data on Application Startup Source: https://docs.kadindexer.io/guides/advanced/performance-scaling A JavaScript async function to fetch and cache static data, such as network information and graph configuration, when an application initializes. This pattern reduces redundant requests for unchanging data. ```javascript async function initializeApp() { const networkInfo = await client.request(` query { networkInfo { networkId numberOfChains nodeChains coinsInCirculation } graphConfiguration { version minimumBlockHeight } } `); permanentCache.set('network_info', networkInfo); } ``` -------------------------------- ### JavaScript: Client-Side Filtering Example (Inefficient) Source: https://docs.kadindexer.io/guides/advanced/query-optimization An example of inefficient client-side filtering in JavaScript. This code fetches a large number of transactions and then filters them in the client, which is less performant than server-side filtering. ```javascript const all = await client.request( query { transactions(first: 1000) { edges { node { hash cmd { meta { sender chainId } } } } } } ); const filtered = all.transactions.edges .filter(e => e.node.cmd.meta.sender === "k:abc..." && e.node.cmd.meta.chainId === "1"); ``` -------------------------------- ### Batch Multi-Chain Queries for Efficiency Source: https://docs.kadindexer.io/guides/advanced/performance-scaling Demonstrates how to optimize data fetching by batching queries across multiple chains into a single request, contrasting it with a less efficient sequential approach. This reduces network overhead and rate limit consumption. ```javascript // ❌ Sequential (slow, uses more rate limit) for (const chainId of ['0', '1', '2']) { await getChainActivity(chainId); } // ✅ Batched (fast, single request) const result = await client.request(` query { c0: transactions(chainId: "0", first: 10) { ... } c1: transactions(chainId: "1", first: 10) { ... } c2: transactions(chainId: "2", first: 10) { ... } } `); ``` -------------------------------- ### Example Variables for Cross-Chain NFT Query (JSON) Source: https://docs.kadindexer.io/guides/accounts/multi-chain-accounts These are example variables to be used with the Cross-Chain NFTs GraphQL query. The primary variable is `accountName`, which specifies the account for which to fetch NFT holdings. ```json { "accountName": "k:abcdef123456789" } ``` -------------------------------- ### JavaScript Subscription Management Source: https://docs.kadindexer.io/guides/realtime/subscriptions Code examples for managing real-time subscriptions in JavaScript, including closing unused subscriptions and handling high-frequency updates. ```APIDOC ## JavaScript Subscription Management ### Close Unused Subscriptions This example shows how to manage a set of subscriptions and clean them up on page unload. ```javascript const subscriptions = new Set(); function subscribe(query, variables, handlers) { const unsubscribe = client.subscribe(query, variables, handlers); subscriptions.add(unsubscribe); return () => { unsubscribe(); subscriptions.delete(unsubscribe); }; } // Clean up on exit window.addEventListener('beforeunload', () => { subscriptions.forEach(unsub => unsub()); }); ``` ### Handle High-Frequency Updates This pattern uses a buffer to process updates in batches, preventing overwhelming the system. ```javascript const buffer = []; let processing = false; client.subscribe(query, {}, { next: (data) => { buffer.push(data); if (!processing) processBuffer(); } }); async function processBuffer() { processing = true; while (buffer.length > 0) { const batch = buffer.splice(0, 10); await processBatch(batch); // Assume processBatch is defined elsewhere } processing = false; } ``` ``` -------------------------------- ### Example Variables for NFT Transfer Query Source: https://docs.kadindexer.io/guides/accounts/transaction-history These are example variables to be used with the NFT transfer GraphQL query. They specify the account name, the number of results to fetch (`first`), and explicitly set `isNft` to true to filter for NFT transfers. ```json { "accountName": "k:fc0c4b9e0b1c2df1a50694f5dbeb2faf7e637018e74f6046da1eb7e8e32e3d30", "first": 10, "last": null, "isNft": true } ``` -------------------------------- ### Graph Configuration API Source: https://docs.kadindexer.io/apis Retrieve general information about this GraphQL API endpoint. ```APIDOC ## GET /api/graphConfiguration ### Description Retrieve general information about this GraphQL API endpoint, such as data indexation depth and API version. ### Method GET ### Endpoint /api/graphConfiguration ### Parameters None ### Response #### Success Response (200) - **graphConfiguration** (object) - Contains information about the API configuration. - **version** (string) - The API version. - **indexerRange** (object) - The range of blocks indexed by the API. - **start** (integer) - The starting block height. - **end** (integer) - The ending block height. #### Response Example ```json { "graphConfiguration": { "version": "v1.0.0", "indexerRange": { "start": 0, "end": 100000 } } } ``` ``` -------------------------------- ### Example Query Variables (JSON) Source: https://docs.kadindexer.io/guides/defi/pool-data Provides an example JSON object for variables that can be used with the 'AllPools' GraphQL query. This includes specifying the sorting order (e.g., 'TVL_USD_DESC' for highest TVL first) and the number of results to fetch ('first'). ```json { "orderBy": "TVL_USD_DESC", "first": 20 } ``` -------------------------------- ### GraphConfiguration Source: https://docs.kadindexer.io/apis/objects General information about the GraphQL API, including the minimum block height indexed and the API version. ```APIDOC ## GraphConfiguration ### Description General information about the GraphQL API. ### Fields - **minimumBlockHeight** (BigInt) - The lowest block-height that is indexed in this endpoint. - **version** (String) - The version of the graphl api. ``` -------------------------------- ### GraphQL Query Complexity Example Source: https://docs.kadindexer.io/guides/advanced/performance-scaling This GraphQL query illustrates how nested fields and the `first` argument contribute to query complexity. The example shows a query that, due to its depth and use of `first` on multiple levels, exceeds the complexity limit for the free tier. ```graphql query { blocks(first: 50) { # 50 edges { node { transactions(first: 20) { # 50 × 20 = 1,000 edges { node { result { ... on TransactionResult { events(first: 10) { # 1,000 × 10 = 10,000 (exceeds free tier!) edges { node { parameters } } } } } } } } } } } } ``` -------------------------------- ### Node.js WebSocket Client Setup for Kadindexer.io Source: https://docs.kadindexer.io/guides/realtime/connection-management Sets up a WebSocket client for connecting to Kadindexer.io using Node.js. It utilizes the `graphql-ws` library and the `ws` package for WebSocket communication. Key configurations include the API endpoint, WebSocket implementation, keep-alive interval, and retry attempts. ```javascript import { createClient } from 'graphql-ws'; import WebSocket from 'ws'; const client = createClient({ url: 'wss://api.mainnet.kadindexer.io/v1', // or wss://api.testnet.kadindexer.io/v1 for testnet webSocketImpl: WebSocket, keepAlive: 10000, retryAttempts: Infinity, shouldRetry: () => true }); ```