Learn how to create a Subnet with a custom virtual machine and deploy it locally.
This tutorial walks through the process of creating a Subnet 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:
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 Subnet configuration. This tutorial uses myblockchain as it Subnet name. Invoke the Subnet Creation Wizard with this command:
To deploy your Subnet, run: avalanche blockchain deploy myblockchain
Make sure to substitute the name of your Subnet if you used a different one than myblockchain.
Next, select Local Network:
Use the arrow keys to navigate: ↓ ↑ → ←? Choose a network to deploy on: ▸ Local Network Fuji Mainnet
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:
> avalanche blockchain deploy myblockchain✔ Local NetworkDeploying [myblockchain] to Local NetworkBackend controller started, pid: 26110, output at: /home/fm/.avalanche-cli/runs/server_20230816_131014/avalanche-cli-backend.logInstalling avalanchego-v1.10.8...avalanchego-v1.10.8 installation successfulNode log path: /home/fm/.avalanche-cli/runs/network_20230816_131608/node<i>/logsStarting network...VMs ready.Blockchain has been deployed. Wait until network acknowledges...Network ready to use. Local network node endpoints:+-------+----------------+------------------------------------------------------------------------------------+-------------------------------------------------+| NODE | VM | URL | ALIAS URL |+-------+----------------+------------------------------------------------------------------------------------+-------------------------------------------------+| node1 | myblockchain | http://127.0.0.1:9650/ext/bc/z9a7L6XmFYskbaHuuLFCxThByKg4xqsYYbaqT5ke6xVutDQTp/rpc | http://127.0.0.1:9650/ext/bc/myblockchain/rpc |+-------+----------------+------------------------------------------------------------------------------------+-------------------------------------------------+| node2 | myblockchain | http://127.0.0.1:9652/ext/bc/z9a7L6XmFYskbaHuuLFCxThByKg4xqsYYbaqT5ke6xVutDQTp/rpc | http://127.0.0.1:9652/ext/bc/myblockchain/rpc |+-------+----------------+------------------------------------------------------------------------------------+-------------------------------------------------+| node3 | myblockchain | http://127.0.0.1:9654/ext/bc/z9a7L6XmFYskbaHuuLFCxThByKg4xqsYYbaqT5ke6xVutDQTp/rpc | http://127.0.0.1:9654/ext/bc/myblockchain/rpc |+-------+----------------+------------------------------------------------------------------------------------+-------------------------------------------------+| node4 | myblockchain | http://127.0.0.1:9656/ext/bc/z9a7L6XmFYskbaHuuLFCxThByKg4xqsYYbaqT5ke6xVutDQTp/rpc | http://127.0.0.1:9656/ext/bc/myblockchain/rpc |+-------+----------------+------------------------------------------------------------------------------------+-------------------------------------------------+| node5 | myblockchain | http://127.0.0.1:9658/ext/bc/z9a7L6XmFYskbaHuuLFCxThByKg4xqsYYbaqT5ke6xVutDQTp/rpc | http://127.0.0.1:9658/ext/bc/myblockchain/rpc |+-------+----------------+------------------------------------------------------------------------------------+-------------------------------------------------+Browser Extension connection details (any node URL from above works):RPC URL: http://127.0.0.1:9650/ext/bc/z9a7L6XmFYskbaHuuLFCxThByKg4xqsYYbaqT5ke6xVutDQTp/rpc
You can use the RPC URL to connect to and interact with your Subnet.
You can verify that your Subnet has deployed correctly by querying the local node to see what Subnets it's running. You need to use the getNodeVersion endpoint. Try running this curl command:
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.