# 使用 hardhat-laika

**什么是 hardhat-laika？**

`hardhat-laika` 是 莱卡自己的 Hardhat 插件，可帮助您将已编译的合约与莱卡同步。这使您无需编写任何额外代码即可发出请求。

相反，它还可以提高您使用 Hardhat 进行开发时的性能！💪

**让我们试试吧！**

首先，我们将开始一个新的 Hardhat 项目，执行

```
npx hardhat init
```

然后，选择您喜欢的配置（我们将使用此配置和 Greeter.sol 作为本指导示例中的示例合约）

```
√ What do you want to do? · Create a basic sample project
√ Hardhat project root: · /path/to/project/
√ Do you want to add a .gitignore? (Y/n) · y
√ Do you want to install this sample project's dependencies with npm (...)? (Y/n) · y
```

项目设置完成后，让我们使用安装hardhat-laika

```
npm i hardhat-laika
```

现在，通过在顶部添加 require(...) 语句将其导入**hardhat.config.js**&#x20;

{% embed url="<https://gist.github.com/nonkung51/b3a7e1dade2f0c89f2b41c9731565001#file-hardhat-config-js>" %}

好了，现在我们都准备好了！让我们尝试使用它！

有两种方法可以使用 hardhat-laika，即

1. 通过命令行
2. 通过你自己的javascript代码（通过定义 hardhat-laika 任务）

让我们试试第一种方法。

1. **The Hardhat Runner CLI**

首先，让我们编译我们的合约，以便我们可以获得 ABI。

```
npx hardhat compile
```

然后，使用 **laika-sync** 任务将其同步到 Laika

```
npx hardhat laika-sync --contract <contract_name> --address <OPTIONAL address_of_that_contract>
```

对于此示例，我们将使用带有以下参数的命令：

```
npx hardhat laika-sync --contract Greeter --address 0x5FbDB2315678afecb367f032d93F642f64180aa
```

你应该能够看到这样的东西。

<br>

![莱卡同步任务](https://miro.medium.com/max/1232/1*2bkX75lbOFii1pl_UCdA1A.gif)

**2. 创建脚本**

让我们看看 scripts/sample-script.js

{% embed url="<https://gist.github.com/nonkung51/d9e0137c2005a2c91fc8c2e43c13b44f#file-sample-script-js>" %}

我们只需简单地**将 hre.run() 添加到第 25** 行即可！我们可以使用命令来运行它。

```
npx hardhat run scripts/sample-script.js
```

你应该能够看到这样的东西。

![](https://miro.medium.com/max/1200/0*SjVc6BI5SiEUakBU.gif)

这两种方法都可以让您直接将莱卡与您的Hardhat环境集成，如图所示。
