> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ckbccc.com/llms.txt - append ".md" to any page URL for its Markdown source.
> Use this file to discover all available pages before exploring further.

---
# @ckb-ccc/connector
URL: https://docs.ckbccc.com/en/docs/packages/core-packages/connector
Source: https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/dev/packages/docs/content/docs/packages/core-packages/connector.mdx
> Web Component connector for wallet connectivity — framework-agnostic.




`@ckb-ccc/connector` provides a native [Web Component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) that renders CCC's wallet-selection UI without requiring any JavaScript framework. It is the foundation that `@ckb-ccc/connector-react` is built on top of.

## When to use this package [#when-to-use-this-package]

Use `@ckb-ccc/connector` when you need wallet connectivity in a plain HTML page, vanilla JS project, or a framework that is not React. If you are building a React application, prefer [`@ckb-ccc/connector-react`](./connector-react.mdx) which wraps this package with React bindings.

## Installation [#installation]

<PackageBadges pkg="@ckb-ccc/connector" />

<Tabs items="['npm', 'yarn', 'pnpm']">
  <Tab value="npm">
    ```bash
    npm install @ckb-ccc/connector
    ```
  </Tab>

  <Tab value="yarn">
    ```bash
    yarn add @ckb-ccc/connector
    ```
  </Tab>

  <Tab value="pnpm">
    ```bash
    pnpm add @ckb-ccc/connector
    ```
  </Tab>
</Tabs>

## The `WebComponentConnector` class [#the-webcomponentconnector-class]

The central export is `ccc.WebComponentConnector` — the underlying custom element class. When you register the element and add it to the DOM, it renders the wallet picker UI.

```typescript
import { ccc } from "@ckb-ccc/connector";

// The connector element
const connector: ccc.WebComponentConnector;

connector.client;       // required borrowed ccc.Client
connector.khieRelayAddress; // optional default Relay multiaddr for Khie
connector.hideKhie; // false by default; hides the Khie connection entry
connector.wallet;       // connected ccc.Wallet | undefined
connector.signer;       // ccc.SignerInfo | undefined

connector.disconnect(); // disconnect the current wallet
connector.addEventListener("select-client", (event) => {
  connector.client = (event as ccc.SelectClientEvent).client;
});
```

The Web Component requires and only borrows its `client`; it never creates or
disposes one. Assign a client before adding the element to the document, keep
its owner alive for as long as the element may use it, and dispose the owner
from your application lifecycle. Network and fee-rate selections emit a
composed, bubbling `select-client` event; the application decides whether to
feed its candidate Client back through the `client` property.

## Select a transaction fee rate [#select-a-transaction-fee-rate]

The connected-wallet view includes a **Fee Rate** entry above **Manage**, so
applications do not need to provide a separate trigger. It opens the selector
inside the same modal and offers economy, auto, and custom
rates. Selections apply immediately; use the back button to return to the
connected-wallet view. For now, the selection is retained by the connector UI
only.

## Usage in plain HTML [#usage-in-plain-html]

```html
<!doctype html>
<html>
  <head>
    <script type="module">
      import { ccc } from "https://esm.sh/@ckb-ccc/connector";

      const connector = document.createElement("ccc-connector");
      const clientOwner = ccc.ClientPublicTestnet.open();
      connector.client = clientOwner.value;
      connector.style.cssText = "display: none; z-index: 999;";
      let connectionOwner;

      window.addEventListener(
        "pagehide",
        () => {
          void connectionOwner?.dispose();
          void clientOwner.dispose();
        },
        { once: true },
      );

      document.getElementById("open-btn").addEventListener("click", () => {
        connector.style.display = "";
      });

      connector.addEventListener("close", () => {
        connector.style.display = "none";
      });

      connector.addEventListener("select-client", (event) => {
        connector.client = event.client;
      });

      connector.addEventListener("connection", (event) => {
        event.stopPropagation();
        const owner = event.connectionOwner?.map((connection) => connection);
        const previous = connectionOwner;
        connectionOwner = owner;
        void previous?.dispose();

        if (owner) {
          owner.value.signerInfo.signer.getRecommendedAddress().then((addr) => {
            document.getElementById("address").textContent = addr;
          });
        }
      });

      // `client` must be assigned before the element is connected.
      document.body.append(connector);
    </script>
  </head>
  <body>
    <button id="open-btn">Connect Wallet</button>
    <p id="address"></p>

  </body>
</html>
```

