Create a Blockchain Running the AVM

Introduction

One of the core features of Avalanche is the ability to create new blockchains. Avalanche supports the creation of new instances of the Avalanche Virtual Machine (AVM). In this tutorial, we’ll create a blockchain by creating a new instance of the AVM.
If you're interested in building custom blockchains, see Create a Virtual Machine (VM) and Create a Custom Blockchain.
Note: IDs of Blockchains, Subnets, Transactions and Addresses can be different for each run/network. It means that some inputs, endpoints etc. in the tutorial can be different when you try.

Prerequisites

You will need a running node, a user on the node, and some AVAX in the address controlled by the user. All of that is covered in the Run an Avalanche Node tutorial.
Next, you need to have your node be a validator on the Primary Network. You can find out how to do that in the Add a Validator tutorial. It is recommended you do that with API calls, since that is the way you will be interacting with your node in the rest of this tutorial.

Create the Subnet

Every blockchain is validated by a subnet. Before you can create a blockchain, you’ll need a subnet to validate it. You can also use a subnet that already exists if you have a sufficient number of its control keys.

Add Validators to the Subnet

The subnet needs validators in it to, well, validate blockchains.

Create the Genesis Data

Each blockchain has some genesis state when it’s created. Each VM defines the format and semantics of its genesis data. The AVM and Coreth have a static API method named buildGenesis that takes in a JSON representation of a blockchain’s genesis state and returns the byte representation of that state.
The AVM’s documentation specifies that the argument to avm.buildGenesis should look like this:
1
{
2
"genesisData":
3
{
4
"assetAlias1": { // Each object defines an asset
5
"name": "human readable name",
6
"symbol":"AVAL", // Symbol is between 0 and 4 characters
7
"initialState": {
8
"fixedCap" : [ // Choose the asset type.
9
{ // Can be "fixedCap", "variableCap"
10
"amount":1000, // At genesis, address A has
11
"address":"A" // 1000 units of asset
12
},
13
{
14
"amount":5000, // At genesis, address B has
15
"address":"B" // 1000 units of asset
16
},
17
... // Can have many initial holders
18
]
19
}
20
},
21
"assetAliasCanBeAnythingUnique": { // Asset alias can be used in place of assetID in calls
22
"name": "human readable name", // names need not be unique
23
"symbol": "AVAL", // symbols need not be unique
24
"initialState": {
25
"variableCap" : [ // No units of the asset exist at genesis
26
{
27
"minters": [ // The signature of A or B can mint more of
28
"A", // the asset.
29
"B"
30
],
31
"threshold":1
32
},
33
{
34
"minters": [ // The signatures of 2 of A, B and C can mint
35
"A", // more of the asset
36
"B",
37
"C"
38
],
39
"threshold":2
40
},
41
... // Can have many minter sets
42
]
43
}
44
},
45
... // Can list more assets
46
}
47
}
Copied!
To create the byte representation of this genesis state, call avm.buildGenesis. Your call should look like the one below. Note that AVAX does not exist on custom blockchains, but you'll still need a way to pay for transaction fees on this new chain. On custom AVM instances, the transaction fees are denominated in the first asset specified in the genesisData. In this example, fees are paid with asset1 (named myFixedCapAsset.) Make sure that you put enough amount to cover for fees. The default transaction fee is 1,000,000 of whatever asset the fees are denominated in. More information about fees can be found here.
Note that this call is made to the AVM’s static API endpoint, /ext/vm/avm:
1
curl -X POST --data '{
2
"jsonrpc": "2.0",
3
"id" : 1,
4
"method" : "avm.buildGenesis",
5
"params" : {
6
"genesisData": {
7
"asset1": {
8
"name": "myFixedCapAsset",
9
"symbol":"MFCA",
10
"initialState": {
11
"fixedCap" : [
12
{
13
"amount":100000000,
14
"address": "avax1dmrwka6uck44zkaamagq46hhntta67yxfy9h9z"
15
},
16
{
17
"amount":100000000,
18
"address": "avax1u4uvatmymlue3zf4w0admnyj6vsw9mqk7hjckl"
19
},
20
{
21
"amount":5000000,
22
"address": "avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70"
23
},
24
{
25
"amount":5000000,
26
"address": "avax1hzrwdlpum8xmt3pgstejx4sz86ajylmmaylspc"
27
}
28
]
29
}
30
},
31
"asset2": {
32
"name": "myVarCapAsset",
33
"symbol":"MVCA",
34
"initialState": {
35
"variableCap" : [
36
{
37
"minters": [
38
"avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70",
39
"avax1hzrwdlpum8xmt3pgstejx4sz86ajylmmaylspc"
40
],
41
"threshold":1
42
},
43
{
44
"minters": [
45
"avax1je76jegcc0qylnz473ag9l5ywvhe8we8e5qw0k",
46
"avax1y9sull9tpaz9s507uekmm4sejwvndrela0mu43",
47
"avax1grn5kuzalzek7uk405fmgae06ly8cw52ms070k"
48
],
49
"threshold":2
50
}
51
]
52
}
53
}
54
}
55
}
56
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/vm/avm
Copied!
This returns the byte representation of your blockchain’s genesis state:
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"bytes": "111TNWzUtHKoSvxohjyfEwE2X228ZDGBngZ4mdMUVMnVnjtnawW1b1zbAhzyAM1v6d7ECNj6DXsT7qDmhSEf3DWgXRj7ECwBX36ZXFc9tWVB2qHURoUfdDvFsBeSRqatCmj76eZQMGZDgBFRNijRhPNKUap7bCeKpHDtuCZc4YpPkd4mR84dLL2AL1b4K46eirWKMaFVjA5btYS4DnyUx5cLpAq3d35kEdNdU5zH3rTU18S4TxYV8voMPcLCTZ3h4zRsM5jW1cUzjWVvKg7uYS2oR9qXRFcgy1gwNTFZGstySuvSF7MZeZF4zSdNgC4rbY9H94RVhqe8rW7MXqMSZB6vBTB2BpgF6tNFehmYxEXwjaKRrimX91utvZe9YjgGbDr8XHsXCnXXg4ZDCjapCy4HmmRUtUoAduGNBdGVMiwE9WvVbpMFFcNfgDXGz9NiatgSnkxQALTHvGXXm8bn4CoLFzKnAtq3KwiWqHmV3GjFYeUm3m8Zee9VDfZAvDsha51acxfto1htstxYu66DWpT36YT18WSbxibZcKXa7gZrrsCwyzid8CCWw79DbaLCUiq9u47VqofG1kgxwuuyHb8NVnTgRTkQASSbj232fyG7YeX4mAvZY7a7K7yfSyzJaXdUdR7aLeCdLP6mbFDqUMrN6YEkU2X8d4Ck3T"
5
},
6
"id": 1
7
}
Copied!

