Kastle SDK

To integrate with your dapp with Kastle Wallet by Kastle SDK, follow the steps below. These step-by-step instructions, along with code snippets, will guide you through connecting the wallet and interact with the wallet.

Install Kastle SDK

npm i @forbole/kastle-sdk

Detect Kastle

Check whether Kastle is installed or not

import * as sdk from "@forbole/kastle-sdk";

const isInstalled = await sdk.isWalletInstalled();

Interact with Kastle

import * as sdk from "@forbole/kastle-sdk";

await sdk.switchNetwork("testnet-10");
const connected = await sdk.connect();
const txId = await sdk.sendKaspa("<receipt-address>", sdk.kaspaWasm.kaspaToSompi("1")!);

Operate commit reveal script

import * as sdk from "@forbole/kastle-sdk";

// KRC20 transfer
const publicKey = await sdk.getPublicKey();
const protocol = "kasplex";
const action = `{"p":"krc-20","op":"transfer","tick":"kasp","amt":"100000000","to":<reciept-address>"}`;
const script = sdk.buildRevealCommitScript(publicKey, protocol, action);
const { commitTxId, revealTxId, error } = await sdk.doCommitReveal(
  script, {
    revealPriorityFee: sdk.kaspaWasm.kaspaToSompi("1")
});

Sign PSKT

import * as sdk from "@forbole/kastle-sdk";

// prepare KRC20 send
const publicKey = await sdk.getPublicKey();
const script = sdk.buildRevealCommitScript(publicKey, "<protocol>", "<action>");
const scriptUtxo = await sdk.getCommitScriptUtxo(script, commitTxId);
const preparedTx = sdk.buildTransaction([scriptUtxo], [yourOutput1]);
const signedTx = await sdk.signPskt(preparedTx, [{
  inputIndex: 0,
  script,
  signType: sdk.SignType.SingleAnyOneCanPay,
}]);

Send PSKT

import * as sdk from "@forbole/kastle-sdk";

const pskt = "<transaction-in-json>"
const txId = await sdk.sendTransactionWithExtraOutputs(pskt, [yourOutput1, yourOutput2], sdk.kaspaWasm.kaspaToSompi("0.1")!);

Last updated