Client API
Core functions for initializing and creating FHEVM clients.
initFHEVM
Initialize the FHEVM SDK. Must be called once before using any other functionality.
import { initFHEVM } from '@fhevmsdk/core'
await initFHEVM()
Returns
Promise<void>
Throws
Error- If not running in a browser environmentError- If FHEVM SDK initialization fails
Example
import { initFHEVM } from '@fhevmsdk/core'
async function setup() {
try {
await initFHEVM()
console.log('FHEVM initialized successfully')
} catch (error) {
console.error('Failed to initialize FHEVM:', error)
}
}
createFHEVMClient
Create an FHEVM client instance for encryption and decryption operations.
import { createFHEVMClient } from '@fhevmsdk/core'
const client = await createFHEVMClient({
network: 'sepolia', // optional, defaults to 'sepolia'
provider: window.ethereum, // optional, defaults to window.ethereum
})
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| options | CreateFHEVMClientOptions | No | {} | Client configuration options |
CreateFHEVMClientOptions
interface CreateFHEVMClientOptions {
network?: 'sepolia' | FhevmInstanceConfig
provider?: any // window.ethereum or EIP-1193 provider
}
Returns
Promise<FHEVMClient>
interface FHEVMClient {
instance: FhevmInstance
isReady: boolean
encrypt: {
uint8: (params: EncryptParams) => Promise<EncryptedValue>
uint16: (params: EncryptParams) => Promise<EncryptedValue>
uint32: (params: EncryptParams) => Promise<EncryptedValue>
uint64: (params: EncryptParams) => Promise<EncryptedValue>
uint128: (params: EncryptParams) => Promise<EncryptedValue>
uint256: (params: EncryptParams) => Promise<EncryptedValue>
}
decrypt: (params: DecryptParams) => Promise<bigint>
}
Throws
Error- If not running in a browser environmentError- If Ethereum provider is not availableError- If unknown network specified
Examples
Basic Usage
import { initFHEVM, createFHEVMClient } from '@fhevmsdk/core'
await initFHEVM()
const client = await createFHEVMClient({
network: 'sepolia',
})
console.log('Client ready:', client.isReady)
Custom Provider
import { createFHEVMClient } from '@fhevmsdk/core'
const client = await createFHEVMClient({
network: 'sepolia',
provider: customProvider, // Custom EIP-1193 provider
})
Custom Network Config
import { createFHEVMClient } from '@fhevmsdk/core'
import type { FhevmInstanceConfig } from '@fhevmsdk/core'
const customConfig: FhevmInstanceConfig = {
aclAddress: '0x...',
gatewayUrl: 'https://gateway.example.com',
publicKey: '...',
chainId: 12345,
}
const client = await createFHEVMClient({
network: customConfig,
})
Type Exports
FHEVMClient
interface FHEVMClient {
instance: FhevmInstance // Raw FHEVM instance
isReady: boolean // Client initialization status
encrypt: EncryptMethods // Encryption methods
decrypt: DecryptMethod // Decryption method
}
CreateFHEVMClientOptions
interface CreateFHEVMClientOptions {
network?: 'sepolia' | FhevmInstanceConfig
provider?: any
}
FhevmInstance
type FhevmInstance = {
// Internal FHEVM instance (from @zama-fhe/relayer-sdk)
}
Related APIs
- Encrypt API - Encryption methods
- Decrypt API - Decryption method
- Config API - Network configuration
- Utils API - Utility functions