UseDocumentation 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.
decryptForView to reveal a confidential (encrypted) value locally in your app so you can display it in the UI.
Unlike decryptForTx, this flow does not return an on-chain-verifiable signature, and it is not meant to be published on-chain.
Flow
- Read the encrypted handle (
ctHash) from your contract. - Ensure you have a permit that authorizes decryption of that value.
- Call
decryptForView(ctHash, utype).execute()to get the plaintext.
decryptForView always decrypts using a permit (there is no .withoutPermit() mode). If your protocol intends for the plaintext to become publicly visible on-chain, use decryptForTx instead.Prerequisites
- Create and connect a client.
- Know the encrypted handle (
ctHash) and the encrypted type (utype). - Have a permit available for the connected
chainId + account.
Permit setup
If you don’t have a permit yet, create one once after connecting:Decrypt for UI
Choose the pattern that matches how your app manages permits:What decryptForView returns
Running .execute() resolves to a scalar JS value:
- Integer utypes (
Uint8,Uint16,Uint32,Uint64,Uint128): abigint FheTypes.Bool: abooleanFheTypes.Uint160(address): a checksummed0x...address string
Builder API
.execute() — required, call last
Runs the decryption and returns a UI-friendly scalar value.
.withPermit(...) — optional
Select which permit to use:
.withPermit()— uses the active permit.withPermit(permitHash)— fetches a stored permit by hash.withPermit(permit)— uses the provided permit object
.withPermit(...), the active permit is used by default.
.setAccount(address) — optional
Overrides the account used to resolve the active/stored permit.
.setChainId(chainId) — optional
Overrides the chain used to resolve the Threshold Network URL and permits.
.onPoll(callback) — optional
Register a callback that fires once per poll attempt while decryptForView waits for the Threshold Network to return the sealed plaintext. Useful for surfacing decrypt progress in a UI.
| Field | Type | Description |
|---|---|---|
operation | 'decrypt' | 'sealoutput' | Which Threshold Network flow is polling. For decryptForView this is 'sealoutput'. |
requestId | string | The Threshold Network request id. May be the empty string during submit-time retries — see .set404RetryTimeout(...) below. |
attemptIndex | number | Zero-based poll attempt counter. |
elapsedMs | number | Time since the first submit attempt. |
intervalMs | number | Delay until the next poll. |
timeoutMs | number | Overall budget shared by submit-retries and status-polling. |
.set404RetryTimeout(timeoutMs) — optional
Configures how long decryptForView keeps retrying when the Threshold Network’s submit endpoint responds with 404 Not Found before a requestId is available. This typically happens on slower backends where the ciphertext isn’t visible yet at submit time. Defaults to 10_000 ms.
0 to disable submit-time retries (404 becomes a hard failure). Submit retries share the same overall timeout budget as status polling.
Common UI patterns
Common pitfalls
- Missing permit:
decryptForViewwill fail if there is no active permit for the currentchainId + account. - Wrong
utype: you must pass the correct FHE type for the ciphertext. - Wrong chain/account: permits are scoped to
chainId + account. If the user switches wallets or networks, create/select the correct permit.