Skip to content

ConnectWallet

A pre-built wallet connection button that handles the full connect/disconnect flow for KasWare and Kastle browser wallets. Drop it into your app and customize through props and slots.

Web only

ConnectWallet relies on browser extension APIs (window.kasware / window.kastle) and is only supported in web browsers. Mobile apps are not supported.

Import

ts
import { ConnectWallet } from 'vue-kaspa'

Basic usage

vue
<script setup lang="ts">
import { ConnectWallet } from 'vue-kaspa'
</script>

<template>
  <ConnectWallet />
</template>

This renders a "Connect Wallet" button. Clicking it opens a wallet selection menu. Once connected, it shows the truncated address and a dropdown with disconnect.

Props

PropTypeDefaultDescription
walletsWalletProvider[]['kasware', 'kastle']Which wallet providers to offer
networkstring'mainnet'Target network passed to Kastle on connect. Ignored for KasWare.
labelstring'Connect Wallet'Button text when disconnected
showBalancebooleanfalseShow KAS balance in the connected dropdown (KasWare only)
showNetworkbooleantrueShow a network badge next to the connected address
truncatenumber6Address characters to show at each end

Events

EventPayloadDescription
connected{ provider, address, publicKey }Fires when a wallet connects successfully
disconnectedFires when the wallet disconnects
errorErrorFires when a connection attempt fails
vue
<ConnectWallet
  @connected="({ address }) => console.log('Connected:', address)"
  @disconnected="console.log('Disconnected')"
  @error="(err) => console.error(err)"
/>

Slots

trigger

Replaces the default "Connect Wallet" button. Receives open (boolean) and toggle (function) as slot props.

vue
<ConnectWallet>
  <template #trigger="{ open, toggle }">
    <button class="my-btn" @click="toggle">
      {{ open ? 'Cancel' : 'Connect' }}
    </button>
  </template>
</ConnectWallet>

icon-kasware / icon-kastle

Replace the wallet logo shown in the selection menu. By default the component ships with the official KasWare and Kastle logos bundled — no additional setup needed.

vue
<ConnectWallet>
  <template #icon-kasware>
    <img src="/my-kasware-logo.png" alt="KasWare" width="28" height="28" />
  </template>
  <template #icon-kastle>
    <img src="/my-kastle-logo.png" alt="Kastle" width="28" height="28" />
  </template>
</ConnectWallet>

connected

Replaces the entire connected state display. Receives the full wallet context as slot props.

vue
<ConnectWallet>
  <template #connected="{ address, network, balance, truncatedAddress, disconnect }">
    <div class="my-wallet-indicator">
      <span>{{ truncatedAddress }}</span>
      <span>{{ network }}</span>
      <button @click="disconnect">Sign out</button>
    </div>
  </template>
</ConnectWallet>

Slot props for connected:

PropTypeDescription
providerWalletProvider | nullActive wallet provider
addressstring | nullFull connected address
publicKeystring | nullConnected public key
balanceWalletBalance | nullBalance in sompi (KasWare only)
networkstring | nullActive network
truncatedAddressstringPre-truncated address string
disconnect() => voidCall to disconnect

Customization examples

Only KasWare

vue
<ConnectWallet :wallets="['kasware']" />

Only Kastle on testnet

vue
<ConnectWallet :wallets="['kastle']" network="testnet-10" />

Show balance

vue
<ConnectWallet :show-balance="true" />

Custom label and longer address

vue
<ConnectWallet label="Connect your wallet" :truncate="10" />

Listening to events

vue
<script setup lang="ts">
import { ConnectWallet } from 'vue-kaspa'
import type { WalletProvider } from 'vue-kaspa'

function onConnected(payload: { provider: WalletProvider; address: string; publicKey: string }) {
  console.log(`${payload.provider} connected: ${payload.address}`)
}
</script>

<template>
  <ConnectWallet @connected="onConnected" />
</template>

Theming

ConnectWallet reads from the same --ks-* CSS variables used by the CLI templates. Define them on your root element to control colors:

css
:root {
  --ks-surface:  #ffffff;
  --ks-soft:     #f4f4f5;
  --ks-border:   #e4e4e7;
  --ks-heading:  #18181b;
  --ks-text:     #3f3f46;
  --ks-muted:    #a1a1aa;
  --ks-accent:   #49c5a3;
}

.dark {
  --ks-surface:  #09090b;
  --ks-soft:     #18181b;
  --ks-border:   #27272a;
  --ks-heading:  #fafafa;
  --ks-text:     #a1a1aa;
  --ks-muted:    #52525b;
}

If you haven't set these variables, the component falls back to hardcoded light-mode values.

Using useWallet alongside

ConnectWallet is built on top of useWallet(). Since both share module-level state, you can read wallet state anywhere in your app without prop-drilling:

vue
<script setup lang="ts">
import { ConnectWallet, useWallet } from 'vue-kaspa'

const wallet = useWallet()
</script>

<template>
  <!-- Put the button in your header -->
  <ConnectWallet />

  <!-- Read the state anywhere -->
  <p v-if="wallet.isConnected.value">
    Sending from {{ wallet.address.value }}
  </p>
</template>

Released under the MIT License.