Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve Hardhat tutorial #712

Merged
merged 7 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/.gitbook/assets/image (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.gitbook/assets/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 22 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,53 @@ layout:

Learn the basics of fhEVM, set it up, and make it run with ease.

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Overview</strong></td><td>Understand the basic concepts of fhEVM library.</td><td><a href=".gitbook/assets/start1.png">start1.png</a></td><td><a href="getting_started/overview.md">key_concepts.md</a></td></tr><tr><td><strong>Quick start</strong></td><td>Deploy your first fhEVM smart contract.</td><td><a href=".gitbook/assets/start4.png">start4.png</a></td><td><a href="getting_started/quick_start/overview.md">quick_start.md</a></td></tr><tr><td><strong>Get started with Hardhat</strong></td><td>Learn how to deploy and write confidential smart contracts with Hardhat</td><td><a href=".gitbook/assets/start5.png">start5.png</a></td><td><a href="tutorials/hardhat.md">hardhat.md</a></td></tr></tbody></table>
<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Overview</strong></td><td>Explore the suite of fhEVM protocol.</td><td><a href=".gitbook/assets/start1.png">start1.png</a></td><td><a href="getting-started/overview.md">overview.md</a></td></tr><tr><td><strong>Quick start with Remix</strong></td><td>Learn and prototype in the in-browser IDE.</td><td><a href=".gitbook/assets/start4.png">start4.png</a></td><td><a href="getting-started/overview-1/overview.md">overview.md</a></td></tr><tr><td><strong>Get started with Hardhat</strong></td><td>Develop in production-ready envrionment.</td><td><a href=".gitbook/assets/start5.png">start5.png</a></td><td><a href="broken-reference">Broken link</a></td></tr></tbody></table>

## Develop a fhEVM smart contract

Start developing fhEVM smart contracts in Solidity by exploring its core features, discovering essential guides, and learning more with user-friendly tutorials.

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><strong>Fundamentals</strong></td><td>Explore core features.</td><td><ul><li><a href="tutorials/hardhat.md">Write contract with Hardhat</a></li><li><a href="smart_contracts/types.md">Use encrypted types</a></li></ul></td><td><a href=".gitbook/assets/build1.png">build1.png</a></td></tr><tr><td><strong>Guides</strong></td><td>Learn more about fhEVM implementation.</td><td><ul><li><a href="./frontend/webapp.md">Frontend</a></li></ul></td><td><a href=".gitbook/assets/build2.png">build2.png</a></td></tr><tr><td><strong>Tutorials</strong></td><td>Build quickly with tutorials.</td><td><ul><li><a href="tutorials/see-all-tutorials.md">See all tutorials</a></li></ul></td><td><a href=".gitbook/assets/build3.png">build3.png</a></td></tr></tbody></table>
<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><strong>Smart contract</strong></td><td>Learn core Solidity library.</td><td><ul><li><a href="smart_contracts/key_concepts.md">Key features</a></li><li><a href="smart_contracts/types.md">Use encrypted types</a></li></ul></td><td><a href=".gitbook/assets/build1.png">build1.png</a></td></tr><tr><td><strong>Frontend</strong></td><td>Write a dAPP frontend.</td><td><ul><li><a href="frontend/setup.md">Set up</a></li><li><a href="frontend/webapp.md">Build a web application</a></li></ul></td><td><a href=".gitbook/assets/build2.png">build2.png</a></td></tr><tr><td><strong>Tutorials</strong></td><td>Build quickly with tutorials.</td><td><ul><li><a href="tutorials/see-all-tutorials.md">See all tutorials</a></li></ul></td><td><a href=".gitbook/assets/build3.png">build3.png</a></td></tr></tbody></table>

## Explore more

Access to additional resources and join the Zama community.

### Explanations

Explore the technical architecture of the fheEVM protocol and the underlying cryptographic principles that power it.

* [Architecture overview](smart_contracts/architecture_overview.md)
* [FHE on blockchain](smart_contracts/architecture_overview/fhe-on-blockchain.md)
* [fhEVM components](smart_contracts/architecture_overview/fhevm-components.md)
* [Encryption, decryption re-encryption and computaiton](smart_contracts/d_re_ecrypt_compute.md)

### References

Refer to the API and access additional resources for in-depth explanations while working with fhEVM.

- [API function specifications](references/functions.md)
- [Repositories](references/repositories.md)
* [API function specifications](references/functions.md)
* [Repositories](references/repositories.md)

### Supports

Ask technical questions and discuss with the community. Our team of experts usually answers within 24 hours in working days.

- [Community forum](https://community.zama.ai/c/fhevm/15)
- [Discord channel](https://discord.com/invite/fhe-org)
- [Telegram](https://t.me/+Ojt5y-I7oR42MTkx)
* [Community forum](https://community.zama.ai/c/fhevm/15)
* [Discord channel](https://discord.com/invite/fhe-org)
* [Telegram](https://t.me/+Ojt5y-I7oR42MTkx)

### Developers

Collaborate with us to advance the FHE spaces and drive innovation together.

- [Contribute to fhEVM](developer/contribute.md)
- [Follow the development roadmap](developer/roadmap.md)
- [See the latest test release note](https://github.com/zama-ai/fhevm/releases)
- [Request a feature](https://github.com/zama-ai/fhevm/issues/new?assignees=&labels=enhancement&projects=&template=feature-request.md&title=)
- [Report a bug](https://github.com/zama-ai/fhevm/issues/new?assignees=&labels=bug&projects=&template=bug_report_fhevm.md&title=)
* [Contribute to fhEVM](developer/contribute.md)
* [Follow the development roadmap](developer/roadmap.md)
* [See the latest test release note](https://github.com/zama-ai/fhevm/releases)
* [Request a feature](https://github.com/zama-ai/fhevm/issues/new?assignees=\&labels=enhancement\&projects=\&template=feature-request.md\&title=)
* [Report a bug](https://github.com/zama-ai/fhevm/issues/new?assignees=\&labels=bug\&projects=\&template=bug_report_fhevm.md\&title=)

---
***

{% hint style="success" %}
**Zama 5-Question Developer Survey**
Expand Down
109 changes: 58 additions & 51 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,81 @@
# Table of contents

- [Welcome to fhEVM](README.md)
- [Whitepaper](https://github.com/zama-ai/fhevm/blob/main/fhevm-whitepaper-v2.pdf)
* [Welcome to fhEVM](README.md)
* [White paper](https://github.com/zama-ai/fhevm/blob/main/fhevm-whitepaper-v2.pdf)

## Getting Started

- [Overview](getting_started/overview.md)
- [Quick start](getting_started/quick_start/overview.md)
- [1. Setting up Remix](getting_started/quick_start/remix.md)
- [2. Connect your wallet to Remix](getting_started/quick_start/connect_wallet.md)
- [3. Deploying ConfidentialERC20](getting_started/quick_start/deploying_cerc20.md)
- [4. Interacting with the contract](getting_started/quick_start/interact.md)
* [Overview](getting-started/overview.md)
* [Quick Start](getting-started/overview-1/overview.md)
* [Remix](getting-started/overview-1/remix/README.md)
* [1. Setting up Remix](getting-started/overview-1/remix/remix.md)
* [2. Connect your wallet to Remix](getting-started/overview-1/remix/connect_wallet.md)
* [3. Deploying ConfidentialERC20](getting-started/overview-1/remix/deploying_cerc20.md)
* [4. Interacting with the contract](getting-started/overview-1/remix/interact.md)
* [Hardhat](getting-started/overview-1/hardhat/README.md)
* [Prerequisites](getting-started/overview-1/hardhat/prerequisites.md)
* [1. Setting up Hardhat](getting-started/overview-1/hardhat/1.-setting-up-hardhat.md)
* [2. Writing contracts](getting-started/overview-1/hardhat/2.-writing-contracts.md)
* [3. Testing in mocked mode](getting-started/overview-1/hardhat/3.-testing-in-mocked-mode.md)
* [4. Deploying the contract](getting-started/overview-1/hardhat/4.-deploying-the-contract.md)
* [5. Interacting with the contract](getting-started/overview-1/hardhat/5.-interacting-with-the-contract.md)

## Tutorials

- [Tutorial: Setting up Hardhat](tutorials/hardhat.md)
- [See all tutorials](tutorials/see-all-tutorials.md)
* [See all tutorials](tutorials/see-all-tutorials.md)

## Smart contract

- [Key features](smart_contracts/key_concepts.md)
- [Configuration](smart_contracts/configure.md)
- [FhEVM contracts](smart_contracts/contracts.md)
- [Supported types](smart_contracts/types.md)
- [Operations on encrypted types](smart_contracts/operations.md)
- [Access Control List](smart_contracts/acl/README.md)
- [ACL examples](smart_contracts/acl/acl_examples.md)
- [Encrypted Inputs](smart_contracts/inputs.md)
- [Decryption](smart_contracts/decryption/README.md)
- [Decryption](smart_contracts/decryption/decrypt.md)
- [Decryption in depth](smart_contracts/decryption/decrypt_details.md)
- [Re-encryption](smart_contracts/decryption/reencryption.md)
- [If sentances](smart_contracts/loop.md)
- [Branching in FHE](smart_contracts/conditions.md)
- [AsEbool, asEuintXX, asEaddress and asEbytesXX operations](smart_contracts/asEXXoperators.md)
- [Generate random numbers](smart_contracts/random.md)
- [Error handling](smart_contracts/error_handling.md)
- [Gas estimation](smart_contracts/gas.md)
- [Debug decrypt](smart_contracts/debug_decrypt.md)
- [Using Foundry](smart_contracts/write_contract/foundry.md)
* [Key features](smart_contracts/key_concepts.md)
* [Configuration](smart_contracts/configure.md)
* [FhEVM contracts](smart_contracts/contracts.md)
* [Supported types](smart_contracts/types.md)
* [Operations on encrypted types](smart_contracts/operations.md)
* [Access Control List](smart_contracts/acl/README.md)
* [ACL examples](smart_contracts/acl/acl_examples.md)
* [Encrypted Inputs](smart_contracts/inputs.md)
* [Decryption](smart_contracts/decryption/README.md)
* [Decryption](smart_contracts/decryption/decrypt.md)
* [Decryption in depth](smart_contracts/decryption/decrypt_details.md)
* [Re-encryption](smart_contracts/decryption/reencryption.md)
* [If sentences](smart_contracts/loop.md)
* [Branching in FHE](smart_contracts/conditions.md)
* [AsEbool, asEuintXX, asEaddress and asEbytesXX operations](smart_contracts/asEXXoperators.md)
* [Generate random numbers](smart_contracts/random.md)
* [Error handling](smart_contracts/error_handling.md)
* [Gas estimation](smart_contracts/gas.md)
* [Debug decrypt](smart_contracts/debug_decrypt.md)
* [Using Foundry](smart_contracts/write_contract/foundry.md)

## Frontend

- [Setup](frontend/setup.md)
- [Build a web application](frontend/webapp.md)
- [Using React.js](https://github.com/zama-ai/fhevm-react-template)
- [Using Next.js](https://github.com/zama-ai/fhevm-next-template)
- [Using Vue.js](https://github.com/zama-ai/fhevm-vue-template)
- [Using Node or Typescript](frontend/node.md)
- [Using the CLI](frontend/cli.md)
- [Common webpack errors](frontend/webpack.md)
* [Setup](frontend/setup.md)
* [Build a web application](frontend/webapp.md)
* [Using React.js](https://github.com/zama-ai/fhevm-react-template)
* [Using Next.js](https://github.com/zama-ai/fhevm-next-template)
* [Using Vue.js](https://github.com/zama-ai/fhevm-vue-template)
* [Using Node or Typescript](frontend/node.md)
* [Using the CLI](frontend/cli.md)
* [Common webpack errors](frontend/webpack.md)

## Explanations

- [Architectural overview](smart_contracts/architecture_overview.md)
- [FHE on blockchain](smart_contracts/architecture_overview/fhe-on-blockchain.md)
- [fhEVM components](smart_contracts/architecture_overview/fhevm-components.md)
- [Encryption, decryption, re-encryption, and computation](smart_contracts/d_re_ecrypt_compute.md)
* [Architectural overview](smart_contracts/architecture_overview.md)
* [FHE on blockchain](smart_contracts/architecture_overview/fhe-on-blockchain.md)
* [fhEVM components](smart_contracts/architecture_overview/fhevm-components.md)
* [Encryption, decryption, re-encryption, and computation](smart_contracts/d_re_ecrypt_compute.md)

## References

- [Table of all addresses](references/table_of_addresses.md)
- [Smart contracts - fhEVM API](references/functions.md)
- [Frontend - fhevmjs lib](references/fhevmjs.md)
- [Repositories](references/repositories.md)
* [Table of all addresses](references/table_of_addresses.md)
* [Smart contracts - fhEVM API](references/functions.md)
* [Frontend - fhevmjs lib](references/fhevmjs.md)
* [Repositories](references/repositories.md)

## Developer

- [Contributing](developer/contribute.md)
- [Development roadmap](developer/roadmap.md)
- [Release note](https://github.com/zama-ai/fhevm/releases)
- [Feature request](https://github.com/zama-ai/fhevm/issues/new?assignees=&labels=enhancement&projects=&template=feature-request.md&title=)
- [Bug report](https://github.com/zama-ai/fhevm/issues/new?assignees=&labels=bug&projects=&template=bug_report_fhevm.md&title=)
* [Contributing](developer/contribute.md)
* [Development roadmap](developer/roadmap.md)
* [Release note](https://github.com/zama-ai/fhevm/releases)
* [Feature request](https://github.com/zama-ai/fhevm/issues/new?assignees=\&labels=enhancement\&projects=\&template=feature-request.md\&title=)
* [Bug report](https://github.com/zama-ai/fhevm/issues/new?assignees=\&labels=bug\&projects=\&template=bug_report_fhevm.md\&title=)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 1. Setting up Hardhat

This guide walks you through setting up your Hardhat environment using Zama's fhEVM Hardhat template.

## Step 1: Clone the Hardhat template

1. Open the repository: [Zama fhEVM Hardhat Template](https://github.com/zama-ai/fhevm-hardhat-template)
2. Click "Use this template" to create a new repository under your GitHub account.
3. Clone the repository you have created to your local environment
4. Copy the repository URL of your newly created repository.
5. Open a terminal and run:

```sh
git clone <your-new-repo-url>
cd <your-new-repo-name>
```

{% embed url="https://scribehow.com/embed/Step_1__M1Gjr6SAQuOsPyT7luekmw?removeLogo=true&skipIntro=true" %}

## Step 2: Configure the environment

1. Copy the environment configuration template:

```sh
cp .env.example .env
```
2. Install project dependencies: Depending on your package manager, run one of the following:

```sh
# Using npm
npm install

# Using yarn
yarn install

# Using pnpm
pnpm install
```

{% embed url="https://scribehow.com/embed/Step_2_Copy__dIIvxIkrTPWTMD-A9s3Twg?removeLogo=true&skipIntro=true" %}

## Project structure overview

* **`contracts/`**: Write your Solidity smart contracts here.
* **`test/`**: Place your test scripts for smart contract testing.
* **`deploy/`**: Deployment scripts for deploying your contracts.
* **`hardhat.config.js`**: The pre-configured Hardhat setup file for deploying on Sepolia.
* **`.env`:** The envrionment file that stores sensitive or environment-specific variables such as private keys and API keys.

To learn more about Hardhat, refer to the [official Hardhat documentation](https://hardhat.org/hardhat-runner/docs/getting-started#overview).

***

You are now ready to start building your confidential smart contracts with fhEVM!
72 changes: 72 additions & 0 deletions docs/getting-started/overview-1/hardhat/2.-writing-contracts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 2. Writing contracts

This document explains how to write confidential smart contract using fhEVM in Hardhat projects.

## Prerequisites

Before proceeding, ensure you have:

* A working Hardhat environment set up (see [previous section](1.-setting-up-hardhat.md)).
* Basic knowledge of Solidity.
* An understanding of ERC20 tokens.

## Understanding the example contract

The Hardhat template includes an example contract in the `contracts/` folder - `MyConfidentialERC20.sol`. This contract enables:

* Private ERC20 token transfers.
* Encrypted balances.
* Minting functionality for authorized addresses.

Let's break down the contract.

{% embed url="https://scribehow.com/embed/Contract__WHzYcFfeQp-wamyKwJVDhw?removeLogo=true&skipIntro=true" %}



### Step 1. Importing required libraries and contracts.

```solidity
pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";
import "fhevm/config/ZamaFHEVMConfig.sol";
import "fhevm-contracts/contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol";
```

* **`TFHE.sol`**: The core Solidity library of Zama's fhEVM. It enables encrypted data type like `euint64`, secures encrypted operations, such as addition and comparison and allows access control.
* **`SepoliaZamaFHEVMConfig`**: A configuration contract that automatically sets up the required configurations for real-time encrypted operations on the Sepolia testnet.
* **`ConfidentialERC20Mintable.sol`** : The confidential smart contract that allows for full ERC20 compatibility with FHE encryption.

### Step 2. Contract construction

```solidity
contract MyConfidentialERC20 is SepoliaZamaFHEVMConfig, ConfidentialERC20Mintable {
constructor(string memory name_, string memory symbol_) ConfidentialERC20Mintable(name_, symbol_, msg.sender) {}
}
```

* This contract inherits `SepoliaZamaFHEVMConfig` and `ConfidentialERC20Mintable`.
* The constructor initializes the ERC20 token with a name and symbol, setting the deployer as the initial owner.

## Going further

This is a simple basic contract that we will deploy and use in this tutorial. To write more complex confidential smart contracts or customize your own functions:

* Explore the full range of fhEVM capabilities in the [**Smart Contract**](../../../smart_contracts/key_concepts.md) section.
* Use the **`fhevm-contracts`** library and extend from the basic contract templates.

{% hint style="info" %}
The **fhevm-contracts** is a Solidity library designed for developers to easily develop confidential smart contracts using fhEVM. It provides:

* **Ready-to-use confidential contracts**: Pre-built implementations of common token standards with FHE capabilities
* **Base contracts**: Foundational building blocks for creating custom confidential smart contracts
* **Extensions**: Additional features and utilities that can be added to base contracts
* **Testing utilities**: Tools to help test FHE-enabled smart contracts

See more details in [the fhEVM-contracts documentation](../../../smart_contracts/contracts.md).
{% endhint %}

***

Your contract is ready! Let's move on to testing and deployment.
Loading
Loading