Neon EVM:如何用Remix部署dApps (Neon EVM: How to Deploy dApps Using Remix)


Deploying a decentralized application, or dApp for short, is the final stage of any developer’s process of bringing their vision of a crypto project to reality. Neon’s features as an Ethereum Virtual Machine (EVM) on Solana make it suitable for cheap and simple deployment of dApps written in Solidity. In this article series about dApp deployment, we will illustrate how to deploy a simple “Hello World” dApp using three different deployment tools: Remix, Truffle, and Hardhat.

部署去中心化应用(简称 dApp),是开发人员将他们的加密项目愿景变为现实的最后阶段。 Neon 作为 Solana 上以太坊虚拟机 (EVM) 的功能,使其适用于以 Solidity 编写的低成本且简单的 dApp 部署。在这个关于 dApp 部署的系列文章中,我们将说明如何使用三种不同的部署工具(Remix、Truffle 和 Hardhat)来部署一个简单的“Hello World”dApp:。

This article will focus on deploying dApps with Remix. Remix is an online IDE for Solidity programs and can be used to run code without any local installation. This makes it convenient for deploying dApps from anywhere, so long as the user has the contract source code. However, since it is an online environment, its capacity for supporting large, complex projects is limited. Therefore, Remix should be used primarily for simple code, which can be deployed with ease and requires minimal dependency management.

本文将重点介绍使用 Remix 部署 dApp。 Remix 是 Solidity 程序的在线 IDE,无需任何本地安装即可运行代码。这使得从任何地方部署 dApp 变得很方便,只要用户有合约源代码。然而,由于它是一个在线环境,它支持大型、复杂项目的能力是有限的。因此,Remix 主要用于简单的代码,可以轻松部署并且需要最少的依赖管理。

开始之前 Before You Begin

Before you start the tutorial below, make sure that the following is true:
在开始下面的教程之前,请确保满足以下条件:

  • MetaMask is installed on your device.
    MetaMask 已安装在您的设备上。

  • MetaMask is configured for the Neon EVM.
    MetaMask 是为 Neon EVM 配置的。

To install and configure MetaMask, follow this guide.
要安装和配置 MetaMask,请参照 本指南

“你好,世界”指南 (Hello World Tutorial)

The following tutorial will explain how to deploy a simple Hello World contract to the Neon Devnet using Remix.

以下教程将解释如何使用 Remix 将简单的 Hello World 合约部署到 Neon Devnet。

Step 1: Create a Simple Smart Contract in Remix
第 1 步:在 Remix 中创建一个简单的智能合约

To add a smart contract to Remix, go to https://remix.ethereum.org, click on the “Create New File” icon, and type “helloWorld.sol” in the field that appears. Then, paste the following code into the empty file and press CTRL+S to save the smart contract file.

要将智能合约添加到 Remix,请转到 https://remix.ethereum.org,单击“创建新文件(Create New File)”图标,然后输入“helloWorld.sol ”在出现的字段中。然后,将以下代码粘贴到空文件中,然后按 CTRL+S 保存智能合约文件。

// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.7;

contract helloWorld {

string public text = "Hello World!";

function callHelloWorld() public view returns (string memory) {

return text;

}

}

The process should look like in the image below (Fig. 1).
流程如图1所示:

图 1—加载 helloWorld 智能合约 (Fig. 1 — Loading the helloWorld smart contract)


Step 2: Compile the Smart Contract
第 2 步:编译智能合约

Before the smart contract can be deployed, it must first be compiled. To accomplish this, select the “Solidity compiler” tab in the left side menu. The SOLIDITY COMPILER menu will appear.

在部署智能合约之前,必须先对其进行编译。为此,请在左侧菜单中选择“Solidity 编译器(Solidity compiler)”选项卡。将出现 SOLIDITY 编译器菜单。

Click on the Compile helloWorld.sol button to compile the smart contract (Fig. 2).

点击 Compile helloWorld.sol 按钮编译智能合约(图 2)。

If the compilation is successful, a green icon will appear near the Solidity compiler button.

如果编译成功,Solidity 编译器按钮附近会出现一个绿色图标。

图 2—编译 helloWorld 智能合约 (Fig. 2 — Compiling helloWorld smart contract)


Step 3: Connect Remix to MetaMask
第 3 步:将 Remix 连接到 MetaMask

