Skip to content

Composing and Signing a transfer on the nativeToken contract.

with-indexer-client.ts
import { 
  createKontorWalletClient, 
  signet, 
  custom, 
  mnemonicToAccount,
  createKontorIndexerClient,
  http,
  nativeToken,
} from "@kontor/kontor-sdk";
 
const account = mnemonicToAccount("mnemomic phrase", {
    networkConfig: signet.networkConfig,
    coinType: 1, 
});
 
const indexerClient = createKontorIndexerClient({
    chain: signet,
    transport: http(),
});
 
const walletClient = createKontorWalletClient({
  account,
  chain: signet,
  transport: custom({
    request: async (args: any) => {},
  }),
});
 
const composeResponse = await indexerClient.procContract({
  account: ["taproot-address", "x-only-public-key"],
  wit: nativeToken.wit,
  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,              
  participantScripts: composeResponse.result.per_participant,  
})                                                           
 
// ... broadcast ... 
 
const destinationBalance  = await indexerClient.viewContract({
  wit: nativeToken.wit,
  contractAddress: 'token_0_0',
  functionName: "balance",
  args: ["dst-x-only-public-key"],
})