# Aleo Leo Playground 的使用教程

By [Yaakov](https://paragraph.com/@yaakov) · 2024-04-28

---

Aleo Leo Playground 的使用教程
=========================

Leo Playground 是 Aleo 官方开发的类似 remix 的 web 端应用程序，帮助开发者简化开发 Leo 程序的流程。

**_Leo Playground 的优势_**

*   **易于使用：** Leo Playground 为开发人员提供了一个用户友好的界面，可以轻松地编写、编译和执行 Leo 程序。
    
*   \*\*可访问性：\*\*作为一个在线平台，Leo Playground 可以通过任何网络浏览器访问，允许开发人员试验 Aleo 的编程语言，而无需安装其他软件。
    
*   \*\*代码测试：\*\*开发人员可以直接在 Leo Playground 中测试他们的 Leo 程序，以确保它们在部署到实际环境之前按预期编译和运行。
    
*   **示例程序：** Leo Playground 提供了从基础到高级的广泛示例，使开发人员能够学习和理解 Leo 和 Aleo 指令的功能。
    

使用 Leo Playground 非常直观。您可以访问从基础到高级的大量示例，让您无缝地使用 Aleo 开发程序。

    https://play.leo-lang.org
    

### 教程

#### 1\. 安装

在开始使用 Leo Playground 之前，请确保您已安装以下工具：

*   [Leo](https://developer.aleo.org/leo/installation/) : 安装Aleo的编程语言Leo，用于编写和编译Leo程序
    
*   [Aleo's transaction cannon](https://github.com/AleoHQ/tx-cannon) : 用来部署、执行和压力测试您的 Leo 程序。
    
*   [snarkOS](https://github.com/AleoHQ/snarkOS) : 安装 snarkOS 以在本地或 AWS 上启动实时开发网络。
    
*   [tmux](https://formulae.brew.sh/formula/tmux) : 安装 tmux，因为 devnet 仪表板使用它来管理节点。
    

#### 2\. 启动本地 Aleo [Devnet](https://developer.aleo.org/leo/playground#2-start-a-local-aleo-devnet)

    cd snarkOS
    ./devnet.sh
    
    Enter the total number of validators (default: 4): 4
    Do you want to run 'cargo install --path .' to build the binary? (y/n, default: y): n
    Do you want to clear the existing ledger logs? (y/n, default: n): n
    

当节点启动时，您将看到节点 0 的信息，将其复制下来！

    - 👋 Welcome to Aleo! We thank you for running a node and supporting privacy.
    - 🔑 Your development private key for node 0 is <private key>
    - 🪪 Your Aleo address is <address>
    - 🧭 Starting a validator node on Aleo Testnet 3 Phase 3 at 0.0.0.0:4130
    - 🌐 Starting the REST server at 0.0.0.0:3030
    - 🔑 Your one-time JWT token is <jwt-token>
    

如果您因为滚动太快而错过了它，请使用以下`tmux`命令向上滚动：

    ctrl+b+[  # enter scroll mode to scroll up
    ctrl+b+w  # see all 4 validator nodes
    ctrl+b+:kill-session  # kills the session
    q  # exit ctrl+b mode
    

在浏览器中使用 [http://localhost:3030/testnet3/latest/height](http://localhost:3030/testnet3/latest/height) 检查网络是否正在运行。如果区块高度在不断增加，这表明您的网络处于活动状态。

#### 3\. 在本地执行您的 Playground 项目

导航回您的 Playground 项目并使用 Leo 的命令行界面运行您的转换函数之一。在本地编译并执行Leo程序以测试其功能。

    leo run <function>
    

#### 4\. 在 Devnet 上部署您的程序

让我们将您的程序部署到您刚刚启动的本地开发网络上。

请记住，您启动了一个在 [http://localhost:3030](http://localhost:3030) 运行的干净的开发网络。我们现在要做的是将您的程序部署到该网络。

再次确保它正在运行：[http://localhost:3030/testnet3/latest/height](http://localhost:3030/testnet3/latest/height)

    cd <your-project>
    tx-cannon deploy <project>/build/<project>.aleo -k <node-private-key-you-jotted-down-earlier> --fee 3 -e http://localhost:3030
    

您可以使用以下命令检查网络上的部署是否成功： [http://localhost:3030/testnet3/transaction/](http://localhost:3030/testnet3/transaction/) 。 5. 使用交易cnnon在链上执行 一旦您的程序部署在 devnet 上，就可以轻松在链上执行您的程序。`.toml` 文件是这个程序的配置文件，您可以在存储库中找到具有不同输入的各种示例。下面显示的示例适用于`helloworld.aleo`. # helloworld.aleo \[\[step\]\] private\_keys = \["your-node-private-key"\] order = 0 program\_id = "helloworld.aleo" function = "main" inputs = \[ "5u32", "5u32" \] fee = 3 当我们调用该`tx-cannon execute`命令时，我们要求它查找我们在本地开发网络上部署的程序，并使用提供的输入和相应的私钥执行它。 tx-cannon batch-execute --test helloworld.toml -e http://localhost:3030 再次检查程序是否执行： [http://localhost:3030/testnet3/transaction/](http://localhost:3030/testnet3/transaction/) `<your-txn-id>`。 [tx-cannon 存储库](https://github.com/AleoHQ/tx-cannon)中还有更多功能有待探索。您可以批量部署、执行和传输，因此请利用此工具对您的应用程序运行开发测试！ 恭喜，您已经使用 Playground 成功将一个项目署到 Aleo Devnet 网络！ _您可以在这里找到更多信息：_ https://developer.aleo.org/leo/playground/

---

*Originally published on [Yaakov](https://paragraph.com/@yaakov/aleo-leo-playground)*