Interactions between Remix and the Neon EVM are carried out through MetaMask. Before connecting Remix to MetaMask, select “Deploy & run transactions” in the left sidebar menu. The DEPLOY & RUN TRANSACTIONS menu will appear.

Remix 和 Neon EVM 之间的交互是通过 MetaMask 进行的。在将 Remix 连接到 MetaMask 之前,请在左侧边栏菜单中选择“部署并运行交易(Deploy & run transactions)”。 接着部署并运行交易(DEPLOY & RUN TRANSACTIONS)菜单将会出现。

Choose the “Injected Provider — Metamask” environment to connect Remix with an active account in MetaMask (Fig. 3). Make sure that your MetaMask wallet is set to display the Neon Devnet network before you complete this step.

选择“Injected Provider - Metamask”环境以将 Remix 与 MetaMask 中的活动帐户连接起来(图 3)。在完成此步骤之前,请确保您的 MetaMask 钱包已设置为显示 Neon Devnet 网络。

选择“Injected Provider - Metamask”环境,将 Remix 与 MetaMask 中的活动帐户连接起来(图 3)。在完成此步骤之前,请确保您的 MetaMask 钱包已设置为显示 Neon Devnet 网络。

Once you do this, the MetaMask pop-up window should appear. It will display a list of available accounts, if you have multiple accounts. Choose your desired account and click “Next”. Then, click “Connect” to connect to this account.

完成此操作后,应出现 MetaMask 弹出窗口。如果您有多个帐户,它将显示可用帐户列表。选择您想要的帐户,然后单击“下一步(Next)”。然后,单击“连接(Connect)”连接到该帐户。

图 3—“Injected Provider” 将 Remix 与 Metamask 中的活动帐户连接起来 (Fig. 3 — “Injected Provider” connects Remix with an active account in Metamask)


Step 4: Deploy a Smart Contract on Solana Devnet
第 4 步:在 Solana Devnet 上部署智能合约

The contract is finally ready to be deployed by clicking the “Deploy” button (Fig. 4).

通过单击“部署(Deploy)”按钮,合约终于可以部署了(图 4)。

图 4—部署智能合约 (Fig. 4 — Deploying the smart contract)

MetaMask will send a notification in the form of a pop-up window to confirm the transaction. Click “Confirm” to execute it.

MetaMask 会以弹窗的形式发送通知以确认交易。点击“确认(Confirm)”执行。

If all the above steps have been completed successfully, a green icon will appear near the “Deploy & run transactions” button. The contract’s methods will now be present as buttons under the “Deployed Contracts” section (Fig. 5).

如果上述所有步骤均已成功完成,“部署并运行交易(Deploy & run transactions)”按钮附近将出现一个绿色图标。合约的方法现在将显示为“已部署合约(Deployed Contracts)”部分下的按钮(图 5)。

图 5—Remix 面板的最终视图 (Fig. 5 — Final view of the Remix panel)

Finally, to obtain the desired ‘Hello World’ functionality, click on the “callHelloWorld” button, which will return the string “Hello World!” (Fig. 6).

最后,要获得所需的“Hello World”功能,请单击“callHelloWorld(callHelloWorld)”按钮,该按钮将返回字符串“Hello World!” (图 6)。

图 6—调用智能合约方法 (Fig. 6 — Calling the smart contract methods)

结论 (Conclusion)

Fortunately for Solidity developers new to using Neon, Remix is a quick and easy solution for contract deployment. It allows this deployment to occur from any device and does not require any specific local installations or settings. However, as it is an online IDE, its security is limited (don’t include any mainnet private keys in your contract code here!) and it will not work well with large projects. Therefore, Remix is best for testing smaller contracts when a quick check is desired.

Remix 是一种快速简便的合约部署解决方案,这对于刚开始使用 Neon 的 Solidity 开发人员来说是幸运的。它允许从任何设备进行部署,并且不需要任何特定的本地安装或设置。然而,由于它是一个在线 IDE,它的安全性是有限的(不要在你的合约代码中包含任何主网私钥!)并且它不适用于大型项目。因此,当需要快速检查时,Remix 最适合测试较小的合约。

Visit our docs for a complete tutorial on using Remix to deploy your dapps.

请访问我们的 文档,获取有关使用 Remix 部署 dapp 的完整教程。

赞赏