Files
2025-12-27 21:42:55 -08:00

4.4 KiB

Build a web application

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

Using directly the library

Step 1: Setup the library

@luxfhe-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

The LuxFHE CDN url format is https://cdn.luxfhe.org/relayer-sdk-js/<package-version>/relayer-sdk-js.umd.cjs

Include this line at the top of your project.

<script
  src="https://cdn.luxfhe.org/relayer-sdk-js/0.3.0-7/relayer-sdk-js.umd.cjs"
  type="text/javascript"
></script>

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

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

Using ESM CDN

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

<script type="module">
  import {
    initSDK,
    createInstance,
    SepoliaConfig,
  } from 'https://cdn.luxfhe.org/relayer-sdk-js/0.3.0-7/relayer-sdk-js.umd.cjs';

  await initSDK();
  const config = { ...SepoliaConfig, network: window.ethereum };
  config.network = window.ethereum;
  const instance = await createInstance(config);
</script>

Using npm package

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

# Using npm
npm install @luxfhe-fhe/relayer-sdk

# Using Yarn
yarn add @luxfhe-fhe/relayer-sdk

# Using pnpm
pnpm add @luxfhe-fhe/relayer-sdk

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

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

Step 2: Initialize your project

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

import { initSDK } from '@luxfhe-fhe/relayer-sdk/bundle';

const init = async () => {
  await initSDK(); // Load needed WASM
};

Step 3: Create an instance

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

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

const init = async () => {
  await initSDK(); // Load FHE
  const config = { ...SepoliaConfig, network: window.ethereum };
  return createInstance(config);
};

init().then((instance) => {
  console.log(instance);
});

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