Skip to content

Kontor Indexer Client

The indexer client is an interface to a Kontor Indexer. It allows users to interface with smart contract data and compose transactions via Kontor Indexer Actions.

Import

import {  createKontorIndexerClient } from "@kontor/kontor-sdk";

Usage

import {  createKontorIndexerClient, http, signet } from "@kontor/kontor-sdk";
 
const indexerClient = createKontorIndexerClient({ 
    chain: signet, 
    transport: http(), 
});  

From here, you can call Kontor Indexer Actions such as viewContract to read contract state.

 
const totalSupply = await indexerClient.viewContract({
  wit: nativeToken.wit,
  contractAddress: 'token_0_0',
  functionName: "total-supply",
})

With webSocket transport

The indexer client can also be configured with a webSocket transport to enable web socket dependent actions.

import {  createKontorIndexerClient, http, webSocket, signet, nativeToken } from "@kontor/kontor-sdk";
 
const clientWithWebsocket = createKontorIndexerClient({ 
    chain: signet, 
    transport: webSocket(), 
});  
 
clientWithWebsocket.watchEvents({
	onEvent: (event) => {
		console.log(event);
	},
	onError: console.log,
});
 
 
// When the client is only configured with `webSocket` transport,
// it is only decorated with `webSocket` actions
clientWithWebsocket.
account
chain
extend
watchEvents
websocket
const clientWithHttpAndWebsocket = createKontorIndexerClient({ chain: signet, transport: { http: http(), websocket: webSocket() }, }); clientWithHttpAndWebsocket.watchEvents({ onEvent: (event) => { console.log(event); }, onError: console.log, }); // When the client is only configured with `http` and `webSocket` // transport, it is decorated with `http` and `webSocket` actions. clientWithHttpAndWebsocket.
account
buildComposeQuery
buildInstructionQuery
chain
composeTransaction
extend
getBlock
getContract
getIndexerStatus
getLatestBlock
getResult
getTransaction
http
inspectTransaction
inspectTransactionHex
listBlocks
listBlockTransactions
listContracts
listResults
listTransactions
procContract
simulateContract
simulateTransaction
viewContract
viewContractRaw
watchEvents
websocket