Fund a Local Test Network

Introduction

In Create a Local Test Network, we showed you how to launch a 5 node local test network. Once you have a local network the next step is to fund an address so that you can begin creating transactions and interacting with smart-contracts.
We'll show you how to leverage a pre-funded private key to access funds on the X-Chain, C-Chain and P-Chain. NOTE this same private key, PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN, can be used to sign txs locally using AvalancheJS. You don't need to import the key into the local keystore in order to access those funds. They are in the genesis vertex and block for each respective chain.

Create a User

First run keystore.createUser to create a user in the local keystore.
1
curl --location --request POST '127.0.0.1:9650/ext/keystore' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc":"2.0",
5
"id" :1,
6
"method" :"keystore.createUser",
7
"params" :{
8
"username": "username",
9
"password": "password"
10
}
11
}'
12
13
{
14
"jsonrpc": "2.0",
15
"result": {
16
"success": true
17
},
18
"id": 1
19
}
Copied!
Next you can import the pre-funded private key, PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN—aka ewoq, into any of the 3 blockchains on the default subnet. After importing the key you can check the balance to confirm that it worked.

X-Chain

Import ewoq into the X-Chain.
1
curl --location --request POST '127.0.0.1:9650/ext/bc/X' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc":"2.0",
5
"id" :1,
6
"method" :"avm.importKey",
7
"params" :{
8
"username": "username",
9
"password": "password",
10
"privateKey":"PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
11
}
12
}'
13
14
{
15
"jsonrpc": "2.0",
16
"result": {
17
"address": "X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"
18
},
19
"id": 1
20
}
Copied!

Check X-Chain balance

Confirm the X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u address now has a balance of 300m AVAX on the X-Chain.
1
curl --location --request POST '127.0.0.1:9650/ext/bc/X' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc":"2.0",
5
"id" : 1,
6
"method" :"avm.getBalance",
7
"params" :{
8
"address":"X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u",
9
"assetID": "AVAX"
10
}
11
} '
12
13
{
14
"jsonrpc": "2.0",
15
"result": {
16
"balance": "300000000000000000",
17
"utxoIDs": [
18
{
19
"txID": "2fombhL7aGPwj3KH4bfrmJwW6PVnMobf9Y2fn9GwxiAAJyFDbe",
20
"outputIndex": 1
21
}
22
]
23
},
24
"id": 1
25
}
Copied!

C-Chain

Import ewoq into the C-Chain.
1
curl --location --request POST '127.0.0.1:9650/ext/bc/C/avax' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"method": "avax.importKey",
5
"params": {
6
"username":"username",
7
"password":"password",
8
"privateKey":"PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
9
},
10
"jsonrpc": "2.0",
11
"id": 1
12
}'
13
14
{
15
"jsonrpc": "2.0",
16
"result": {
17
"address": "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
18
},
19
"id": 1
20
}
Copied!

Check the C-Chain balance

Confirm the 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC address has a balance of 50m (0x295be96e64066972000000 in hex) AVAX on the C-Chain.
1
curl --location --request POST 'localhost:9650/ext/bc/C/rpc' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc": "2.0",
5
"method": "eth_getBalance",
6
"params": [
7
"0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC",
8
"latest"
9
],
10
"id": 1
11
}'
12
13
{
14
"jsonrpc": "2.0",
15
"id": 1,
16
"result": "0x295be96e64066972000000"
17
}
Copied!

Integrate with MetaMask

To see this account on Metamask, follow these steps:
  • Set up Metamask by following this and create a Avalanche Local network.
  • Create a new account by importing this private key 0x56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027 on Metamask
  • Now you can see the balance of this newly created account on Avalanche Local

P-Chain

Import ewoq into the P-Chain.
1
curl --location --request POST '127.0.0.1:9650/ext/bc/P' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc":"2.0",
5
"id" :1,
6
"method" :"platform.importKey",
7
"params" :{
8
"username":"username",
9
"password":"password",
10
"privateKey":"PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
11
}
12
}'
13
14
{
15
"jsonrpc": "2.0",
16
"result": {
17
"address": "P-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"
18
},
19
"id": 1
20
}
Copied!

Check P-Chain balance

Confirm the P-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u address has a balance of 30m AVAX on the P-Chain. 20m should be unlocked and 10m locked and stakeable.
1
curl --location --request POST '127.0.0.1:9650/ext/bc/P' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc":"2.0",
5
"id" :1,
6
"method" :"platform.getBalance",
7
"params" :{
8
"address":"P-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"
9
}
10
}'
11
12
{
13
"jsonrpc": "2.0",
14
"result": {
15
"balance": "30000000000000000",
16
"unlocked": "20000000000000000",
17
"lockedStakeable": "10000000000000000",
18
"lockedNotStakeable": "0",
19
"utxoIDs": [
20
{
21
"txID": "11111111111111111111111111111111LpoYY",
22
"outputIndex": 1
23
},
24
{
25
"txID": "11111111111111111111111111111111LpoYY",
26
"outputIndex": 0
27
}
28
]
29
},
30
"id": 1
31
}
Copied!
Last modified 19d ago