## Usage with a bundler (vanilla JS/TS) [#usage-with-a-bundler-vanilla-jsts]

```typescript
import { ccc } from "@ckb-ccc/connector";

// The custom element is auto-registered when you import the package.
const connector = document.createElement(
  "ccc-connector",
) as ccc.WebComponentConnector;
const clientOwner = ccc.ClientPublicTestnet.open();
connector.client = clientOwner.value; // The Connector borrows it.
connector.khieRelayAddress = "/dns4/relay.example/tcp/443/wss";
connector.hideKhie = true;

// Show the wallet picker
connector.style.display = "";

// Listen for events
connector.addEventListener("close", () => {
  connector.style.display = "none";
});

// The Connector requests changes; the application controls the Client.
connector.addEventListener("select-client", (event) => {
  connector.client = (event as ccc.SelectClientEvent).client;
});

let connectionOwner: ccc.Owner<ccc.ConnectorConnection> | undefined;
connector.addEventListener("connection", (event) => {
  event.stopPropagation();
  const owner = (event as ccc.ConnectorConnectionEvent).connectionOwner?.map(
    (connection) => connection,
  );
  const previous = connectionOwner;
  connectionOwner = owner;
  void previous?.dispose();

  console.log("Connected wallet:", owner?.value.wallet.name);
  console.log("Signer:", owner?.value.signerInfo);
});

// `client` must be assigned before the element is connected.
document.body.append(connector);

// Once these resources are no longer used, the caller releases them:
// await connectionOwner?.dispose();
// await clientOwner.dispose();
```

## Styling with CSS custom properties [#styling-with-css-custom-properties]

Set CSS custom properties on `<ccc-connector>` to theme the built-in UI. The
Web Component consumes the variables listed below; the defaults shown are the
light theme supplied by `@ckb-ccc/connector-react`.

| Custom property         | React default       | Controls                                       |
| ----------------------- | ------------------- | ---------------------------------------------- |
| `--background`          | `#fff`              | Dialog and input base background               |
| `--divider`             | `#eee`              | Dividers and separators                        |
| `--btn-primary`         | `#f8f8f8`           | Primary button background                      |
| `--btn-primary-hover`   | `#efeeee`           | Primary button hover and selected background   |
| `--btn-secondary`       | `#ddd`              | Secondary pill button background               |
| `--btn-secondary-hover` | `#ccc`              | Secondary pill button hover background         |
| `--btn-color`           | `color` (`#1e1e1e`) | Button text, SVG icon, and embedded input text |
| `--btn-color-hover`     | `--btn-color`       | Button content on hover or when selected       |
| `--icon-primary`        | `#1E1E1E`           | Primary icons                                  |
| `--icon-secondary`      | `#666666`           | Secondary icons                                |
| `--tip-color`           | `#666`              | Supporting and tip text                        |
| `--tip-color-hover`     | `--tip-color`       | Interactive tip text on hover or when selected |

The connector's regular text inherits the standard CSS `color` property.
When omitted, `--btn-color` also inherits `color`, `--btn-color-hover` falls
back to `--btn-color`, and `--tip-color-hover` falls back to `--tip-color`.

```html
<ccc-connector
  style="
    color: #e6eef2;
    --background: #11181c;
    --divider: #28343a;
    --btn-primary: #171d21;
    --btn-primary-hover: #5bcefa;
    --btn-color: #e6eef2;
    --btn-color-hover: #070a0c;
    --tip-color: #76858d;
    --tip-color-hover: #31515f;
  "
></ccc-connector>
```

## Comparison with `@ckb-ccc/connector-react` [#comparison-with-ckb-cccconnector-react]

| Feature           | `@ckb-ccc/connector` | `@ckb-ccc/connector-react`   |
| ----------------- | -------------------- | ---------------------------- |
| Framework         | None (Web Component) | React                        |
| Integration style | DOM events           | `Provider` + `useCcc()` hook |
| State management  | Manual DOM listeners | React context, reactive      |
| Peer dependency   | —                    | `react >= 16`                |

<Callout type="info">
  `@ckb-ccc/connector-react` uses `@lit/react` to wrap this Web Component. All
  wallet integrations (JoyID, MetaMask, Nostr, BTC wallets, etc.) are wired
  through the same underlying connector element.
</Callout>
