fhevmjs
is working out of the box and we recommend you to use it. We also provide three GitHub templates to start your project with everything set.
You can use this template to start an application with fhevmjs, using Vite + React + TypeScript.
You can also use this template to start an application with fhevmjs, using Vite + Vue + TypeScript.
You can also use this template to start an application with fhevmjs, using Next + TypeScript.
First, you need to install the library.
fhevmjs
uses ESM format. You need to set the type to "module" in your package.json. If your node project use "type": "commonjs"
or no type, you can force the loading of the web version by using import { createInstance } from 'fhevmjs/web';
To use the library in your project, you need to load the WASM of TFHE first with initFhevm
.
Once the WASM is loaded, you can now create an instance. An instance receives an object containing:
chainId
(optional): the chainId of the network
network
(optional): the Eip1193 object provided by window.ethereum
(used to fetch the public key and/or chain id)
networkUrl
(optional): the URL of the network (used to fetch the public key and/or chain id)
publicKey
(optional): if the public key has been fetched separately (cache), you can provide it
gatewayUrl
(optional): the URL of the gateway to retrieve a reencryption
coprocessorUrl
(optional): the URL of the coprocessor
You can now use your instance to encrypt parameters or do a reencryption.