Skip to content
Developer Handbook

Dapp connection protocols

WizardConnect

On this page

WizardConnect lets a dapp exchange encrypted messages with an HD wallet through a Nostr relay. The dapp shows a wiz:// pairing link as a QR code for the wallet to scan. The hdwalletv1 session supplies xpubs scoped to named paths so the app can derive public keys locally.

Pair a wallet

Use @wizardconnect/core for the relay and @wizardconnect/dapp for the session manager. Register the wallet-ready handler before presenting the pairing URI. Keep the URI and stored relay credentials inside the pairing and reconnect flows.

import { initiateDappRelay } from '@wizardconnect/core';
import { DappConnectionManager } from '@wizardconnect/dapp';

const manager = new DappConnectionManager('BCH demo');
manager.on('walletready', (wallet) => showWallet(wallet.wallet_name));

const relay = initiateDappRelay(({ client, status }) => {
  manager.updateConnection(client, status);
});
manager.attachRelay(relay);
showPairingQr(relay.uri);

showWallet and showPairingQr are app callbacks. The manager also exposes stored session handling, and the React package provides an integration hook.

Build and sign

  1. Read the approved path names and derive only the child public keys the app needs. Common path names are receive, change and defi.
  2. Build the transaction with the full data for each UTXO it spends, including BCH value, locking bytecode, and any tokens. For each wallet-controlled input, identify its input index, path name and child address index.
  3. Send the transaction and the input paths with manager.signTransaction. For app-side broadcast, set broadcast: false and verify the returned signedTransaction before submitting it.
const result = await manager.signTransaction({
  transaction: { transaction: rawUnsignedHex, sourceOutputs, broadcast: false },
  inputPaths: [[0, 'receive', 3]],
});
if (result.error) throw new Error(result.error);

This example assumes input 0 spends the fourth child of the approved receive path. The address index comes from the wallet path used for the UTXO. Scope xpub access appropriately because an xpub reveals addresses derived beneath that path.

Reconnect, cancel and disconnect

Reconnect using the existing relay identity and session state. The SDK can re-deliver pending requests when the wallet returns, so keep one logical signing request per user action. Pass an AbortSignal to cancel stale requests. On disconnect, clear cached session paths and any app state derived from the session.

WizardConnect protocol reference · Riften Labs dapp SDK guide