Skip to content

KontorProtocol/Kontor-SDK

Repository files navigation

Kontor-SDK

Overview

import { 
  createKontorIndexerClient,
  createKontorWalletClient, 
  signet, 
  custom, 
  mnemonicToAccount,
  http,
  parseWit
} 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", {
    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({
  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,              
  participantScripts: composeResponse.result.per_participant,  
})                                                           

// ... broadcast ... 

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

Documentation

Check out the documentation here.

Misc

This SDK is inspired by the inimitable viem and abitype libraries.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors