



`@ckb-ccc/okx` integrates OKX Wallet into CCC, providing `Signer` implementations for Bitcoin and Nostr protocols. It communicates with the wallet via the browser-injected `window.okxwallet` object and reuses protocol implementations from `@ckb-ccc/uni-sat` and `@ckb-ccc/nip07` rather than reimplementing them from scratch.

<Callout type="info">
  If you're using `@ckb-ccc/connector-react` or `@ckb-ccc/ccc`, OKX is already included — no separate installation needed.
</Callout>

## Installation [#installation]

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

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

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

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

**Dependencies:**

| Package            | Description                                              |
| ------------------ | -------------------------------------------------------- |
| `@ckb-ccc/core`    | Base types — `Signer`, `Client`, `Transaction`, and more |
| `@ckb-ccc/nip07`   | NIP-07 protocol support — Nostr signer implementation    |
| `@ckb-ccc/uni-sat` | UniSat protocol support — Bitcoin provider interface     |

## Architecture [#architecture]

`@ckb-ccc/okx` composes existing single-protocol packages rather than reimplementing them:

<Mermaid
  chart="graph TB
    subgraph &#x22;OKX Package&#x22;
        OKX[&#x22;@ckb-ccc/okx&#x22;]
    end

    subgraph &#x22;Protocol Dependencies&#x22;
        UniSat[&#x22;@ckb-ccc/uni-sat&#x22;]
        NIP07[&#x22;@ckb-ccc/nip07&#x22;]
        Core[&#x22;@ckb-ccc/core&#x22;]
    end

    subgraph &#x22;Signer Classes&#x22;
        BitcoinSigner[&#x22;BitcoinSigner&#x22;]
        NostrSigner[&#x22;NostrSigner&#x22;]
    end

    OKX -.->|&#x22;uses&#x22;| UniSat
    OKX -.->|&#x22;uses&#x22;| NIP07

    BitcoinSigner --> UniSat
    NostrSigner --> NIP07
    UniSat --> Core
    NIP07 --> Core"
/>

### Entry point: `getOKXSigners` [#entry-point-getokxsigners]

`getOKXSigners(client)` is the main entry point. It checks for `window.okxwallet` and returns a `SignerInfo[]` array — empty if the wallet isn't available:

<Mermaid
  chart="graph TD
    Start[&#x22;getOKXSigners(client)&#x22;] --> Check[&#x22;window.okxwallet exists?&#x22;]
    Check -->|No| Empty[&#x22;return []&#x22;]
    Check -->|Yes| Create[&#x22;Create SignerInfo array&#x22;]

    Create --> BTC[&#x22;new BitcoinSigner(client, window.okxwallet)&#x22;]
    Create --> Nostr[&#x22;new NostrSigner(client, window.okxwallet.nostr)&#x22;]

    BTC --> Array[&#x22;SignerInfo[]&#x22;]
    Nostr --> Array"
/>

## Bitcoin protocol [#bitcoin-protocol]

`BitcoinSigner` extends `ccc.SignerBtc` and adapts the UniSat provider interface for OKX.

### Network support [#network-support]

| Network key | Chain     | Network type | Provider access          |
| ----------- | --------- | ------------ | ------------------------ |
| `btc`       | `bitcoin` | Mainnet      | `this.providers.bitcoin` |

<Callout type="warning">
  OKX only supports Bitcoin mainnet. While the code includes mappings for `btcTestnet` and `btcSignet`, OKX no longer provides providers for these networks, so they are not actually available. See [the announcement](https://www.okx.com/help/okx-wallet-to-cease-support-for-the-btc-testnet) for details.
</Callout>

### Account and public key retrieval [#account-and-public-key-retrieval]

`BitcoinSigner` supports two methods to accommodate different OKX provider versions:

* **`getAccounts()`** — returns an array of addresses.
* **`getSelectedAccount()`** — returns the currently selected account.

## Nostr protocol [#nostr-protocol]

`NostrSigner` wraps the provider interfaces from `@ckb-ccc/nip07` with two additions:

* **Public key caching** — `publicKeyCache` avoids redundant RPC calls.
* **Event signing** — delegates to `this.provider.signEvent` after ensuring the public key is attached.

## Account change detection [#account-change-detection]

Both `BitcoinSigner` and `NostrSigner` implement `onReplaced()` to keep connection state in sync when the user switches accounts in the wallet UI:

<Mermaid
  chart="sequenceDiagram
    participant App as Application
    participant Signer as Protocol Signer
    participant Provider as OKX Provider

    App->>Signer: onReplaced(listener)
    Signer->>Provider: on(&#x22;accountChanged&#x22;, replacer)

    Note over Provider: User switches account

    Provider->>Signer: emit(&#x22;accountChanged&#x22;)
    Signer->>App: listener()
    Signer->>Provider: removeListener(&#x22;accountChanged&#x22;)"
/>

`onReplaced()` registers a listener for `"accountChanged"`, invokes the application callback when triggered, and returns a cleanup function that removes the listener.

## Integration pattern [#integration-pattern]

`@ckb-ccc/okx` follows the same integration contract as every other wallet package in CCC:

* **Factory function** — `getOKXSigners` returns a `SignerInfo[]` array.
* **Provider detection** — checks for `window.okxwallet` before creating any signers.
* **Graceful degradation** — returns an empty array when the wallet is unavailable or incompatible.

This means `SignersController` can treat OKX exactly like any other signer source, with no special-casing required in application code.


---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ckbccc.com/llms.txt
> Use this file to discover all available pages before exploring further.
