Web applications

This document guides you through building a web application using the @zama-fhe/relayer-sdk library.

Using directly the library

Step 1: Setup the library

@zama-fhe/relayer-sdk consists of multiple files, including WASM files and WebWorkers, which can make packaging these components correctly in your setup cumbersome. To simplify this process, especially if you're developing a dApp with server-side rendering (SSR), we recommend using our CDN.

Using UMD CDN

Include this line at the top of your project.

<script
  src="https://cdn.zama.ai/relayer-sdk-js/0.2.0/relayer-sdk-js.umd.cjs"
  type="text/javascript"
></script>

In your project, you can use the bundle import if you install @zama-fhe/relayer-sdk package:

import {
  initSDK,
  createInstance,
  SepoliaConfig,
} from '@zama-fhe/relayer-sdk/bundle';

Using ESM CDN

If you prefer You can also use the @zama-fhe/relayer-sdk as a ES module:

Using npm package

Install the @zama-fhe/relayer-sdk library to your project:

@zama-fhe/relayer-sdk 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 '@zama-fhe/relayer-sdk/web';

Step 2: Initialize your project

To use the library in your project, you need to load the WASM of TFHE first with initSDK.

Step 3: Create an instance

Once the WASM is loaded, you can now create an instance.

You can now use your instance to encrypt parameters, perform user decryptions or public decryptions.

Last updated