Create the Blockchain

Now let’s create the new blockchain. To do so, we call platform.createBlockchain. Your call should look like the one below. You have to change subnetID to the subnet that will validate your blockchain, and supply a username that controls a sufficient number of the subnet’s control keys. As a reminder, you can find out what a subnet’s threshold and control keys are by calling platform.getSubnets.
1
curl -X POST --data '{
2
"jsonrpc": "2.0",
3
"method": "platform.createBlockchain",
4
"params" : {
5
"subnetID": "KL1e8io1Zi2kr8cTXxvi321pAzfQuUa8tmBfadqpf9K2dc2TT",
6
"vmID":"avm",
7
"name":"My new AVM",
8
"genesisData": "111TNWzUtHKoSvxohjyfEwE2X228ZDGBngZ4mdMUVMnVnjtnawW1b1zbAhzyAM1v6d7ECNj6DXsT7qDmhSEf3DWgXRj7ECwBX36ZXFc9tWVB2qHURoUfdDvFsBeSRqatCmj76eZQMGZDgBFRNijRhPNKUap7bCeKpHDtuCZc4YpPkd4mR84dLL2AL1b4K46eirWKMaFVjA5btYS4DnyUx5cLpAq3d35kEdNdU5zH3rTU18S4TxYV8voMPcLCTZ3h4zRsM5jW1cUzjWVvKg7uYS2oR9qXRFcgy1gwNTFZGstySuvSF7MZeZF4zSdNgC4rbY9H94RVhqe8rW7MXqMSZB6vBTB2BpgF6tNFehmYxEXwjaKRrimX91utvZe9YjgGbDr8XHsXCnXXg4ZDCjapCy4HmmRUtUoAduGNBdGVMiwE9WvVbpMFFcNfgDXGz9NiatgSnkxQALTHvGXXm8bn4CoLFzKnAtq3KwiWqHmV3GjFYeUm3m8Zee9VDfZAvDsha51acxfto1htstxYu66DWpT36YT18WSbxibZcKXa7gZrrsCwyzid8CCWw79DbaLCUiq9u47VqofG1kgxwuuyHb8NVnTgRTkQASSbj232fyG7YeX4mAvZY7a7K7yfSyzJaXdUdR7aLeCdLP6mbFDqUMrN6YEkU2X8d4Ck3T",
9
"username":"USERNAME GOES HERE",
10
"password":"PASSWORD GOES HERE"
11
},
12
"id": 1
13
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/P
Copied!
The response contains the transaction ID:
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"txID": "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH",
5
"changeAddr": "P-avax103y30cxeulkjfe3kwfnpt432ylmnxux8r73r8u"
6
},
7
"id": 1
8
}
Copied!

