Kastle
  • Kastle Wallet Documentation
    • Architecture
    • Kastle Wallet Derivation Path
    • How to Integrate
      • Kastle Wallet API
      • Kastle SDK
    • EVM compatible
    • Bug Report
  • 🔗Contact Us
    • Website
    • Email
    • Telegram
    • X
    • Medium
Powered by GitBook
On this page
  • Detect Kastle
  • Interact with Kastle
  1. Kastle Wallet Documentation
  2. How to Integrate

Kastle Wallet API

To integrate your dApp with Kastle Wallet by Kastle Wallet API, 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.

This API is subject to changes. Please refer to this code for the most up to date version.

Detect Kastle

Check whether the Kastle extension is installed:

if (window.kastle) {
  console.log('Kastle Wallet detected!');
} else {
  alert('Please install Kastle Wallet.');
}

Interact with Kastle

const network = "mainnet"
const kaspaWasm = initKaspaWasm() // your initialize function for Kaspa Wasm file

const rpc = new kaspaWasm.RpcClient({
    url: "wss://ws.kaspa.forbole.com/borsh",
    networkId: network,
});

await rpc.connect()

// Connect wallet and get address
const isSuccess = await kastle.connect(network)
const { address, publicKey } = await kastle.getAccount();

// Build send transaction
const { entries } = await rpc.getUtxosByAddresses([address]);
const pending = await kaspaWasm.createTransactions({
  entries,
  outputs: [
    {
      address: "kaspa:123...sac",
      amount: kaspaWasm.kaspaToSompi("1"),
    },
  ],
  priorityFee: kaspaWasm.kaspaToSompi("0.01"),
  changeAddress: address,
  networkId: network,
});
const transaction = pending.transactions[0];
const txJson = transaction.serializeToSafeJSON();

const txId = await kastle.signAndBroadcastTx(network, txJson);

await rpc.disconnect()

For more code examples check here: https://github.com/forbole/kastle/blob/main/docs/index.js

PreviousHow to IntegrateNextKastle SDK

Last updated 1 month ago