Ckb-connect-wallet-kit is on npm: compound React wallet UI for CCC, now with did:ckb

Hi everyone,

Back in April I posted a revamp of the CKB wallet connection UI as a compound React component on top of CCC. The feedback from CKB builders was consistent: this should be installable as a package, not something you copy out of a demo.

That package is now live as ckb-connect-wallet-kit. You wrap your own ccc.Provider, compose the button / icon / balance / address yourself, and optionally show the connected lock’s did:ckb avatar, display name, and identifier. The kit never mounts CCC. Current version is 0.2.1.

Links

What it is

ckb-connect-wallet-kit is a compound React UI for [@ckb-ccc/connector-react](``https://www.npmjs.com/package/@ckb-ccc/connector-react``). Shared state (wallet, address, balance, open()) lives in React context, so there is no prop drilling. A value on a single piece overrides the matching provider default.

What you get:

  • Compose the exact connected-wallet UI you want

  • One fetch for address and balance (Promise.all)

  • Loading pulses on the button and the connected pill

  • Provider-level defaults, overridable per instance

  • Balance control: decimalPlaces (0–20) truncates, does not round; optional CKB suffix

  • Address control: keep frontChars and endChars, the middle becomes ...

  • ConnectWalletButton hides after connect; the info pieces render only then

  • Optional did:ckb profile for the connected lock

  • TypeScript types for defaults, DecimalPlaces, and DidProfile

Creating or editing a DID is a signed CKB transaction and is outside this kit. The DID pieces only read live did:ckb cells owned by the connected lock.

What it requires

Peer dependencies:

  • react and react-dom (^18.3.1)

  • @ckb-ccc/connector-react (^1.0.0)

You must mount your own ccc.Provider. ConnectWallet and ConnectWalletKitProvider both call ccc.useCcc(), so they throw if CCC is missing.

The components ship Tailwind class names, not a prebuilt stylesheet. Tailwind v4 does not scan node_modules unless you point it at the package.

Install

npm install ckb-connect-wallet-kit @ckb-ccc/connector-react react react-dom

Same packages with pnpm / yarn / bun:

pnpm add ckb-connect-wallet-kit @ckb-ccc/connector-react react react-dom
yarn add ckb-connect-wallet-kit @ckb-ccc/connector-react react react-dom
bun add ckb-connect-wallet-kit @ckb-ccc/connector-react react react-dom

Then in your CSS:

@import "tailwindcss";
@source "../node_modules/ckb-connect-wallet-kit/dist";

Adjust the @source path if your CSS file sits somewhere else relative to node_modules.

How to use it

The pieces have built-in styles. Leave off className, formatting props, and defaults to use them as-is.

1. CCC provider, no styling

Your ccc.Provider plus the kit pieces. No ConnectWalletKitProvider, no defaults, no className.

import { ccc } from "@ckb-ccc/connector-react";
import {
  ConnectWallet,
  ConnectWalletButton,
  ConnectWalletInfoContainer,
  ConnectWalletInfoImage,
  ConnectWalletInfoBalance,
  ConnectWalletInfoAddress,
} from "ckb-connect-wallet-kit";

export function App() {
  return (
    <ccc.Provider
      defaultClient={new ccc.ClientPublicTestnet()}
      clientOptions={[
        { name: "CKB Testnet", client: new ccc.ClientPublicTestnet() },
        { name: "CKB Mainnet", client: new ccc.ClientPublicMainnet() },
      ]}
    >
      <ConnectWallet>
        <ConnectWalletButton />
        <ConnectWalletInfoContainer>
          <ConnectWalletInfoImage />
          <ConnectWalletInfoBalance />
          <ConnectWalletInfoAddress />
        </ConnectWalletInfoContainer>
      </ConnectWallet>
    </ccc.Provider>
  );
}

The button uses the built-in pill. After connect it hides, and the container shows the icon, the full formatted balance with CKB, and an address truncated to 10 + 6 characters.

2. Kit provider, no defaults

Same CCC tree. ConnectWalletKitProvider only opens the defaults context. Omit defaults so every composition uses the built-in look. Style or format a single piece with props when you need to.

import { ccc } from "@ckb-ccc/connector-react";
import {
  ConnectWalletKitProvider,
  ConnectWallet,
  ConnectWalletButton,
  ConnectWalletInfoContainer,
  ConnectWalletInfoImage,
  ConnectWalletInfoBalance,
  ConnectWalletInfoAddress,
} from "ckb-connect-wallet-kit";

export function App() {
  return (
    <ccc.Provider
      defaultClient={new ccc.ClientPublicTestnet()}
      clientOptions={[
        { name: "CKB Testnet", client: new ccc.ClientPublicTestnet() },
        { name: "CKB Mainnet", client: new ccc.ClientPublicMainnet() },
      ]}
    >
      <ConnectWalletKitProvider>
        <ConnectWallet>
          <ConnectWalletButton>Connect</ConnectWalletButton>
          <ConnectWalletInfoContainer>
            <ConnectWalletInfoImage />
            <ConnectWalletInfoBalance decimalPlaces={4} withCurrency />
            <ConnectWalletInfoAddress frontChars={6} endChars={4} />
          </ConnectWalletInfoContainer>
        </ConnectWallet>
      </ConnectWalletKitProvider>
    </ccc.Provider>
  );
}

3. Kit provider, with defaults

Set look and formatting once. A prop on one piece still wins over the matching default.

import { ccc } from "@ckb-ccc/connector-react";
import {
  ConnectWalletKitProvider,
  ConnectWallet,
  ConnectWalletButton,
  ConnectWalletInfoContainer,
  ConnectWalletInfoImage,
  ConnectWalletInfoBalance,
  ConnectWalletInfoAddress,
} from "ckb-connect-wallet-kit";

export function App() {
  return (
    <ccc.Provider
      defaultClient={new ccc.ClientPublicTestnet()}
      clientOptions={[
        { name: "CKB Testnet", client: new ccc.ClientPublicTestnet() },
        { name: "CKB Mainnet", client: new ccc.ClientPublicMainnet() },
      ]}
    >
      <ConnectWalletKitProvider
        defaults={{
          buttonClassName: "rounded-md bg-blue-600 text-white dark:bg-blue-600 dark:text-white",
          infoContainerClassName: "rounded-md bg-blue-600 text-white dark:bg-blue-600 dark:text-white",
          decimalPlaces: 4,
          withCurrency: true,
          frontChars: 6,
          endChars: 4,
          buttonLabel: "Connect Wallet",
        }}
      >
        <ConnectWallet>
          <ConnectWalletButton />
          <ConnectWalletInfoContainer className="flex items-center gap-2">
            <ConnectWalletInfoImage />
            <div className="flex flex-col items-start">
              <ConnectWalletInfoBalance />
              <ConnectWalletInfoAddress />
            </div>
          </ConnectWalletInfoContainer>
        </ConnectWallet>
      </ConnectWalletKitProvider>
    </ccc.Provider>
  );
}

className is merged after the provider class, so conflicting Tailwind utilities on that instance win.

LayoutProvider is the previous name of ConnectWalletKitProvider. Same props. It does not mount CCC.

How class names and defaults resolve

For appearance classes:

  1. Built-in styles (used when that default is omitted)

  2. defaults.*ClassName from ConnectWalletKitProvider

  3. className on the component (merged last)

For values (decimalPlaces, withCurrency, frontChars, endChars, didFrontChars, didEndChars, button label):

  1. Built-in fallback

  2. defaults.* from the provider

  3. The prop on the component (wins)

ClassValue is the clsx input type: a string, array, or conditional object of class names.

Components and props

ConnectWalletKitProvider

Sit this under the app’s ccc.Provider. It only stores shared defaults. It calls ccc.useCcc(), so it throws if CCC is missing. It never mounts ccc.Provider.

  • children (React.ReactNode) β€” The rest of the app.

  • defaults (ConnectWalletDefaults, default {}) β€” Shared look and formatting for every composition under the provider.

defaults

  • buttonClassName (ClassValue, default rounded-full bg-black text-white hover:opacity-90 dark:bg-white dark:text-black text-sm font-bold sm:text-base px-5 py-3) β€” Replaces the built-in colors, radius, and padding on ConnectWalletButton. Include dark: utilities if the button should keep that color in dark mode.

  • infoContainerClassName (ClassValue, same built-in appearance as the button) β€” Same role for the connected wallet pill (ConnectWalletInfoContainer).

  • imageClassName (ClassValue, default w-6 h-6) β€” Replaces the default size of the wallet icon.

  • balanceClassName (ClassValue, default font-semibold text-sm) β€” Replaces the default balance typography.

  • addressClassName (ClassValue, default text-xs font-normal) β€” Replaces the default address typography.

  • decimalPlaces (0–20 / DecimalPlaces, unset by default so up to 10 fraction digits show) β€” Shared balance precision. Digits are truncated, not rounded. 0 is a valid value.

  • withCurrency (boolean, default true) β€” When true, appends a CKB suffix after the balance.

  • frontChars (number, default 10) β€” Characters kept at the start of the truncated address.

  • endChars (number, default 6) β€” Characters kept at the end of the truncated address.

  • buttonLabel (React.ReactNode, default "Connect Wallet") β€” Label of ConnectWalletButton. A children prop on that button still wins.

  • didAvatarClassName (ClassValue, default w-6 h-6 rounded-full object-cover) β€” Replaces the default size and shape of ConnectWalletDidAvatar.

  • didNameClassName (ClassValue, default font-semibold text-sm) β€” Replaces the default typography of ConnectWalletDidName.

  • didIdClassName (ClassValue, default text-xs font-normal) β€” Replaces the default typography of ConnectWalletDidId.

  • didFrontChars (number, default 14) β€” Characters kept at the start of the truncated did:ckb: string.

  • didEndChars (number, default 6) β€” Characters kept at the end of the truncated did:ckb: string.

LayoutProvider

Same component as ConnectWalletKitProvider. Same props. Must sit under the app’s ccc.Provider.

  • children (React.ReactNode) β€” The rest of the app.

  • defaults (ConnectWalletDefaults, default {}) β€” Same as ConnectWalletKitProvider.

ConnectWallet

Local provider for one composition. It reads the CCC signer once and shares balance, address, loading, wallet, and open() with its children. Must sit under the app’s ccc.Provider.

  • children (React.ReactNode) β€” The button, the connected info, and any layout you put between them.

ConnectWalletButton

Renders only while no wallet is connected. Clicking it calls CCC open(). Hidden after connect.

  • className (ClassValue) β€” Merged after defaults.buttonClassName, so it overrides conflicting utilities on this button only.

  • children (React.ReactNode, default defaults.buttonLabel, then "Connect Wallet") β€” Replaces the button label.

ConnectWalletInfoContainer

Renders only after a wallet is connected. The whole pill calls open() again, which is how CCC shows account actions.

  • children (React.ReactNode) β€” Your layout for the icon, balance, and address.

  • className (ClassValue) β€” Merged after defaults.infoContainerClassName.

ConnectWalletInfoImage

The wallet icon from wallet.icon. Renders nothing until a wallet is connected.

  • className (ClassValue) β€” Merged after defaults.imageClassName. Built-in size is w-6 h-6.

ConnectWalletInfoBalance

Formats the signer balance with Intl.NumberFormat. When decimalPlaces is set (on the component or via defaults), extra digits are truncated, not rounded. Renders nothing until a wallet is connected.

  • decimalPlaces (0–20, default defaults.decimalPlaces, then up to 10 fraction digits) β€” Overrides the provider precision for this instance.

  • withCurrency (boolean, default defaults.withCurrency, then true) β€” When true, appends CKB after the number.

  • className (ClassValue) β€” Merged after defaults.balanceClassName.

ConnectWalletInfoAddress

Shows the recommended address. If the address is longer than frontChars + endChars, the middle is replaced with .... Renders nothing until a wallet is connected.

  • frontChars (number, default defaults.frontChars, then 10) β€” Characters kept at the start.

  • endChars (number, default defaults.endChars, then 6) β€” Characters kept at the end.

  • className (ClassValue) β€” Merged after defaults.addressClassName.

did:ckb

Optional. Place ConnectWalletDid inside ConnectWallet. It lists the live did:ckb cells owned by the connected lock and shares the newest one with its children. Nothing is fetched unless you render it, and it renders nothing before a wallet connects.

The display name and avatar come from services.profile in the DID document (displayName, avatar, bio), the convention used by did:ckb dashboards. A DID without a profile still has an identifier.

<ConnectWallet>
  <ConnectWalletButton />
  <ConnectWalletInfoContainer className="flex items-center gap-2">
    <ConnectWalletDid>
      <ConnectWalletDidAvatar fallback={<ConnectWalletInfoImage />} />
      <div className="flex flex-col items-start">
        <ConnectWalletDidName fallback={<ConnectWalletInfoAddress frontChars={6} endChars={4} />} />
        <ConnectWalletDidId />
      </div>
    </ConnectWalletDid>
  </ConnectWalletInfoContainer>
</ConnectWallet>

ConnectWalletDid

  • children (React.ReactNode) β€” The DID pieces, or anything that calls useConnectWalletDid().

  • resolve (DidResolver, default lists live did:ckb cells locked by the wallet) β€” Replace the lookup. Receives { client, signer, lock, address } and returns DidProfile[].

  • script (DidScript, default mainnet or testnet by client prefix) β€” Code hash and hash type of a custom did:ckb deployment. CCC’s KnownScript.DidCkb is used when the installed CCC has it.

  • pick ((dids: DidProfile[]) => DidProfile | undefined, default newest cell) β€” Choose which DID to show when the lock owns several.

useConnectWalletDid() returns { dids, did, isLoading, error, select } for a custom display. listDidsByLock, decodeDidCell, extractDidProfile, argsToDid, and DID_CKB_SCRIPTS are exported for use outside React.

ConnectWalletDidAvatar

The avatar from services.profile.avatar. Renders nothing while the lookup runs, and the fallback when the DID has no avatar.

  • className (ClassValue) β€” Merged after defaults.didAvatarClassName. Built-in is w-6 h-6 rounded-full object-cover.

  • fallback (React.ReactNode, default null) β€” Rendered when there is no avatar.

ConnectWalletDidName

The display name from services.profile.displayName. Renders the fallback when the DID has no name.

  • className (ClassValue) β€” Merged after defaults.didNameClassName. Built-in is font-semibold text-sm.

  • fallback (React.ReactNode, default null) β€” Rendered when there is no display name.

ConnectWalletDidId

The did:ckb: identifier, shortened with .... The full value is in the title attribute.

  • frontChars (number, default defaults.didFrontChars, then 14) β€” Characters kept at the start.

  • endChars (number, default defaults.didEndChars, then 6) β€” Characters kept at the end.

  • className (ClassValue) β€” Merged after defaults.didIdClassName.

  • fallback (React.ReactNode, default null) β€” Rendered when the lock owns no DID.

Prefer to copy the source

If you would rather vendor the files than depend on the package, copy these into the same folder in your app:

  • src/connect-wallet.tsx

  • src/utils.ts

  • src/connect-wallet-kit-provider.tsx

  • src/did-ckb.ts and src/connect-wallet-did.tsx (only if you want the DID pieces)

They have to stay together. Mount your own ccc.Provider around the kit provider. Then:

npm install @ckb-ccc/connector-react clsx tailwind-merge react react-dom

Tailwind already scans your project source on this path, so you do not add an @source rule.

Try it

The live demo at ckb-connect-wallet-kit.vercel.app has the same three usage examples, the did:ckb composition, and a components page that lists every prop.

I would like feedback from CKB app developers who are already on CCC, especially on:

  • Whether the CCC-first provider split matches how you already wrap apps

  • How the did:ckb pieces should behave when a lock owns several DIDs

  • Any missing pieces you still end up writing by hand

MIT licensed. Issues and PRs welcome on the repo.

Best,
Victor Okenwa

2 Likes