Tutorial
Quick Start Guide
Build your first FHE-enabled smart contract in four steps.
What you'll learn
✓
Setting up your dev environment with Maze FHE libraries✓
Converting standard Solidity types to encrypted types✓
Using FHE operations for arithmetic on encrypted data✓
Implementing access control for decryption permissions01
Environment Setup
Install Node.js, Hardhat, and Maze FHE dependencies
02
Write Basic Contract
Start with a simple Solidity contract
03
Convert to Maze FHE
Transform your contract to support FHE operations
04
Test & Deploy
Test locally and deploy to testnet
1
Environment Setup
Ensure you have Node.js v18+, npm or yarn, and basic Solidity knowledge.
Terminalbash
npm install --save-dev hardhat
npx hardhat init
# Download MAZE FHE library
mkdir -p maze-solidity/{lib,config}
curl -sL https://mazedapp.org/maze-solidity/lib/FHE.sol -o maze-solidity/lib/FHE.sol
curl -sL https://mazedapp.org/maze-solidity/lib/MazeACL.sol -o maze-solidity/lib/MazeACL.sol
curl -sL https://mazedapp.org/maze-solidity/config/MazeConfig.sol -o maze-solidity/config/MazeConfig.sol2
Write a Basic Contract
Start with a simple Solidity counter contract that we’ll convert to FHE.
12345678910111213pragma solidity ^0.8.0; contract Counter { uint32 private _count; function getCount() public view returns (uint32) { return _count; } function increment(uint32 value) public { _count += value; }}3
Convert to Maze FHE
Here’s the same contract modified to use encrypted values:
12345678910111213141516171819pragma solidity ^0.8.0; import {FHE, euint32, externalEuint32} from "@maze/solidity/lib/FHE.sol";import {MazeEthereumConfig} from "@maze/solidity/config/MazeConfig.sol"; contract FHECounter is MazeEthereumConfig { euint32 private _count; function getCount() public view returns (euint32) { return _count; } function increment(externalEuint32 calldata inputEuint32, bytes calldata inputProof) public { euint32 evalue = FHE.fromExternal(inputEuint32, inputProof); _count = FHE.add(_count, evalue); FHE.allowThis(_count); FHE.allow(_count, msg.sender); }}Key Changes
▸Import FHE library: Access encrypted types and operations
▸uint32 → euint32: Standard type becomes encrypted
▸FHE.fromExternal(): Convert external encrypted input with ZK proof
▸FHE.add(): Perform addition on encrypted values
▸FHE.allow(): Grant decryption permission to specific addresses
4
Test & Deploy
Terminalbash
npx hardhat test
npx hardhat run scripts/deploy.js --network sepoliaImportant
- ▸Test on testnets before mainnet deployment
- ▸Ensure you have testnet ETH for gas fees
- ▸Verify contract addresses after deployment
- ▸Use MAZE Playground to test contracts interactively