Skip to content

viewContract

The viewContract action makes it possible to query contract state in a fully type-safe manner.

Below is an example of calling several view methods on the nativeToken contract.

import { nativeToken, createKontorIndexerClient, http, signet } from '@kontor/kontor-sdk'
 
export const indexerClient = createKontorIndexerClient({
  chain: signet,
  transport: http()
})
 
const totalSupply = await indexerClient.viewContract({
  wit: nativeToken.wit,
  contractAddress: 'token_0_0',
  functionName: '
balance
balances
total-supply
}) const totalSupply = await indexerClient.viewContract({ wit: nativeToken.wit, contractAddress: 'token_0_0', functionName: 'total-supply', }) const userBalance = await indexerClient.viewContract({ wit: nativeToken.wit, contractAddress: 'token_0_0', functionName: 'balance', args: [ "2c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51f" ] })