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
-
Homepage / demo: https://ckb-connect-wallet-kit.vercel.app/
-
My GitHub: Victor-Okenwa (Okenwa victor) Β· GitHub
-
Earlier thread: Revamping and Refactoring the CKB Wallet Connection Experience: A Modular Compound Component for React Developers
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; optionalCKBsuffix -
Address control: keep
frontCharsandendChars, the middle becomes... -
ConnectWalletButtonhides after connect; the info pieces render only then -
Optional did:ckb profile for the connected lock
-
TypeScript types for defaults,
DecimalPlaces, andDidProfile
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:
-
reactandreact-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:
-
Built-in styles (used when that default is omitted)
-
defaults.*ClassNamefromConnectWalletKitProvider -
classNameon the component (merged last)
For values (decimalPlaces, withCurrency, frontChars, endChars, didFrontChars, didEndChars, button label):
-
Built-in fallback
-
defaults.*from the provider -
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, defaultrounded-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 onConnectWalletButton. Includedark: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, defaultw-6 h-6) β Replaces the default size of the wallet icon. -
balanceClassName(ClassValue, defaultfont-semibold text-sm) β Replaces the default balance typography. -
addressClassName(ClassValue, defaulttext-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.0is a valid value. -
withCurrency(boolean, defaulttrue) β Whentrue, appends aCKBsuffix after the balance. -
frontChars(number, default10) β Characters kept at the start of the truncated address. -
endChars(number, default6) β Characters kept at the end of the truncated address. -
buttonLabel(React.ReactNode, default"Connect Wallet") β Label ofConnectWalletButton. Achildrenprop on that button still wins. -
didAvatarClassName(ClassValue, defaultw-6 h-6 rounded-full object-cover) β Replaces the default size and shape ofConnectWalletDidAvatar. -
didNameClassName(ClassValue, defaultfont-semibold text-sm) β Replaces the default typography ofConnectWalletDidName. -
didIdClassName(ClassValue, defaulttext-xs font-normal) β Replaces the default typography ofConnectWalletDidId. -
didFrontChars(number, default14) β Characters kept at the start of the truncateddid:ckb:string. -
didEndChars(number, default6) β Characters kept at the end of the truncateddid: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 asConnectWalletKitProvider.
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 afterdefaults.buttonClassName, so it overrides conflicting utilities on this button only. -
children(React.ReactNode, defaultdefaults.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 afterdefaults.infoContainerClassName.
ConnectWalletInfoImage
The wallet icon from wallet.icon. Renders nothing until a wallet is connected.
className(ClassValue) β Merged afterdefaults.imageClassName. Built-in size isw-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, defaultdefaults.decimalPlaces, then up to 10 fraction digits) β Overrides the provider precision for this instance. -
withCurrency(boolean, defaultdefaults.withCurrency, thentrue) β Whentrue, appendsCKBafter the number. -
className(ClassValue) β Merged afterdefaults.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, defaultdefaults.frontChars, then10) β Characters kept at the start. -
endChars(number, defaultdefaults.endChars, then6) β Characters kept at the end. -
className(ClassValue) β Merged afterdefaults.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 callsuseConnectWalletDid(). -
resolve(DidResolver, default lists live did:ckb cells locked by the wallet) β Replace the lookup. Receives{ client, signer, lock, address }and returnsDidProfile[]. -
script(DidScript, default mainnet or testnet by client prefix) β Code hash and hash type of a custom did:ckb deployment. CCCβsKnownScript.DidCkbis 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 afterdefaults.didAvatarClassName. Built-in isw-6 h-6 rounded-full object-cover. -
fallback(React.ReactNode, defaultnull) β 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 afterdefaults.didNameClassName. Built-in isfont-semibold text-sm. -
fallback(React.ReactNode, defaultnull) β Rendered when there is no display name.
ConnectWalletDidId
The did:ckb: identifier, shortened with .... The full value is in the title attribute.
-
frontChars(number, defaultdefaults.didFrontChars, then14) β Characters kept at the start. -
endChars(number, defaultdefaults.didEndChars, then6) β Characters kept at the end. -
className(ClassValue) β Merged afterdefaults.didIdClassName. -
fallback(React.ReactNode, defaultnull) β 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.tsandsrc/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