Create a Local Test Network

Introduction

In the Get Started tutorial, we connect a node to the test network. You might find it useful to create a local test network.

We’ll show you how to launch a 5 node local test network. For both, we’ll show how to launch the network using Avash and manually.

The 5 nodes will have HTTP ports (where API calls should be sent) 9650, 9652, 9654, 9656 , and 9658.

Create a Local Test Network

The below commands assume you have AvalancheGo installed at $GOPATH/src/github.com/ava-labs/avalanchego. Each of the five nodes created is a validator. The staking keys for these nodes are in $GOPATH/src/github.com/ava-labs/avalanchego/staking/local/staker1.crt, etc.

Manually

To start the network:

cd $GOPATH/src/github.com/ava-labs/avalanchego
./scripts/build.sh
./build/avalanchego --public-ip=127.0.0.1 --snow-sample-size=2 --snow-quorum-size=2 --http-port=9650 --staking-port=9651 --db-dir=db/node1 --staking-enabled=true --network-id=local --bootstrap-ips= --staking-tls-cert-file=$(pwd)/staking/local/staker1.crt --staking-tls-key-file=$(pwd)/staking/local/staker1.key
./build/avalanchego --public-ip=127.0.0.1 --snow-sample-size=2 --snow-quorum-size=2 --http-port=9652 --staking-port=9653 --db-dir=db/node2 --staking-enabled=true --network-id=local --bootstrap-ips=127.0.0.1:9651 --bootstrap-ids=NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg --staking-tls-cert-file=$(pwd)/staking/local/staker2.crt --staking-tls-key-file=$(pwd)/staking/local/staker2.key
./build/avalanchego --public-ip=127.0.0.1 --snow-sample-size=2 --snow-quorum-size=2 --http-port=9654 --staking-port=9655 --db-dir=db/node3 --staking-enabled=true --network-id=local --bootstrap-ips=127.0.0.1:9651 --bootstrap-ids=NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg --staking-tls-cert-file=$(pwd)/staking/local/staker3.crt --staking-tls-key-file=$(pwd)/staking/local/staker3.key
./build/avalanchego --public-ip=127.0.0.1 --snow-sample-size=2 --snow-quorum-size=2 --http-port=9656 --staking-port=9657 --db-dir=db/node4 --staking-enabled=true --network-id=local --bootstrap-ips=127.0.0.1:9651 --bootstrap-ids=NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg --staking-tls-cert-file=$(pwd)/staking/local/staker4.crt --staking-tls-key-file=$(pwd)/staking/local/staker4.key
./build/avalanchego --public-ip=127.0.0.1 --snow-sample-size=2 --snow-quorum-size=2 --http-port=9658 --staking-port=9659 --db-dir=db/node5 --staking-enabled=true --network-id=local --bootstrap-ips=127.0.0.1:9651 --bootstrap-ids=NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg --staking-tls-cert-file=$(pwd)/staking/local/staker5.crt --staking-tls-key-file=$(pwd)/staking/local/staker5.key

With Avash

We assume you’ve installed Avash.

To open Avash:

cd $GOPATH/src/github.com/ava-labs/avash
go build
./avash

Now we’re in Avash. To start the network:

runscript scripts/five_node_staking.lua

When you want to tear down the network, run exit to exit Avash.

Verifying Nodes are Connected

We can look at one of the node’s peers to ensure that the nodes are connected. To do so, call info.peers.

curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"info.peers"
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info

peers should have 4 entries:

{
"jsonrpc":"2.0",
"result":{
"numPeers":"4",
"peers":[
{
"ip":"127.0.0.1:36698",
"publicIP":"127.0.0.1:9655",
"nodeID":"NodeID-NFBbbJ4qCmNaCzeW7sxErhvWqvEQMnYcN",
"version":"avalanche/1.0.5",
"lastSent":"2020-11-15T09:29:16-05:00",
"lastReceived":"2020-11-15T09:29:09-05:00"
},
{
"ip":"127.0.0.1:37036",
"publicIP":"127.0.0.1:9657",
"nodeID":"NodeID-GWPcbFJZFfZreETSoWjPimr846mXEKCtu",
"version":"avalanche/1.0.5",
"lastSent":"2020-11-15T09:29:16-05:00",
"lastReceived":"2020-11-15T09:29:18-05:00"
},
{
"ip":"127.0.0.1:38764",
"publicIP":"127.0.0.1:9659",
"nodeID":"NodeID-P7oB2McjBGgW2NXXWVYjV8JEDFoW9xDE5",
"version":"avalanche/1.0.5",
"lastSent":"2020-11-15T09:29:16-05:00",
"lastReceived":"2020-11-15T09:29:15-05:00"
},
{
"ip":"127.0.0.1:60194",
"publicIP":"127.0.0.1:9653",
"nodeID":"NodeID-MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ",
"version":"avalanche/1.0.5",
"lastSent":"2020-11-15T09:29:16-05:00",
"lastReceived":"2020-11-15T09:29:09-05:00"
}
]
},
"id":1
}

Getting AVAX

When running a network with --network-id=local, as we’ve done, there is a pre-funded X-Chain address that you can import in order to get AVAX. The private key for this address is PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN. After you create a keystore user on a node, you can import this key, and the funds it holds, with:

curl --location --request POST 'localhost:9650/ext/platform' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "platform.importKey",
"params":{
"username":"USERNAME GOES HERE",
"password":"PASSWORD GOES HERE",
"privateKey":"PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
},
"id": 1
}'

That’s it! Your local version of Avalanche is up and running. It has the default blockchains: the X-Chain, C-Chain, and P-Chain. The only subnet that exists is the Primary Network.

You can add more nodes to the network. Just remember to give unique values for db-dir, http-port , and staking-port.