# 使用Hardhat部署合约

## Hardhat简介

**Hardhat**是一个方便在以太坊系列的链上上进行构建的任务运行器。使用它可以帮助开发人员管理和自动化构建智能合约和dApp的过程中固有的重复任务，以及轻松地围绕此工作流程引入更多功能。

**Hardhat**还内置了**Hardhat 网络**，**Hardhat 网络**是为开发而设计的本地以太坊网络。 用来部署合约，运行测试和**调试代码**。

## 环境搭建

### 安装Node.js

因为Hardhat是基于JavaScript编写的，所以需要确保运行系统中已经安装了Node.js >=12.0

#### Ubuntu

```shell
sudo apt update
sudo apt install curl git
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs
```

#### MacOS

```shell
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
nvm install 12
nvm use 12
nvm alias default 12
npm install npm --global 
```

### 安装Hardhat

在Node环境安装成功后，就可以安装Hardhat了

```
npm install --save-dev hardhat
```

## 合约部署

### 下载合约

进入github，clone对应仓库

```
git clone git@github.com:relationlabs/relation-sbt.git
```

### 准备编译环境

```
npm install --save-dev hardhat
```

### 编译合约

```
cd relation-sbt
npm install
npx hardhat compile
```

### 部署合约

部署合约时，通过设置"network"参数来选择部署的环境。network可以是localhost，也可以测试网或者主网环境

```
npx hardhat run scripts/deploy.js --network {$network}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://relationlabs.gitbook.io/semantic-sbt/semanticsbt-zh/untitled/shi-yong-hardhat-bu-shu-he-yue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
