Neon EVM: How to Deploy dApps Using Truffle

Neon Labs
Neon Labs
Published in
4 min readOct 5, 2022

As a developer, you know the importance of understanding how to deploy the smart contract code you’ve written onto the blockchain. Our Deploying Neon dApps article series provides this crucial information in a simple and straightforward way. This article, the second in the series, will show you how to deploy Solidity dApps using Truffle. You can also check out our articles on deploying Neon with Remix and Hardhat.

Truffle is a deployment tool, development environment, and asset pipeline that makes it easy for developers to test and debug their code on-chain. Unlike Remix, which only supports a few functions and can’t run automated tests, Truffle is an advanced and flexible tool that can support much more complex code. However, Truffle can only be used via a command-line interface and is not an IDE.

To deploy your contracts successfully, you will need to modify the publicly available Truffle configuration file, which contains the private keys for the wallets the contract interacts with. For this reason, you should only use Truffle for debugging or testing purposes and not for mainnet deployment.

Before You Begin

Before you start the tutorial below, make that the following is true:

  • MetaMask is installed on your device
  • MetaMask is configured for Neon EVM
  • NodeJS v8.9.4 or later is installed on your device
  • Git is installed on your device (on Windows, use Git Bash)

To install and configure MetaMask, follow this guide.

ERC-20 Tutorial

The following tutorial will explain how to deploy a simple ERC-20 token contract to the Neon Devnet using Truffle.

Step 1: Install Truffle

Using Git, clone the ERC-20 Truffle project from Neon’s remote repository and navigate to it with the following commands:

Then, run the following command to install Truffle and the dependencies necessary to run the example project:

If the above command results in an error, run the following command:

Step 2: Set Up the MetaMask Accounts and Configuration File

To interact with the soon-to-be-deployed contracts, you’ll need to create two new accounts in MetaMask. Before you begin, make sure that MetaMask is connected to the Neon Devnet.

In MetaMask, create two new accounts by clicking on your current account’s icon in the top right of the MetaMask extension pop-up, and then when the drop-down menu appears, click on “Create an Account”. Then, use the NeonFaucet to obtain some Devnet NEON tokens for these accounts.

Next, click on the three vertical dots to the right of your currently displayed account name and wallet address to open a drop-down menu. Select “Account Details” then “Export Private Key”. Enter your password and select “Confirm” to get access to the private key for that account. Copy both accounts’ private keys and paste them into the truffle-config.js file in the project folder, replacing the placeholder text in lines 11 and 12 of that file. Make sure to prefix these keys with “0x” in the configuration file.

Step 3: Compile Contracts

To compile the project’s contracts (which are located in the “contracts/” folder), run the following command:

The output from this command should be similar to the following:

Step 4: Run Tests

To run the project tests before deploying, run the following command. It will compile the contracts, deploy them to the Neon Devnet, and run all the tests in the “tests/” folder to make sure the contracts are working as expected.

If the tests all pass, the output of this command should look something like this:

Step 5: Run Migrations

Deploying the contracts to Neon requires running some migration scripts, which are located in the “migrations/” folder. To do this, run the following command:

You should see output in your terminal similar to the following:

Step 6: Connect the Project to MetaMask

To use this newly deployed ERC-20-style Neon Devnet token with ease, follow these instructions to import the token as an asset in MetaMask. Use the “contract address” from the output in Step 5 for the “Token Contract Address” in the instructions.

Once you complete this final step, you will be able to see your new ERC-20 assets in the MetaMask profiles of the new test accounts.

Conclusion

Truffle is a versatile, flexible solution for deploying dApps on Neon, with a lot of room for customization and playing with advanced features. However, because it has some security vulnerabilities when deploying to Neon, it remains usable only for testing and development. Therefore, while Truffle is great for Neon developers during the development process itself, the final deployment must be done with a different tool.

Visit the Neon docs for a complete tutorial on using Truffle to deploy your dApps.

--

--