2.0 RC docsView 1.x docs
Concept · FHE + core

The shared core every 2.0 product uses

Encryption, decryption, operators, gas and errors, shared by vesting, airdrop, disperse and the faucet.

v2.0.0-rc.1 release candidate
The API is frozen and later candidates carry fixes only, except the receipt-free and Safe create surface of /fhe-airdrop, which is @beta. Published on the next dist-tag; latest stays on 1.6.0 until 2.0.0.

Every product subpath of v2.0.0-rc.1 sits on the same core: one Encryptor contract, one gas policy, one receipt mode, one telemetry interface and one error hierarchy. The product subpaths re-export most of it, so you rarely import these subpaths directly, but this is where each piece is defined and where its behaviour is documented once. Install with pnpm add @tokenops/sdk@next and the optional Zama peers at ~3.6.0.

The five shared subpaths#

The value exports below are read from the installed build, so they cannot list something the artifact does not export. Types are not listed; the API reference has those.

@tokenops/sdk

SDK_VERSION, the deployed-address registry and its accessors, chain helpers, branded hex types, gas helpers, receipt-mode types and the core error palette.

71 runtime value exports
AccessDeniedErrorAclNotPropagatedErrorAlreadyInitializedErrorapplyGasHeadroomasAirdropIdasEncryptedHandleasExternalInputProofasRoleasSignatureasTxHashasVestingIdBatchTooLargeErrorchainsWithDeploymentchainsWithKnownRegistryEntryContractRevertErrorDecryptionFailedErrorDEFAULT_GAS_HEADROOM_PERCENTDEPLOYED_ADDRESSESDeploymentAddressUnavailableErrorEncryptionFailedErrorFeatureDisabledErrorFheHandleNotAllowedErrorgetConfidentialTestTokenAddressgetDeployedAddressgetFheAirdropComplianceImplementationAddressgetFheAirdropEcdsaImplementationAddressgetFheAirdropFactoryAddressgetFheAirdropMerkleImplementationAddressgetFheDisperseSingletonAddressgetFheVestingFactoryAddressgetTestTokenAddressInsufficientBalanceErrorInsufficientFeeErrorInsufficientGasFundsErrorInvalidArgumentErrorInvalidSignatureErrorisSupportedChainIdisTokenOpsSdkErrorMAX_TRANSACTION_GASMissingAccountErrorMissingClientErrorMissingEncryptorErrorMissingPeerDependencyErrorMissingPublicClientErrorMissingWalletClientErrorNetworkErrorOPERATOR_NOT_APPROVED_REMEDIATIONOperatorNotApprovedErrorPausedErrorReceiptEventAmbiguousErrorReceiptEventNotFoundErrorReentrancyErrorRelayerUnreachableErrorrequireConfidentialTestTokenAddressrequireFheAirdropFactoryAddressrequireFheDisperseSingletonAddressrequireFheVestingFactoryAddressrequireTestTokenAddressSDK_VERSIONSigningFailedErrorSUPPORTED_CHAINSTokenOpsContractErrorTokenOpsSdkErrorTokenOpsValidationErrorTransferFailedErrorUnknownWriteFailureErrorUnsupportedChainErrorUserDecryptNotAllowedErrorUserRejectedSignatureErrorWalletChainMismatchErrorWalletRejectedError
@tokenops/sdk/telemetry

Telemetry sinks: NoopTelemetry, ConsoleTelemetry and TokenOpsTelemetry, plus withTelemetry and the SdkTelemetry interface.

4 runtime value exports
ConsoleTelemetryNoopTelemetryTokenOpsTelemetrywithTelemetry
@tokenops/sdk/fhe

The Encryptor contract, the Node and mock encryptors, ERC-7984 operator helpers, the FHEVM ACL registry, scaleRatio and the mock-token mint. Bundles without @zama-fhe/sdk.

65 runtime value exports
AccessDeniedErrorACL_ALLOWED_EVENTAclNotPropagatedErrorAlreadyInitializedErrorBatchTooLargeErrorContractRevertErrorcreateLocalFhevmEncryptorcreateMockEncryptorcreateMockErc7984ClientcreateSepoliaEncryptorDecryptionFailedErrorDEFAULT_GAS_HEADROOM_PERCENTDeploymentAddressUnavailableErrorEncryptionFailedErrorensureOperatorERC7984_OPERATOR_MAX_DEADLINEERC7984_SET_OPERATOR_ABIerc7984OperatorAbiFeatureDisabledErrorFHE_SPLIT_DENOMINATORFheHandleNotAllowedErrorFHEVM_ACL_ADDRESS_BY_CHAINgetFhevmAclAddressInsufficientBalanceErrorInsufficientFeeErrorInsufficientGasFundsErrorInvalidArgumentErrorInvalidSignatureErrorisOperatorisTokenOpsSdkErrorMAINNET_CHAIN_IDMAX_EUINT64_PER_INPUT_PROOFmintMockERC7984MissingAccountErrorMissingClientErrorMissingEncryptorErrorMissingPeerDependencyErrorMissingPublicClientErrorMissingWalletClientErrorMOCK_ERC7984_MINT_ABINetworkErrorOperatorNotApprovedErrorPausedErrorReceiptEventAmbiguousErrorReceiptEventNotFoundErrorReentrancyErrorRelayerUnreachableErrorrequireFhevmAclAddressresolveEncryptorrevokeOperatorscaleRatioSEPOLIA_CHAIN_IDsetOperatorshareSigningFailedErrorTokenOpsContractErrorTokenOpsSdkErrorTokenOpsValidationErrorTransferFailedErrorUnknownWriteFailureErrorUnsupportedChainErrorUserDecryptNotAllowedErrorUserRejectedSignatureErrorWalletChainMismatchErrorWalletRejectedError
@tokenops/sdk/fhe/web