Verify Success

After a few seconds, the transaction to create our blockchain should have been accepted and the blockchain should exist (assuming the request was well-formed, etc.)
To check, call platform.getBlockchains. This returns a list of all blockchains that exist.
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"method" :"platform.getBlockchains",
5
"params" :{}
6
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/P
Copied!
The response confirms that the blockchain was created:
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"blockchains": [
5
{
6
"id": "AXerNQX7voY2AABaRdTAyXcawBURBR6thPRJp43LtPpZZi6Qz",
7
"name": "X-Chain",
8
"subnetID": "11111111111111111111111111111111LpoYY",
9
"vmID": "jvYyfQTxGMJLuGWa55kdP2p2zSUYsQ5Raupu4TW34ZAUBAbtq"
10
},
11
{
12
"id": "tZGm6RCkeGpVETUTp11DW3UYFZmm69zfqxchpHrSF7wgy8rmw",
13
"name": "C-Chain",
14
"subnetID": "11111111111111111111111111111111LpoYY",
15
"vmID": "mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6"
16
},
17
{
18
"id": "sw813hGSWH8pdU9uzaYy9fCtYFfY7AjDd2c9rm64SbApnvjmk",
19
"name": "My new TSVM",
20
"subnetID": "KL1e8io1Zi2kr8cTXxvi321pAzfQuUa8tmBfadqpf9K2dc2TT",
21
"vmID": "tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH"
22
},
23
{
24
"id": "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH",
25
"name": "My new AVM",
26
"subnetID": "KL1e8io1Zi2kr8cTXxvi321pAzfQuUa8tmBfadqpf9K2dc2TT",
27
"vmID": "jvYyfQTxGMJLuGWa55kdP2p2zSUYsQ5Raupu4TW34ZAUBAbtq"
28
}
29
]
30
},
31
"id": 1
32
}
Copied!

Validating the Blockchain

Every blockchain needs a set of validators to validate and process transactions on it. You can check if a node is validating a given blockchain by calling platform.getBlockchainStatus on that node:
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"method" :"platform.getBlockchainStatus",
5
"params" :{
6
"blockchainID":"xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH"
7
}
8
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/P
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"status": "Validating"
5
},
6
"id": 1
7
}
Copied!
If it responds "Validating", the node is validating the given chain. If it responds "Syncing", then the chain tracked by this node but it is not validating. If it responde "Created" then the chain exists but it is not being synced. Note that in order to validate or watch a subnet, you need to start your node with argument --whitelisted-subnets=[subnet ID goes here] (e.g. --whitelisted-subnets=KL1e8io1Zi2kr8cTXxvi321pAzfQuUa8tmBfadqpf9K2dc2TT) as well as add the node to the subnet's validator set.
More information can be found in the Adding a Subnet Validator tutorial.

Interacting with the New Blockchain

You can interact with this new instance of the AVM almost the same way you’d interact with the X-Chain. There are some small differences:
    The API endpoint of your blockchain is 127.0.0.1:9650/ext/bc/xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH. The last part in the endpoint is the blockchain ID. This can be a different ID when you create your blockchain. You can also alias this chain ID with myxchain for simpler API URLs. More information:
    Addresses are prepended with custom blockchain's ID xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH- rather than X-. This can be a different ID when you create your blockchain.
    Fees are paid with the first asset specified in the genesis data, as noted above, rather than AVAX...

Verify Balance

In the genesis data we specified that address avax1dmrwka6uck44zkaamagq46hhntta67yxfy9h9z has 100,000,000 units of the asset with alias asset1. Let’s verify that:
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"method" :"avm.getBalance",
5
"params" :{
6
"address":"xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax1dmrwka6uck44zkaamagq46hhntta67yxfy9h9z",
7
"assetID":"asset1"
8
}
9
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"balance": "100000000",
5
"utxoIDs": [
6
{
7
"txID": "9tKDkdk4PUj3GW3tw6fuYywVRwP5gXDj7XTEuPkmLAhauPN8a",
8
"outputIndex": 0
9
}
10
]
11
},
12
"id": 1
13
}
Copied!

Send Asset

