Skip to main content
To get started with Cofhejs, you need to install it as a dependency in your JavaScript project. You can do this using npm (Node Package Manager), Yarn, or pnpm. Open your terminal and navigate to your project’s directory, then run the following:
pnpm add cofhejs

Setup

To use Cofhejs for interacting with FHE-enabled smart contracts, you must first initialize it. The cofhejs client handles key operations such as encrypting input data, creating permits, and decrypting output data from the blockchain.
1

Import required modules

Import the Cofhejs library and your web3 provider library (Ethers.js or Viem).
const { cofhejs } = require("cofhejs/node");
const { ethers } = require("ethers");
2

Initialize your web3 provider

Set up your provider and signer based on your environment.
3

Initialize Cofhejs

Initialize the Cofhejs client with your provider and signer.
Below is a complete example setup:
const { cofhejs } = require("cofhejs/node");
const { ethers } = require("ethers");

// initialize your web3 provider
const provider = new ethers.JsonRpcProvider("http://127.0.0.1:42069");
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);

// initialize cofhejs Client with ethers (it also supports viem)
await cofhejs.initializeWithEthers({
  ethersProvider: provider,
  ethersSigner: wallet,
  environment: "TESTNET"
});

Next Steps

Now that you have Cofhejs installed and initialized, you’re ready to start building with FHE-enabled smart contracts. Here are the key concepts to learn next: