Introduction
Welcome to this guide on building a subnet on a local network using Avalanche CLI and GitHub Codespaces! If you're curious about Avalanche or want to dive deeper into blockchain development, you're in the right place.
Avalanche is a fast, scalable blockchain platform that supports custom networks called subnets. These subnets operate independently but benefit from Avalanche's overall security and speed. Subnets are crucial for creating tailored blockchain environments, whether for development, testing, or specific applications. If you want to know more about Avalanche Subnet, go visit my article on Avalanche Subnets. Reading this article will help you understand about Avalanche subnets more.
Now, in this article, we will learn to create our very own subnet on a local environment using GitHub codespace and Avalanche-CLI.
If you want to check a more user-friendly approach on how to create a subnet, don't forget to check out my article on how to create a subnet without using code.
Now let's move on to our main topic and start the creation of a subnet using Avalanche-CLI.
Set up the deployment environment
Avalanche officials provide us with an Avalanche Starter Kit. The Avalanche Starter Kit contains mostly all of the tools that one will need to get started quickly with Avalanche. Avalanche CLI is also among the tools it provides. Using it, you may configure a virtual machine (VM), build a subnet, and set up a local network, among other things.
To use the Avalanche Starter Kit, you need to open the Avalanche Starter Kit GitHub Repository.
After opening the GitHub repository.
- Click the green button on the right side and write Code on it.
- Open the codespace tab inside it and click on the button Create codespace on main to start a new codespace.
It may take some time to start the codespace.
Once opened, just verify if everything is working fine or not.
Open up the terminal and then type avalanche. If everything is fine it will show up some commands.
With this, you are ready to create your own subnet.
Create your Subnet
To start with the creation of a subnet, you need to run the command given below.
avalanche subnet create <subnetName>
Substitute <subnetName> with any desired name for your subnet. For example:
avalanche subnet create MyFirstSubnet
Here, MyFirstSubnet is the name for the subnet that I will be creating.
After running this command, there will be a wizard that will ask you to set some configurations for your subnet installation. This time we will be moving with basic configurations, so,
- Choose your VM: Subnet-EVM
- Which version of Subnet EVM would you like?: Use the latest release version
- Would you like to enable Teleporter on your VM?: Yes
- Would you like to run AMW Relayer when deploying your VM?: Yes
After the installation is completed, provide some basic configurations for attributes like.
- Chain ID: Any random positive number. Eg. 9889
- Token Symbol: Eg. MFS
- How would you like to set fees: Low disk use / Low Throughput 1.5 mil gas/s (C-Chain's setting) (the first option)
- How would you like to distribute funds: Airdrop 1 million tokens to the default ewoq address (second option)
- Would you like to add a custom precompile to modify the EVM?: No
With all these configurations, your subnet will be installed and ready to be deployed.
To view the configurations of your subnet, type the command
avalanche subnet describe <subnetName>
Just replace the subnetName with the name of your subnet whose configuration you wanted to view. In my case, the command would be:
avalanche subnet describe MyFirstSubnet
Running the command will provide some output like:
Start your Local Network(optional)
Moving forward, before deploying your subnet, you need to start your local network.
Open up a new terminal and type the command:
avalanche network start
Running this command will show you some output like this:
You can check your network whether it is running or not by simply running a command:
avalanche network status
If you don't start your network manually it will be automatically started when you deploy your first Subnet.
Deploy your Subnet
To deploy your subnet run the command:
avalanche subnet deploy <subnetName>
When asked to select the network, select the Local Network to deploy the subnet on.
The deployment process will start, and after it is done, your screen should look like this:
The endpoints of your five nodes are included in this output, which you may use to connect and communicate with your subnet. Since you are using a Subnet-EVM, you may connect to wallets and tools that are compatible with EVM by using those RPC URLs.
Please keep in mind that because the Avalanche Network is running in a Github Codespace, the localhost (127.0.0.1) will only be accessible from within the Codespace, so connecting your wallet with the localhost RPC URL will fail because your wallet will be running in the host's local environment (your PC), not the network's local environment (the Codespace cloud). In the following stages, we will show you how to link your wallet.
Add your Created Subnet to your Wallet
To add the subnet to your wallet, you need to make the RPC endpoints available/public. By default, it is set to private.
Codespaces do not make ports accessible to the public by default. While they may be accessed via the command line, we prefer to use a wallet, such as Core, on our PC. As a result, we need to ensure that the RPC endpoint is callable.
Let's make the port public, to do so, click on the antenna symbol in the bottom bar, then right-click on the row labelled Node-1 (9650). There, go to Port Visibility and choose Public.
Now anyone can connect and interact with your node that is running in the Avalanche Starter Kit Codespace.
Finally, Add Blockchain to your wallet
Open Core Wallet and choose the arrow on the top right. In the popup, select Manage Networks. From there, click the + sign to add your own network.
If you want to know about core wallet and how to set up core wallet, feel free to read the article How to Set Up Core Crypto Wallet? and get your wallet ready.
Fill in the network details along with the RPC Url of the Codespace ( not the referencing localhost ) and click on Save to connect.
Conclusion
Congratulations! You've successfully built and deployed your subnet using Avalanche CLI and GitHub Codespaces. This guide has walked you through setting up your environment, creating a subnet, and connecting it to your wallet.
Subnets are key to Avalanche's flexibility, enabling customized blockchain environments. Keep exploring and experimenting with different configurations to fully harness the power of Avalanche.
Thanks for following along, and happy building! If you have any questions, feel free to reach out by leaving a comment.
FAQs
Q. What is a subnet in Avalanche?
Ans. A subnet in Avalanche is a smaller, custom network within the larger Avalanche blockchain ecosystem. It allows for specialized configurations and can operate independently while benefiting from Avalanche's security and scalability.
Q. How do I create a subnet using Avalanche CLI?
Ans. To create a subnet using Avalanche CLI, you first need to set up your development environment with GitHub Codespaces. Then, use the command avalanche subnet create <subnetName> and follow the prompts to configure and deploy your subnet.
Q. Can I connect my wallet to a subnet running in GitHub Codespaces?
Ans. Yes, you can connect your wallet to a subnet running in GitHub Codespaces by making the RPC endpoints public. This allows your wallet to interact with the subnet nodes, even though the network is hosted in the Codespace environment.