> ## Documentation Index
> Fetch the complete documentation index at: https://fhenix-ci-version-drift-check.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start: JavaScript

> Get started with @cofhe/sdk in a browser or Node.js app

Connect to an FHE-enabled contract, encrypt a value, send it onchain, and decrypt the result, all from JavaScript.

## Prerequisites

* Node.js 18+
* A deployed FHE contract on a supported network (e.g. Sepolia)
* A wallet with testnet ETH

## 1. Install

<CodeGroup>
  ```bash npm theme={null}
  npm install @cofhe/sdk@^0.7.1 viem
  ```

  ```bash pnpm theme={null}
  pnpm add @cofhe/sdk@^0.7.1 viem
  ```

  ```bash yarn theme={null}
  yarn add @cofhe/sdk@^0.7.1 viem
  ```
</CodeGroup>

## 2. Create and connect the client

Import from `@cofhe/sdk/web` for browser apps or `@cofhe/sdk/node` for Node.js scripts.

<CodeGroup>
  ```typescript Web (browser) theme={null}
  import { createCofheConfig, createCofheClient } from '@cofhe/sdk/web';
  import { chains } from '@cofhe/sdk/chains';
  import { createPublicClient, createWalletClient, http, custom } from 'viem';
  import { sepolia } from 'viem/chains';

  // 1. Configure
  const config = createCofheConfig({
    supportedChains: [chains.sepolia],
  });
  const client = createCofheClient(config);

  // 2. Create viem clients (browser wallet)
  const publicClient = createPublicClient({
    chain: sepolia,
    transport: http(),
  });
  const walletClient = createWalletClient({
    chain: sepolia,
    transport: custom(window.ethereum),
  });

  // 3. Connect
  await client.connect(publicClient, walletClient);
  ```

  ```typescript Node.js theme={null}
  import { createCofheConfig, createCofheClient } from '@cofhe/sdk/node';
  import { chains } from '@cofhe/sdk/chains';
  import { createPublicClient, createWalletClient, http } from 'viem';
  import { sepolia } from 'viem/chains';
  import { privateKeyToAccount } from 'viem/accounts';

  // 1. Configure
  const config = createCofheConfig({
    supportedChains: [chains.sepolia],
  });
  const client = createCofheClient(config);

  // 2. Create viem clients
  const account = privateKeyToAccount('0xYOUR_PRIVATE_KEY');
  const publicClient = createPublicClient({
    chain: sepolia,
    transport: http(),
  });
  const walletClient = createWalletClient({
    chain: sepolia,
    transport: http(),
    account,
  });

  // 3. Connect
  await client.connect(publicClient, walletClient);
  ```
</CodeGroup>

<Note>
  If you use Ethers.js instead of viem, see the [Client Setup](/client-sdk/guides/client-setup) guide for adapter usage.
</Note>

## 3. Encrypt and send

```typescript theme={null}
import { Encryptable } from '@cofhe/sdk';

// Encrypt a uint32 value, naming the contract that will consume it
const [valueHash, signature] = await client
  .encryptInputs([Encryptable.uint32(42n)])
  .setConsumingContract(contract.address)
  .execute();

// Pass the handle and its proof to your contract
await contract.setValue(valueHash, signature);
```

## 4. Decrypt for display

```typescript theme={null}
import { FheTypes } from '@cofhe/sdk';

// Create an ACP (one-time per account + chain)
await client.acp.getOrCreateSelfACP();

// Read the encrypted handle from your contract
const ctHash = await contract.storedValue();

// Decrypt locally
const plaintext = await client
  .decryptForView(ctHash, FheTypes.Uint32)
  .execute();

console.log(plaintext); // 42n
```

## Next steps

* [Client Setup](/client-sdk/guides/client-setup): adapters, connection management, and config options.
* [Encrypting Inputs](/client-sdk/guides/encrypting-inputs): supported types, builder API, and progress callbacks.
* [Access Control Permissions](/client-sdk/guides/acps): create, share, and manage decryption authorization.
* [Decrypt to View](/client-sdk/guides/decrypt-to-view): reveal encrypted state in your UI.
* [Decrypt to Transact](/client-sdk/guides/decrypt-to-tx): decrypt with a verifiable signature for onchain use.
