SDK 2.1: platform toolkit + vesting engine
Concept · FHE + core

Shared core and application modules

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

v2.1.0 stable
SDK 2.1 is the stable release on the latest dist-tag. Install it with pnpm add @tokenops/sdk. The receipt-free and Safe create surface of /fhe-airdrop remains @beta.

The product clients in v2.1.0 sit 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 viem zod@^4.1.11 and the optional Zama peers at ~3.6.0.

Application modules added in 2.1#

These modules complement the product clients: versioned contract encoding, a platform kernel, a browser confidential client, an observability exporter and a browser draft vault. They expose their own configuration and error surfaces. The observability exporter is separate from the SdkTelemetry sinks below; choose /observability/web or /observability/node for its environment. Open the guides in the sections list for examples and peer requirements.

The product-client core#

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.

77 runtime value exports
accessControlRoleHashAccessDeniedErrorAclNotPropagatedErrorAlreadyInitializedErrorapplyGasHeadroomasAirdropIdasEncryptedHandleasExternalInputProofasRoleasSignatureasTxHashasVestingIdBatchTooLargeErrorchainsWithDeploymentchainsWithKnownRegistryEntryContractRevertErrorDecryptionFailedErrorDEFAULT_GAS_HEADROOM_PERCENTDEPLOYED_ADDRESSESDeploymentAddressUnavailableErrorEncryptionFailedErrorerc1271AbiFeatureDisabledErrorFheHandleNotAllowedErrorGAS_ESTIMATE_FALLBACK_EVENTgetConfidentialTestTokenAddressgetDeployedAddressgetFheAirdropComplianceImplementationAddressgetFheAirdropEcdsaImplementationAddressgetFheAirdropFactoryAddressgetFheAirdropMerkleImplementationAddressgetFheDisperseSingletonAddressgetFheVestingFactoryAddressgetTestTokenAddressInsufficientBalanceErrorInsufficientFeeErrorInsufficientGasFundsErrorInvalidArgumentErrorInvalidSignatureErrorisSupportedChainIdisTokenOpsErrorisTokenOpsSdkErrorMAX_TRANSACTION_GASMissingAccountErrorMissingClientErrorMissingEncryptorErrorMissingPeerDependencyErrorMissingPublicClientErrorMissingWalletClientErrorNetworkErrorOPERATOR_NOT_APPROVED_REMEDIATIONOperatorNotApprovedErrorPausedErrorReceiptEventAmbiguousErrorReceiptEventNotFoundErrorReentrancyErrorRelayerUnreachableErrorrequireConfidentialTestTokenAddressrequireFheAirdropFactoryAddressrequireFheDisperseSingletonAddressrequireFheVestingFactoryAddressrequireTestTokenAddresssafeMinimalAbiSDK_VERSIONSigningFailedErrorSUPPORTED_CHAINSTokenOpsContractErrorTokenOpsSdkErrorTokenOpsValidationErrorTransferFailedErrorUnknownWriteFailureErrorUnsupportedChainErrorUserDecryptNotAllowedErrorUserRejectedSignatureErrorwaitForSubmittedWriteWalletChainMismatchErrorWalletRejectedError
@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.

68 runtime value exports
AccessDeniedErrorACL_ALLOWED_EVENTAclNotPropagatedErrorAlreadyInitializedErrorBatchTooLargeErrorContractRevertErrorcreateLocalFhevmEncryptorcreateMockEncryptorcreateMockErc7984ClientcreateSepoliaEncryptorDecryptionFailedErrorDEFAULT_GAS_HEADROOM_PERCENTDeploymentAddressUnavailableErrorEncryptionFailedErrorensureOperatorERC7984_OPERATOR_MAX_DEADLINEERC7984_SET_OPERATOR_ABIerc7984BalanceAbierc7984MetadataAbierc7984OperatorAbierc7984WrapperAbiFeatureDisabledErrorFHE_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. Browser bundlers resolve the optional @zama-fhe/sdk peer for this helper.

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#

  • Contract kit - Versioned ABIs, call encoding, Safe hashes and typed data
  • Kernel - IDs, clocks, validation, domain events and telemetry allowlists
  • Confidential client - Browser encryption, streamed reveals and permit lifecycle
  • Observability - Universal configuration and separate web and Node exporters
  • Draft vault - Seal draft amounts with Web Crypto and device-bound keys
  • Encryptors - The Encryptor contract, Node and mock encryptors, input-proof budget
  • Browser encryptor - createSepoliaEncryptorWeb on /fhe/web, workers and threads
  • Relayer API key - Mainnet relayer auth, server-only keys, browser proxy
  • Decryption - UserDecryptor, useDecryptedHandle, ACL propagation
  • Operators - setOperator, ensureOperator and the React pair
  • Gas headroom - Padded estimates, per-call gas, the EIP-7825 cap
  • Receipt-free writes - waitForReceipt: false for Safe and multisig signers
  • Read-hook query options - query on every product read hook
  • Telemetry - Sinks, spans, and what is never sent
  • Deployments - DEPLOYED_ADDRESSES per product and chain
  • Bundling + Node servers - Next.js, Vite, webpack, CSP, Express, wagmi v2 and v3
  • Error palette - Every TokenOpsSdkError class and code
  • Hooks - useDecryptedHandle, useIsOperator, useEnsureOperator

See also