Let's send some asset1 to another address. First, create a recipient address:
1
curl -X POST --data '{
2
"jsonrpc": "2.0",
3
"method": "avm.createAddress",
4
"params": {
5
"username":"USERNAME GOES HERE",
6
"password":"PASSWORD GOES HERE"
7
},
8
"id": 1
9
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"address": "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax1u4uvatmymlue3zf4w0admnyj6vsw9mqk7hjckl"
5
},
6
"id": 1
7
}
Copied!
Now let's send 1 unit of asset1 to the new address with avm.send.
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"method" :"avm.send",
5
"params" :{
6
"assetID" : "asset1",
7
"amount" : 1,
8
"from" : ["xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax1dmrwka6uck44zkaamagq46hhntta67yxfy9h9z"],
9
"to" : "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax1u4uvatmymlue3zf4w0admnyj6vsw9mqk7hjckl",
10
"changeAddr": "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax1dmrwka6uck44zkaamagq46hhntta67yxfy9h9z",
11
"username": "USERNAME GOES HERE",
12
"password": "PASSWORD GOES HERE"
13
}
14
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"txID": "2MqZ5x6keEF1mZ4d6rb12bN4euirTqwTTm1AZGVzTT7n3eKQqq",
5
"changeAddr": "g1GK7GErN3BqauK6BhhU8uCNfaBTMz4VWr3JdwvXXNCwpwQJQ-avax1dmrwka6uck44zkaamagq46hhntta67yxfy9h9z"
6
},
7
"id": 1
8
}
Copied!
We can verify transaction status with:
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"method" :"avm.getTxStatus",
5
"params" :{
6
"txID": "2MqZ5x6keEF1mZ4d6rb12bN4euirTqwTTm1AZGVzTT7n3eKQqq"
7
}
8
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"status": "Accepted"
5
},
6
"id": 1
7
}
Copied!
Now we can confirm balances are changed accordingly:
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"method" :"avm.getBalance",
5
"params" :{
6
"address":"xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax1u4uvatmymlue3zf4w0admnyj6vsw9mqk7hjckl",
7
"assetID": "asset1"
8
}
9
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"balance": "1",
5
"utxoIDs": [
6
{
7
"txID": "2MqZ5x6keEF1mZ4d6rb12bN4euirTqwTTm1AZGVzTT7n3eKQqq",
8
"outputIndex": 0
9
}
10
]
11
},
12
"id": 1
13
}
Copied!
As mentioned above, transaction fees are paid with asset1. We can confirm 1,000,000 unit (default) is used as fee in our transaction. Let's check senders balance after the transaction.
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"method" :"avm.getBalance",
5
"params" :{
6
"address":"xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax1dmrwka6uck44zkaamagq46hhntta67yxfy9h9z",
7
"assetID": "asset1"
8
}
9
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"balance": "98999999",
5
"utxoIDs": [
6
{
7
"txID": "2MqZ5x6keEF1mZ4d6rb12bN4euirTqwTTm1AZGVzTT7n3eKQqq",
8
"outputIndex": 1
9
}
10
]
11
},
12
"id": 1
13
}
Copied!
This address had 100,000,000 asset1, then we sent 1 unit to the other address and paid 1,000,000 for the transaction fee, resulting in a balance of 98,999,999 units of asset1.

Mint Asset

Our blockchain has another asset asset2 named myVarCapAsset. It is a variable-cap asset. Let's mint more units of this asset with avm.mint. Address avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70 controls the mintable asset asset2, and it also has 5,000,000 unit asset1, which is enough to pay the transaction fee.
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" : 1,
4
"method" :"avm.mint",
5
"params" :{
6
"amount": 1,
7
"assetID": "asset2",
8
"from": ["xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70"],
9
"to": "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70",
10
"minters": [
11
"xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70"
12
],
13
"changeAddr": "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70",
14
"username": "USERNAME GOES HERE",
15
"password": "PASSWORD GOES HERE"
16
}
17
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"txID": "2UQL5u5ZEELHfRpAtDYtmFF8BMSdoWNWS1Zf2dkbVSDeTbXeJQ",
5
"changeAddr": "xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70"
6
},
7
"id": 1
8
}
Copied!
Let's check the balance with avm.getAllBalances.
1
curl -X POST --data '{
2
"jsonrpc":"2.0",
3
"id" : 1,
4
"method" :"avm.getAllBalances",
5
"params" :{
6
"address":"xAd5n5PQFV6RRo8UgH54Gf5tJs8oQdctQS2ygp5F2dKZDckYH-avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70"
7
}
8
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/myxchain
Copied!
1
{
2
"jsonrpc": "2.0",
3
"result": {
4
"balances": [
5
{
6
"asset": "asset2",
7
"balance": "1"
8
},
9
{
10
"asset": "asset1",
11
"balance": "4000000"
12
}
13
]
14
},
15
"id": 1
16
}
Copied!
As we can see, 1 unit of asset2 was minted. Address avax16k8n4d8xmhplqn5vhhm342g6n9rkxuj8wn6u70 had 5,000,000 asset1, as defined in the genesis data, and now has 4,000,000 asset1 after paying the transaction fee.
Last modified 1mo ago