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.accountchainextendwatchEventswebsocket
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.accountbuildComposeQuerybuildInstructionQuerychaincomposeTransactionextendgetBlockgetContractgetIndexerStatusgetLatestBlockgetResultgetTransactionhttpinspectTransactioninspectTransactionHexlistBlockslistBlockTransactionslistContractslistResultslistTransactionsprocContractsimulateContractsimulateTransactionviewContractviewContractRawwatchEventswebsocket