Skip to content

simulateContract

simulateContract simulates a type-safe contract function call without executing it on-chain. Unlike simulateTransaction which works with raw transaction hex, simulateContract uses WIT specifications to provide type-safe function calls and returns.

Usage

By default, simulateContract will return a typed result is specified by the contract wit.

import { nativeToken, createKontorIndexerClient, http, signet } from '@kontor/kontor-sdk'
 
export const indexerClient = createKontorIndexerClient({
  chain: signet,
  transport: http(),
  account: ["bc1sender...", "xonly-pubkey"]
})
 
const simulation = await indexerClient.simulateContract({
  wit: nativeToken.wit,
  contractAddress: "token_0_0",
  functionName: "transfer",
  args: ["bc1receiver...", [100n, 0]],
  satsPerVByte: 1,
  utxos: [
     "txid:vout",
  ],
  gas: 10_000n,
})

Verbose

Calling simulateContract with verbose=true will return additional metadata about the simulated call ( e.g. gas consumed ).

import { nativeToken, createKontorIndexerClient, http, signet } from '@kontor/kontor-sdk'
 
export const indexerClient = createKontorIndexerClient({
  chain: signet,
  transport: http(),
  account: ["bc1sender...", "xonly-pubkey"]
})
 
const simulation = await indexerClient.simulateContract({
  wit: nativeToken.wit,
  contractAddress: "token_0_0",
  functionName: "transfer",
  args: ["bc1receiver...", [100n, 0]],
  satsPerVByte: 1,
  utxos: [
     "txid:vout",
  ],
  gas: 10_000n,
  verbose: true
})