> 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 %}
