# 2. Conflux 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%2FwDsn3PXqaJCF3Ng5TRkt%2Fimage.png?alt=media&#x26;token=cbbac37d-a930-4dd6-8edb-54aee534feb3" 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%2FvAGVuhKcmGomYw4IU1Cc%2Fimage.png?alt=media&#x26;token=c6f4485d-f37f-41f8-81e0-c74e4bc5b500" 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. 连接 Conflux

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

<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%2FC3MPpNjVxCDmHZ3laHbj%2Fimage.png?alt=media&#x26;token=a0568ff0-5e70-4c7a-bf42-9d02dd859aa9" alt=""><figcaption></figcaption></figure>

连接 Metamask 或 Fluent Wallet 后，右下角会出现 banner 引导你连接到 Conflux。

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2FscpToB6OV7Sie2SKSNQn%2Fimage.png?alt=media&#x26;token=28bbd07a-52d2-43d2-ba95-8935f21c9f34" 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%2Fp9G2gtM9OSkOAMYMM6kP%2Fimage.png?alt=media&#x26;token=18acd3a1-7987-43ca-bfba-d649f109a249" alt=""><figcaption></figcaption></figure>

## 4. 部署合约

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

<figure><img src="https://2772835953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZ6_j0WUFnBhwIdP3LR%2Fuploads%2Fac1dGEp8NtALnLwWoyVp%2Fimage.png?alt=media&#x26;token=ef59f4b5-08bb-4df8-9ef1-e2aeb3dded97" 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%2FPI8kVeMprLwu2HpMoBPa%2Fimage.png?alt=media&#x26;token=bf275411-6553-4d66-a843-79406ee71b54" 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%2FKnntwiMLbZn1wbvzMVXP%2Fimage.png?alt=media&#x26;token=01131127-38ec-4667-a476-b00e9cf92175" 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%2FtMGTzHXt0OIrrDFsg11M%2Fimage.png?alt=media&#x26;token=db523d99-5f1a-4905-ab0f-ea5f6eddbe09" 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. Conflux Chain Sandbox&#x20;

如果你喜欢使用命令行进行开发，可以打开 Conflux Chain Sandbox，其中已自带 [Conflux Truffle](https://github.com/Conflux-Chain/conflux-truffle),  [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%2FGf55mXcIU8ta7laqXzgv%2Fimage.png?alt=media&#x26;token=3dfa4bcd-a59f-4096-b1b3-0ee2cda7cac9" alt=""><figcaption></figcaption></figure>

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