A Foundry-based template for developing Fully Homomorphic Encryption (FHE) enabled Solidity smart contracts using the FHEVM protocol by Zama.
- Foundry: Installation guide
-
Install dependencies
forge soldeer install
-
Compile and test
forge build forge test -vvv -
Deploy to local network
Start an Anvil node with the FHEVM host contracts deployed (requires forge-fhevm):
# From the forge-fhevm directory ./deploy-local.shThen deploy to the local network:
forge script script/DeployFHECounter.s.sol --rpc-url http://localhost:8545 --broadcast
Warning
🚧 Tests and scripts run only against the local FHEVM mock — never against Sepolia or any live FHEVM deployment.
forge test (and any script that depends on FHE decryption) relies on forge-fhevm's in-memory mock of the FHEVM host contracts — mock KMS / input signers, plaintext database. Those mocks do not exist on a live network, so pointing tests or test-style scripts at Sepolia will fail:
# ❌ FAIL — no mock host contracts on Sepolia
forge test --rpc-url http://sepolia --broadcast
# ❌ FAIL — encrypted state on a live network can't be decrypted in-process
forge script script/SomeFHEScript.s.sol --rpc-url http://sepolia --broadcastTo interact with a contract on Sepolia, deploy it (step 4 below) and interact through the Zama SDK from your dApp.
-
Deploy to Sepolia Testnet
cp .env.example .env # Edit .env with your deployer key and RPC URL source .env forge script script/DeployFHECounter.s.sol \ --rpc-url $RPC_URL \ --private-key $DEPLOYER_PRIVATE_KEY \ --broadcast --verify
fhevm-foundry-template/
├── src/ # Smart contract source files
│ └── FHECounter.sol # Example FHE counter contract
├── test/ # Test files
│ └── FHECounter.t.sol # Tests using forge-fhevm
├── script/ # Deployment scripts
│ └── DeployFHECounter.s.sol
├── foundry.toml # Foundry configuration
└── remappings.txt # Dependency remappings
| Script | Description |
|---|---|
forge build |
Compile all contracts |
forge test -vvv |
Run all tests |
forge test --match-test test_name -vvv |
Run a single test |
forge fmt |
Format code |
forge fmt --check |
Check formatting |
This project is licensed under the BSD-3-Clause-Clear License. See the LICENSE file for details.
- GitHub Issues: Report bugs or request features
- Documentation: FHEVM Docs
- Community: Zama Discord