> For the complete documentation index, see [llms.txt](https://docs.kastle.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kastle.cc/readme/how-to-integrate/kastle-sdk.md).

# 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

```bash
npm i @forbole/kastle-sdk
```

### Detect Kastle

Check whether Kastle is installed or not

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

const isInstalled = await sdk.isWalletInstalled();
```

## Interact with Kastle

```typescript
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

```typescript
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

```typescript
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

<pre class="language-typescript"><code class="lang-typescript">import * as sdk from "@forbole/kastle-sdk";

<strong>const pskt = "&#x3C;transaction-in-json>"
</strong>const txId = await sdk.sendTransactionWithExtraOutputs(pskt, [yourOutput1, yourOutput2], sdk.kaspaWasm.kaspaToSompi("0.1")!);
</code></pre>

{% hint style="info" %}
For more code examples check here: <https://github.com/forbole/kastle-sdk/tree/main/examples/react-playground/src>
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kastle.cc/readme/how-to-integrate/kastle-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
