Learn how to create an Avalanche L1 with a custom virtual machine and deploy it locally.
This tutorial walks through the process of creating an Avalanche L1 with a custom virtual machine and deploying it locally. Although the tutorial uses a fork of Subnet-EVM as an example, you can extend its lessons to support any custom VM binary.
To prove you're running your custom binary and not the stock Subnet-EVM included with Avalanche-CLI, you need to modify the Subnet-EVM binary by making a minor change.
Navigate to the directory you cloned Subnet-EVM into and generate a new commit:
Take note of the new commit hash:
In this case, c0fe6506a40da466285f37dd0d3c044f494cce32.
Now build your custom binary by running:
This command builds the binary and saves it at ./custom_vm.bin.
To start a VM, you need to provide a genesis file. Here is a basic Subnet-EVM genesis that's compatible with your custom VM.
Open a text editor and copy the preceding text into a file called custom_genesis.json. For full breakdown of the genesis file, see the Genesis File.
Note
The timestamp field is the Unix timestamp of the genesis block. 0x66321C34 represents
the timestamp 1714560052 which is the time this tutorial was written. You should use the
timestamp when you create your genesis file.
Now that you have your binary, it's time to create the Avalanche L1 configuration. This tutorial uses myblockchain as it Avalanche L1 name. Invoke the Avalanche L1 Creation Wizard with this command:
To deploy your Avalanche L1, run: avalanche blockchain deploy myblockchain
Make sure to substitute the name of your Avalanche L1 if you used a different one than myblockchain.
Next, select Local Network:
This command boots a five node Avalanche network on your machine. It needs to download the latest versions of AvalancheGo and Subnet-EVM. The command may take a couple minutes to run.
If all works as expected, the command output should look something like this:
You can use the RPC URL to connect to and interact with your Avalanche L1.
You can verify that your Avalanche L1 has deployed correctly by querying the local node to see what Avalanche L1s it's running. You need to use the getNodeVersion endpoint. Try running this curl command:
The command returns a list of all the VMs your local node is currently running along with their versions.
Your results may be slightly different, but you can see that in addition to the X-Chain's avm, the C-Chain's evm, and the P-Chain's platform VM, the node is running the custom VM with commit c0fe6506a40da466285f37dd0d3c044f494cce32.
If you used the default genesis, your custom VM has a prefunded address. You can verify its balance with a curl command. Make sure to substitute the command's URL with the RPC URL from your deployment output.
The command should return:
The balance is hex encoded, so this means the address has a balance of 1 million tokens.
Note, this command doesn't work on all custom VMs, only VMs that implement the EVM's eth_getBalance interface.