Skip to main content
Check out the official Kontor TypeScript SDK documentation here.

Usage

[with-indexer-client.ts]
import { 
  signet, 
  custom, 
  http,
  parseWit,
  mnemonicToAccount,
  createKontorWalletClient, 
  createKontorIndexerClient
} from "@kontor/kontor-sdk";

const contract = [
  "record balance { acc: string, amt: decimal }",
  "record transfer { src: string, dst: string, amt: decimal }",
  "record burn { src: string, amt: decimal }",
  "record mint { dst: string, amt: decimal }",
  "export mint: func(ctx: borrow<proc-context>, amt: decimal) -> result<mint, error>;",
  "export burn: func(ctx: borrow<proc-context>, amt: decimal) -> result<burn, error>;",
  "export transfer: func(ctx: borrow<proc-context>, dst: string, amt: decimal) -> result<transfer, error>;",
  "export balance: func(ctx: borrow<view-context>, acc: string) -> option<decimal>;",
  "export balances: func(ctx: borrow<view-context>) -> list<balance>;",
  "export total-supply: func(ctx: borrow<view-context>) -> decimal;",
  "export attach: func(ctx: borrow<proc-context>, vout: u64, amt: decimal) -> result<transfer, error>;",
  "export detach: func(ctx: borrow<proc-context>) -> result<transfer, error>;",
] as const;

const wit = parseWit(contract);

const account = mnemonicToAccount("mnemomic phrase");

const indexerClient = createKontorIndexerClient({
    chain: signet,
    transport: http(),
});

const walletClient = createKontorWalletClient({
  account,
  chain: signet,
  transport: custom({
    request: async (args: any) => {},
  }),
});

const composeResponse = await indexerClient.procContract({
  wit,
  account: ["taproot-address", "x-only-public-key"],
  contractAddress: 'token_0_0',
  functionName: "transfer",
  args: ["dst-taproot-address", [1n, 18]],
  satsPerVByte: 1,
  utxos: [
     "txid:vout",
  ],
  gas: 10n,
})

const signedCommitHex = await walletClient.signCommit({      
  psbt: composeResponse.result.commit_psbt_hex,              
})                                                           

const signedRevealHex = await walletClient.signReveal({      
  psbt: composeResponse.result.reveal_psbt_hex,              
  parcipantScripts: composeResponse.result.per_participant,  
})                                                           

// ... broadcast ... 

const destinationBalance  = await indexerClient.viewContract({
  wit,
  contractAddress: 'token_0_0',
  functionName: "balance",
  args: ["dst-x-only-public-key"],
})