Documentation Index
Fetch the complete documentation index at: https://cofhe-docs.fhenix.zone/llms.txt
Use this file to discover all available pages before exploring further.
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 code | When it occurs |
|---|
ZkPackFailed | encryptInputs exceeded the 2048-bit plaintext limit |
PermitNotFound | No permit found for the given chainId + account |
PermitInvalid | The permit signature is invalid or expired |
DecryptFailed | Decryption request was rejected by the Threshold Network |
NotConnected | Attempted 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();
}
}