Skip to main content
All SDK operations return values directly and throw typed CofheError objects on failure. This replaces the Result wrapper pattern used by cofhejs.

Catching errors

import { isCofheError, CofheErrorCode, Encryptable } from '@cofhe/sdk';

try {
  const [encrypted] = await client
    .encryptInputs([Encryptable.uint32(42n)])
    .execute();
} catch (err) {
  if (isCofheError(err)) {
    console.error(err.code);    // CofheErrorCode enum value
    console.error(err.message); // human-readable description
  }
}

CofheError structure

Every CofheError has:
  • code — a CofheErrorCode enum value identifying the error type
  • message — a human-readable description of what went wrong
Use isCofheError(err) to check if a caught error is a CofheError.

Common error codes

Error codeWhen it occurs
ZkPackFailedencryptInputs exceeded the 2048-bit plaintext limit
PermitNotFoundNo permit found for the given chainId + account
PermitInvalidThe permit signature is invalid or expired
DecryptFailedDecryption request was rejected by the Threshold Network
NotConnectedAttempted an operation before calling client.connect(...)

Error handling patterns

Encryption errors

import { isCofheError, CofheErrorCode, Encryptable } from '@cofhe/sdk';

try {
  const encrypted = await client
    .encryptInputs([Encryptable.uint128(veryLargeValue)])
    .execute();
} catch (err) {
  if (isCofheError(err) && err.code === CofheErrorCode.ZkPackFailed) {
    console.error('Input too large — split into multiple calls');
  }
}

Decryption errors

import { isCofheError, CofheErrorCode, FheTypes } from '@cofhe/sdk';

try {
  const plaintext = await client
    .decryptForView(ctHash, FheTypes.Uint32)
    .execute();
} catch (err) {
  if (isCofheError(err) && err.code === CofheErrorCode.PermitNotFound) {
    // Create a permit and retry
    await client.permits.getOrCreateSelfPermit();
    const plaintext = await client
      .decryptForView(ctHash, FheTypes.Uint32)
      .execute();
  }
}