fhevmjs provides an easy-to-use function to encrypt your inputs before sending them to the Fhenix blockchain.
Encryption in Fhenix is done using the public key of the network. This key is loaded on initialization of the fhevmjs and can be obtained somehow.
When we perform encryption, we specify the type of euint we encrypt into. This should match the expected type in the Solidity contract we are working with.
First, initialize the library -
import * as fhevmjs from 'fhevmjs';
const instance = fhevmjs.createInstance({
chainId: 8011,
publicKey: tfhePublicKey,
Then, you can use the created instance to encrypt
const resultUint8 = instance.encrypt8(number)
const resultUint16 = instance.encrypt16(number)
const resultUint32 = instance.encrypt32(number)
Note: The encrypt function will throw an error if the number exceeds the limits of the type you are trying to use
The returned type will a Uint8Array, which represents an encrypted FHE number.