Skip to content
Developer Handbook

Dapp connection protocols

CashConnect

On this page

A dapp can use CashConnect to ask a wallet to send 25 loyalty points. The app supplies a transaction template with a named action and sends the amount and recipient as parameters. The wallet resolves the template, gets user approval, executes the action, and returns its result. The current @cashconnect-js/nostr SDK carries these requests over Nostr.

Prepare the template

  1. Define the contract scripts, actions and variables with @cashconnect-js/core. The @cashconnect-js/templates-sdk package provides template development helpers.
  2. Test a single named action first. Define its required parameters and expected transaction outputs, token balance changes and return data.
  3. Review the template and the wallet’s preview using the same pinned version. A wallet approves a template and session scope before it accepts an action.

Start a session

Pass the reviewed template, app metadata, target chain and requested token allowlist to the Nostr SDK’s Dapp. After start(), call createInviteUrl() to render the invite or provide a pairing dialog to pair(). Enable wallet actions when the SDK reports sessionEstablished.

import { Dapp } from '@cashconnect-js/nostr';

const dapp = new Dapp({
  info: { name: 'BCH demo', url: location.origin },
  chain: networkId,
  template: reviewedTemplate,
  allowedTokens: requestedTokenCategories,
});

dapp.on('sessionEstablished', ({ session }) => showConnected(session));
await dapp.start();
if (!dapp.isSessionActive()) showPairingQr(dapp.createInviteUrl());

networkId, the template, token category list, and UI callbacks belong to the app. Keep them aligned with the wallet and the action under review.

Request an action

Call dapp.executeAction(actionName, params) with a name and fields defined in the approved template. Read the returned transaction results, consumed and emitted UTXOs, and reported balance changes. A connection or response alone does not establish on-chain confirmation. Look up the transaction when the app needs confirmation.

Handle cancellation, wallet rejection, and an unreachable peer. A stored session may resume when the wallet comes back online. Use forgetSession() when the user disconnects and stop() when tearing down the local client.

CashConnect protocol reference · First template tutorial · CashConnect SDK