createSepoliaEncryptorWeb and its option and worker types. The only subpath a bundler resolves @zama-fhe/sdk for.

7 runtime value exports
createSepoliaEncryptorWebInvalidArgumentErrorisTokenOpsSdkErrorMAINNET_CHAIN_IDMissingPeerDependencyErrorSEPOLIA_CHAIN_IDTokenOpsSdkError
@tokenops/sdk/fhe/react

Cross-product React hooks, plus the errors those hooks throw for instanceof checks.

3 runtime hooks
useDecryptedHandleuseIsOperatoruseEnsureOperator

Ratios for confidential splits#

Every confidential split uses one plaintext denominator, FHE_SPLIT_DENOMINATOR (90090000, the LCM of 1 to 16 and 10 000). A per-split denominator would reveal the split's shape without decrypting anything. share.fraction(n, m) (m from 1 to 16) and share.basisPoints(bps) (0 to 10 000) build exact numerators over it; pass the result with preScaled: true. scaleRatio scales any other ratio to the same denominator; its width defaults to "uint128", so pass "uint64" to check a split numerator against the bound the encryption enforces. All three come from /fhe and are re-exported by /fhe-vesting, whose splitVesting is the one split today.

import { share, scaleRatio } from "@tokenops/sdk/fhe-vesting";

share.fraction(1, 3);   // { numerator: 30_030_000n, denominator: 90_090_000n }
share.basisPoints(250); // { numerator:  2_252_250n, denominator: 90_090_000n }, 2.5%

// Preview what auto-scaling would send, validated at the encrypt width.
scaleRatio({ numerator: 1n, denominator: 2n, width: "uint64" });

const ratio = share.basisPoints(50);
await manager.splitVesting({
  vestingId,
  numerator: ratio.numerator,
  denominator: ratio.denominator,
  preScaled: true, // share already scaled it exactly
  newRecipient,
});

Hex aliases#

The root exports EncryptedHandle, ExternalInputProof, TxHash, VestingId, AirdropId, Role and Signature. Each is a plain alias of viem's Hex, so they document what a value holds without nominal checking. The matching as* helpers (asTxHash, asVestingId and so on) are identity functions.

What changed since 1.6#

The full list, with every removal and its replacement, is in the migration guides. These are the changes that touch the shared core.

ChangeWhat to doRead
Zama peers move to ~3.6.0Upgrade @zama-fhe/sdk and @zama-fhe/react-sdk together; no range covers both 3.0 and 3.6.Zama 3.0 to 3.6
Encryptor.encrypt resolves hexCustom encryptors return { encryptedValues, inputProof } as Hex. Pass the ZamaSDK itself as the encryptor.Encryptors
createSepoliaEncryptorWeb movedImport it from @tokenops/sdk/fhe/web. From the alphas only the path changed; from 1.6 it also gains auth and offload* options and some behaviour changes.Browser encryptor
Mainnet relayer needs an API keyPass auth from server code; point browsers at a proxy with relayerUrl.Relayer API key
UserDecryptor mirrors decryptValuesPass userDecryptor: () => sdk.decryption and account to useDecryptedHandle.Decryption
Gas headroom on every writeNothing, unless you tune gasHeadroomPercent or pass a per-call gas.Gas headroom
Wallet-chain check on every writeA wallet on a different chain than the public client now throws WalletChainMismatchError before estimating.Error palette
waitForReceipt: falseSafe and multisig signers get a Pending result instead of a hang; hooks resolve Mined | Pending.Receipt-free writes
query on every product read hookTanStack cache options per read, minus queryKey and queryFn.Query options
New error classes and codesMissingPeerDependencyError, AclNotPropagatedError and new codes: an exhaustive switch on err.code needs the new cases.Error palette
SDK_VERSION on the rootPass it as TokenOpsTelemetryOptions.sdkVersion. The vesting hook-fired telemetry event is gone.Telemetry

Upgrading code: from 1.x, from a 2.0 prerelease, and Zama SDK 3.0 to 3.6.

Pages in this section#

See also