# 4. 使用 Ganache v7

{% hint style="info" %}
Consensys 宣布终止与 Truffle 和 Ganache 的合作关系以及和 HardHat 新的合作关系，[更多详情](https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github\&utm_medium=referral\&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_)。
{% endhint %}

## 1. 打开 Sandbox

注：以 GIthub 方式登录 ChainIDE 后才可使用 Sandbox 功能。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FoAIKQR9LuRVPeFmh7Rd3%2Fimage.png?alt=media&#x26;token=6a8b10eb-18f9-471e-afc3-c2de3383191b" alt=""><figcaption></figcaption></figure>

打开 Sandbox

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FgNy5ijyUoMl1ugKEOZq5%2Fimage.png?alt=media&#x26;token=357b3d36-d09f-4fe5-8249-446f7a83f506" alt=""><figcaption></figcaption></figure>

## 2. 启动 Ganache

通过输入带参数的 ganache 来启动一条 terminal 之外的客户端也可以访问的本地链：

```
ganache -h 0.0.0.0
```

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FztoEY7MvS9yid3Wz5toV%2Fimage.png?alt=media&#x26;token=8febb921-a067-4893-a9c3-d5795303c3bc" alt=""><figcaption></figcaption></figure>

## 3. 端口转发

为了其他客户端可以通过链接访问到上图启动的 ganache，请参考 [ChainIDE - 端口转发](https://chainide.gitbook.io/chainide-chinese/5.-port-forwarding) 转发 HTTP 8545 端口，并复制其地址 (例如：<https://sandbox-1e82a87a951241179f98494a6dbb2617-ethereum-8545.uat-sandbox.chainide.com>)。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2Fp3rvUlwjXfeRwhFMIFLE%2Fimage.png?alt=media&#x26;token=b9d1e4c0-0775-463a-9cd0-1d98f38bb4bb" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
这样你就成功的启动了一条 ganache 本地区块链。接下来可以通过 Metamask 连上该条链，或者通过 Truffle, Hrdhat 部署合约, chain id 为 1337。
{% endhint %}

#### 相关链接

* [ganache 文档](https://trufflesuite.com/docs/ganache/)
* [ganache github仓库](https://github.com/trufflesuite/ganache)
