# 2. Ethereum IDE 使用流程演示

## 1. 编写合约

进入项目后，文件夹中自带的 readme.md 文件会自动预览。&#x20;

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2F91jbawmqSxxnxR5xHaWN%2Fimage.png?alt=media&#x26;token=7c9ddec8-a307-4b51-b5b6-3262d85f7420" alt=""><figcaption></figcaption></figure>

在 Explorer 栏中，你可以新建文件（夹），刷新目录，下载文件。也可以直接点击模板中自带的文件。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FMgRJQONDvNgCGLYxJ58K%2Fimage.png?alt=media&#x26;token=d3c4f64e-f125-4f58-bf85-a9b03374fc94" alt=""><figcaption></figcaption></figure>

点击一个合约文件，即可对代码进行编辑操作。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FTZUdOfi3e0fVGjlhgF2Q%2Fimage.png?alt=media&#x26;token=2dd03df4-7c7a-4bba-b341-164ab7867911" alt=""><figcaption></figcaption></figure>

## 2. 编译合约

合约代码编写完成后，点击右侧菜单栏的 Compiler 按钮打开编译模块，选择 Compiler 版本和是否开启 Optimization，然后点击 Compile \*\*\*.sol 启动编译。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FtLRYlIVTGfWTNqopiXnZ%2Fimage.png?alt=media&#x26;token=ac3aba02-b1c4-4550-9392-6dea49a1486f" alt=""><figcaption></figcaption></figure>

编译成功后，下方会显示 [ABI](https://docs.soliditylang.org/en/latest/abi-spec.html) 和 BYTE CODE ，同时控制台上会输出 Compile contract success 的信息提示。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FSqtKrKS28YN7xmytaRJy%2Fimage.png?alt=media&#x26;token=6636a90b-68de-4294-a1f9-1c301a0d519a" alt="" width="326"><figcaption></figcaption></figure>

## 3. 连接 Ethereum

部署合约前，需要先点击右上角的 Connect Wallet，选择连接到 JavaScript VM (使用 JavaScript 实现的 EVM，主要用于测试) 或 Metamask （可部署到 Ethereum 区块链上）。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FUr8z4hC1Bno4csamwFla%2Fimage.png?alt=media&#x26;token=39d036f9-b40f-4a03-b825-02324d4a8ff0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2Fkbhq6dgkf2LqRqkV8utK%2Fimage.png?alt=media&#x26;token=ada7563c-bd25-4242-ad20-aa169d5359de" alt=""><figcaption></figcaption></figure>

## 4. 部署合约

点击右侧的 Deploy & Interaction 按钮，出现部署页与交互页面。选择好已编译的合约后，点击 Deploy进行部署（然后在 Metamask 中点击确认）。合约部署成功后，控制台上会输出现合约部署的结果以及相关信息。&#x20;

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FUozbEpa8YbHmdEhmpQTx%2Fimage.png?alt=media&#x26;token=d92bde9a-aba5-4732-a0af-34b3781811ca" alt=""><figcaption></figcaption></figure>

除此之外，你还可以点击 Import Deployed Contract 导入已部署过的合约，来进行合约交互。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FHCv5Eafo7dOAKNhiCCQp%2Fimage.png?alt=media&#x26;token=302cb059-1a9b-41df-aefc-906d298c1fdd" alt=""><figcaption></figcaption></figure>

## 5. 合约交互

合约部署成功后，可以对合约进行交互操作。点击已部署好的合约，选择对应的接口，点击 Submit 或 Get   进行交互。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FRQmBSmKfdvbaB9zF4hj3%2Fimage.png?alt=media&#x26;token=82a78116-cabf-482d-beb0-b1966ac746fc" alt=""><figcaption></figcaption></figure>

## 6. 交易查询

点击 Output 中的交易 Hash，可以查看每笔交易的具体信息。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FQ6KzcZv4Y4grB7GldDRx%2Fimage.png?alt=media&#x26;token=669c25bc-48c3-4199-8d81-6dc6633bbf50" alt=""><figcaption></figcaption></figure>

## 7. 验证合约

如果你想在区块链浏览器上开源你的智能合约，请参考 [ChainIDE Verifier](https://chainide.gitbook.io/chainide-chinese/4.-chainide-quan-ti-bu-ju/4.7.-cha-jian-xi-tong-mo-kuai/2.7.3-chainide-verifier) 或 [ChainIDE Flattener](https://chainide.gitbook.io/chainide-chinese/4.-chainide-quan-ti-bu-ju/4.7.-cha-jian-xi-tong-mo-kuai/2.7.2.-chainide-flattener-plugin)。

## 8. Ethereum Sandbox&#x20;

如果你喜欢使用命令行进行开发，可以打开 Ethereum Sandbox，其中已自带 [Hardhat](https://hardhat.org/), [Truffle](https://trufflesuite.com/), [Brownie](https://eth-brownie.readthedocs.io/en/stable/) [Ganache](https://trufflesuite.com/ganache/), [Git](https://git-scm.com/) and [Node.js V16](https://nodejs.org/en)。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FXYWE1ayKGhjHLkF8WRva%2Fimage.png?alt=media&#x26;token=fd00bb5a-51d5-4466-b472-7f97b3dcfd91" alt=""><figcaption></figcaption></figure>

如果你在 Sandbox 中启动了一个端口，并且想要访问该端口，请参考 [ChainIDE-端口转发](https://chainide.gitbook.io/chainide-chinese/5.-port-forwarding)。
