From Avash to MetaMask

Reza
4 min readAug 1, 2021
Photo by Krzysztof Kowalik on Unsplash

Or how to set up our own local Avalanche testnet.

First of all, we’re going to want to install Avash which requires Golang 1.15.5 or later and AvalancheGo.

Follow the instructions here to install Go. Don’t forget to set $GOPATH.

Let’s continue with AvalancheGo. Download it from the repo:

go get -v -d github.com/ava-labs/avalanchego/…

Change to the avalanchego directory:

cd $GOPATH/src/github.com/ava-labs/avalanchego

And build it:

./scripts/build.sh

When the build is done the binary will be in:

./build/avalanchego

Alright. Now we need to install Avash. Go back to your home directory:

cd ~

And download and build Avash:

git clone https://github.com/ava-labs/avash.git; cd avash; go build

Make sure we’re already in the avash directory and then run it:

./avash

A file .avash.yaml will be created. This is our Avash configuration file:

Config file set: $HOME/.avash.yaml
Avash successfully configured.

Exit from Avash:

avash> exit

We’ll use our favorite text editor to edit .avash.yaml and fill it in with the relevant parameters.

avalanchelocation: $GOPATH/src/github.com/ava-labs/avalanchego/build/avalanchego
datadir: $HOME/avash/stash
log:
terminal: info
logfile: info
dir: $HOME/avash/stash/logs

Run Avash:

./avash

And now we’ll start a five node testnet:

runscript scripts/five_node_staking.lua

Check whether all five nodes are running:

avash> procmanager list
Output of procmanager list
node1

Verify the nodes are connected by calling info.peers from one node:

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

As we can see all four of our peers are here:

Connected peers

Avalanche nodes have a keystore to manage users. Let’s create a user:

curl -X POST --data '{
"jsonrpc": "2.0",
"id": 1,
"method": "keystore.createUser",
"params": {
"username": "YOUR_USERNAME",
"password": "YOUR_PASSWORD"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/keystore

The response should be:

{"jsonrpc":"2.0","result":{"success":true},"id":1}

Now we need to get some test AVAX so we can actually use this testnet. We want to fund an address on the C-Chain because we want to use it for testing our smart contracts. So how exactly do we do that? Luckily for us, if we’re running a local test network there’s a pre-funded C-Chain address that we can import to get some AVAX. The private key for the address is PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN . Let’s import the key to get access to its funds.

curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.importKey",
"params" :{
"username" :"YOUR_USERNAME",
"password":"YOUR_PASSWORD",
"privateKey":"PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avax

Which is this address on the C-Chain:

{“jsonrpc”:”2.0",”result”:{“address”:”0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC”},”id”:1}

In order to use this address from MetaMask we must import it. Let’s get the private key so we can use it in MetaMask:

curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.exportKey",
"params" :{
"username" :"YOUR_USERNAME",
"password":"YOUR_PASSWORD",
"address": "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avax

We see that it’s the parameter privateKeyHex.

{“jsonrpc”:”2.0",”result”:{“privateKey”:”PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN”,”privateKeyHex”:”0x56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027"},”id”:1}

Before we import the account we’ll first connect MetaMask to our local Avalanche test network. Select ‘Networks’ and select ‘Custom RPC’ and use these parameters:

Network Name: Avalanche Local

New RPC URL: http://localhost:9650/ext/bc/C/rpc

ChainID: 43112

Symbol: AVAX

Explorer: N/A

Add a custom RPC to MetaMask

Click ‘Save’.

Now import the account:

Import an account to MetaMask

Paste the private key 0x56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027 and click ‘Import’.

Input private key and import account

And we can see that the account has funds in it!

Pre-funded C-Chain address

Try sending some AVAX:

Send 1 AVAX

And we’re done!

Send AVAX successful

The private key we used in this example is for testing purposes only. Be careful to not ever expose your private keys or you may risk losing your funds.

--

--