fhEVM
WebsiteLibrariesProduct & ServicesDevelopersSupport
0.5
0.5
  • Welcome to fhEVM
  • Getting Started
    • What is fhEVM
    • Deploy on fhEVM native
      • Using Zama Faucet
      • Local dev node
    • Deploy on Ethereum
    • Whitepaper
  • Fundamentals
    • Write contract
      • Using Hardhat
      • Using Remix
      • Other development environment
    • Encrypted types
      • Operations on encrypted types
      • Branching in FHE
      • Generate random number
    • Encrypted inputs
    • Access Control List
    • Decrypt and reencrypt
    • Contracts standard library
  • Guides
    • Decryption
    • Reencryption
    • Build a web application
    • Build with Node
    • Common pitfalls and best practises
    • How can I break a loop ?
    • Gas estimation on devnet
    • Use the CLI
    • Common webpack errors
  • Tutorials
    • See all tutorials
    • Write confidential smart contract with fhEVM
  • References
    • API function specifications
    • fhevmjs function specifications
    • Repositories
  • Developer
    • Contributing
    • Development roadmap
    • Release note
    • Feature request
    • Bug report
Powered by GitBook

Libraries

  • TFHE-rs
  • Concrete
  • Concrete ML
  • fhEVM

Developers

  • Blog
  • Documentation
  • Github
  • FHE resources

Company

  • About
  • Introduction to FHE
  • Media
  • Careers
On this page

Was this helpful?

Export as PDF
  1. Guides

Build with Node

PreviousBuild a web applicationNextCommon pitfalls and best practises

Last updated 10 months ago

Was this helpful?

First, you need to install the library.

# Using npm
npm install fhevmjs

# Using Yarn
yarn add fhevmjs

# Using pnpm
pnpm add fhevmjs

fhevmjs uses ESM format for web version and commonjs for node version. You need to set the to load the correct version of fhevmjs. If your node project use "type": "module", you can force the loading of the Node version by using import { createInstance } from 'fhevmjs/node';

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

Create an instance

const { createInstance } = require("fhevmjs");

const createFhevmInstance = async () => {
  return createInstance({
    chainId: 8009,
    networkUrl: "https://devnet.zama.ai/",
    gatewayUrl: "https://gateway.zama.ai",
  });
};
createFhevmInstance().then((instance) => {
  console.log(instance);
});

You can now use your instance to or do a .

type to "commonjs" in your package.json
encrypt parameters
reencryption