> For the complete documentation index, see [llms.txt](https://chainide.gitbook.io/chainide-chinese/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chainide.gitbook.io/chainide-chinese/chainide/15.-starknet-ide/2.-starknet-ide-shi-yong-liu-cheng-yan-shi.md).

# 2. Starknet IDE 使用流程演示

{% embed url="<https://www.youtube.com/watch?v=31tAJcYQey0>" %}

### 1. 编写合约 <a href="#id-1.-bian-xie-he-yue" id="id-1.-bian-xie-he-yue"></a>

进入项目后，可以点击文件夹中 readme.md 右上角 preview 进行预览。

<figure><img src="/files/EGmhfsLsaO6YeF1IjEUq" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/rWMC6xqLpsOrOHwpW1Oe" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/wbxIqYLXuYU4p6L8hVBq" alt=""><figcaption></figcaption></figure>

### 2. 测试合约 <a href="#id-2.-ce-shi-he-yue" id="id-2.-ce-shi-he-yue"></a>

合约代码编写完成后，点击右侧菜单栏的 Compiler 按钮打开编译模块，选择好 Module Package Path 后点击 Test。

<figure><img src="/files/qaVg1TUihCkE3Zl8f2Sk" alt=""><figcaption></figcaption></figure>

测试成功后，同时控制台上会输出测试结果。

<figure><img src="/files/5BXIGpc56AFBp2BAH8sb" alt=""><figcaption></figcaption></figure>

### 3. 编译合约 <a href="#id-3.-bian-yi-he-yue" id="id-3.-bian-yi-he-yue"></a>

在右侧菜单栏的 Compiler 中，点击 Build 即可开始编译合约。

<figure><img src="/files/SRMq5SmYN2IeRStfIdGO" alt=""><figcaption></figcaption></figure>

编译成功后，会在当前目录下生成 target 文件夹。

<figure><img src="/files/rZL7nnzQuixyQDK2Lh68" alt=""><figcaption></figcaption></figure>

### 4. 连接到 Starknet 区块链 <a href="#id-4.-lian-jie-dao-sui-qu-kuai-lian" id="id-4.-lian-jie-dao-sui-qu-kuai-lian"></a>

部署合约前，需要先点击右上角的 Connect Wallet，选择连接 Argent X 或者 Braavos。

<figure><img src="/files/hO2RN3K5Jc6Qb5vxy08B" alt=""><figcaption></figcaption></figure>

### 5. 部署合约 <a href="#id-5.-bu-shu-he-yue" id="id-5.-bu-shu-he-yue"></a>

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

<figure><img src="/files/jg2rQMu03VGwV2kP5Wra" alt=""><figcaption></figcaption></figure>

在 Starknet 中部署智能合约需要两个步骤：

1. 声明您合约的 Class  Hash，即将您的合约代码发送到网络。
2. 部署合约，即创建您之前声明的代码的实例。

<figure><img src="/files/eOUhY756BzbEezbYFVF2" alt="" width="444"><figcaption></figcaption></figure>

如果你没有在 Select Compiled Contract 中选择合约，那么你可以上传本地已编译的文件来进行合约部署。

<figure><img src="/files/Q6mrMJHKNKQH3dsbFa66" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/wx4fNr9mMdq9VVdDG2Rm" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/xEtulrxSjrisElQoKn7B" alt=""><figcaption></figcaption></figure>

你也可以通过点击 Use On-Chain Contract Classhash，使用已经 Declare 过的 Classhash 进行部署。

<figure><img src="/files/OJDBU2GlvnWB9AHpSFr2" alt=""><figcaption></figcaption></figure>

### 6. 合约交互 <a href="#id-6.-he-yue-jiao-hu" id="id-6.-he-yue-jiao-hu"></a>

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

<figure><img src="/files/XnHsI2mdyMiRP3EG4k99" alt=""><figcaption></figcaption></figure>

## 7. 交易查询

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

<figure><img src="/files/avjUIMAHMUDPAuENaEYy" alt=""><figcaption></figcaption></figure>

### 8. Starknet Sandbox <a href="#id-8.-sui-sandbox" id="id-8.-sui-sandbox"></a>

如果你喜欢使用命令行进行开发，可以打开 Starknet Sandbox，其中已自带 [Starkli](https://github.com/xJonathanLEI/starkli), [Scarb](https://github.com/software-mansion/scarb), [Dojo](https://github.com/dojoengine/dojo), [Starknet Foundry](https://github.com/foundry-rs/starknet-foundry)**,** [Git](https://git-scm.com/) 和 [Node.js V16](https://nodejs.org/en)。

<figure><img src="/files/WNGYG206WHXn9Mv0uBvf" alt=""><figcaption></figcaption></figure>

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