Flow CLI Configuration

What is Flow CLI Configuration

Flow CLI uses a state called configuration which is stored in a file (usually flow.json).

Flow configuration (flow.json) file will contain the following properties:

  • A networks list pre-populated with the Flow emulator, testnet and mainnet connection configuration.
  • An accounts list pre-populated with the Flow Emulator service account.
  • A deployments empty object where all deployment targets can be defined.
  • A contracts empty object where you define contracts you wish to deploy.

Example Project Configuration

1
{
2
"networks": {
3
"emulator": "127.0.0.1:3569",
4
"mainnet": "access.mainnet.nodes.onflow.org:9000",
5
"testnet": "access.devnet.nodes.onflow.org:9000"
6
},
7
"accounts": {
8
"emulator-account": {
9
"address": "f8d6e0586b0a20c7",
10
"key": "ae1b44c0f5e8f6992ef2348898a35e50a8b0b9684000da8b1dade1b3bcd6ebee",
11
}
12
},
13
"deployments": {},
14
"contracts": {}
15
}

Configuration

Below is an example of a configuration file for a complete Flow project. We'll walk through each property one by one.

1
{
2
"contracts": {
3
"NonFungibleToken": "./cadence/contracts/NonFungibleToken.cdc",
4
"Kibble": "./cadence/contracts/Kibble.cdc",
5
"KittyItems": "./cadence/contracts/KittyItems.cdc",
6
"KittyItemsMarket": "./cadence/contracts/KittyItemsMarket.cdc",
7
"FungibleToken": {
8
"source": "./cadence/contracts/FungibleToken.cdc",
9
"aliases": {
10
"testnet": "9a0766d93b6608b7",
11
"emulator": "ee82856bf20e2aa6"
12
}
13
}
14
},
15
16
"deployments": {
17
"testnet": {
18
"admin-account": ["NonFungibleToken"],
19
"user-account": ["Kibble", "KittyItems", "KittyItemsMarket"]
20
},
21
"emulator": {
22
"emulator-account": [
23
"NonFungibleToken",
24
"Kibble",
25
"KittyItems",
26
"KittyItemsMarket"
27
]
28
}
29
},
30
31
"accounts": {
32
"admin-account": {
33
"address": "3ae53cb6e3f42a79",
34
"key": "12332967fd2bd75234ae9037dd4694c1f00baad63a10c35172bf65fbb8ad1111"
35
},
36
"user-account": {
37
"address": "e2a8b7f23e8b548f",
38
"key": "22232967fd2bd75234ae9037dd4694c1f00baad63a10c35172bf65fbb8ad1111"
39
},
40
"emulator-account": {
41
"address": "f8d6e0586b0a20c7",
42
"key": "2eae2f31cb5b756151fa11d82949c634b8f28796a711d7eb1e52cc301ed11111",
43
}
44
},
45
46
"networks": {
47
"emulator": "127.0.0.1:3569",
48
"mainnet": "access.mainnet.nodes.onflow.org:9000",
49
"testnet": "access.devnet.nodes.onflow.org:9000",
50
"testnetSecure": {
51
"Host": "access-001.devnet30.nodes.onflow.org:9001",
52
"NetworkKey": "ba69f7d2e82b9edf25b103c195cd371cf0cc047ef8884a9bbe331e62982d46daeebf836f7445a2ac16741013b192959d8ad26998aff12f2adc67a99e1eb2988d"
53
}
54
}
55
}

Contracts

Contracts are specified as key-value pairs, where the key is the contract name, and the value is the location of the Cadence source code.

The advanced format allows us to specify aliases for each network.

Simple Format

1
...
2
3
"contracts": {
4
"NonFungibleToken": "./cadence/contracts/NonFungibleToken.cdc"
5
}
6
7
...

Advanced Format

Using advanced format we can define aliases. Aliases define an address where the contract is already deployed for that specific network. In the example scenario below the contract FungibleToken would be imported from the address 9a0766d93b6608b7 when deploying to testnet network and address ee82856bf20e2aa6 when deploying to the Flow emulator. We can specify aliases for each network we have defined. When deploying to testnet it is always a good idea to specify aliases for all the common contracts that have already been deployed to the testnet.

⚠️ If we use an alias for the contract we should not specify it in the deployment section for that network.

Our example below should not include FungibleToken in deployment section for testnet and emulator network.

1
...
2
"FungibleToken": {
3
"source": "./cadence/contracts/FungibleToken.cdc",
4
"aliases": {
5
"testnet": "9a0766d93b6608b7",
6
"emulator": "ee82856bf20e2aa6"
7
}
8
}
9
...

Format used to specify advanced contracts is:

1
"CONTRACT NAME": {
2
"source": "CONTRACT SOURCE FILE LOCATION",
3
"aliases": {
4
"NETWORK NAME": "ADDRESS ON SPECIFIED NETWORK WITH DEPLOYED CONTRACT"
5
...
6
}
7
}

Accounts

The accounts section is used to define account properties such as keys and addresses. Each account must include a name, which is then referenced throughout the configuration file.

Simple Format

When using the simple format, simply specify the address for the account, and a single hex-encoded private key.

1
...
2
3
"accounts": {
4
"admin-account": {
5
"address": "3ae53cb6e3f42a79",
6
"key": "12332967fd2bd75234ae9037dd4694c1f00baad63a10c35172bf65fbb8ad1111"
7
}
8
}
9
10
...

Advanced format

The advanced format allows us to define more properties for the account. We can define the signature algorithm and hashing algorithm, as well as custom key formats.

Please note that we can use service for address in case the account is used on emulator network as this is a special value that is defined on the run time to the default service address on the emulator network.

Example for advanced hex format:

1
...
2
3
"accounts": {
4
"admin-account": {
5
"address": "service",
6
"key":{
7
"type": "hex",
8
"index": 0,
9
"signatureAlgorithm": "ECDSA_P256",
10
"hashAlgorithm": "SHA3_256",
11
"privateKey": "12332967fd2bd75234ae9037dd4694c1f00baad63a10c35172bf65fbb8ad1111"
12
}
13
}
14
}
15
16
...

You can also use BIP44 to derive keys from a mnemonic. For more details please see the FLIP

Example for BIP44 format:

1
...
2
3
"accounts": {
4
"admin-account": {
5
"address": "service",
6
"key":{
7
"type": "bip44",
8
"index": 0,
9
"signatureAlgorithm": "ECDSA_P256",
10
"hashAlgorithm": "SHA3_256",
11
"mnemonic": "skull design wagon top faith actor valley crystal subject volcano access join",
12
"derivationPath": "m/44'/539'/0'/0/0"
13
}
14
}
15
}
16
17
...

Note: Default value for derivationPath is m/44'/539'/0'/0/0 if omitted.

You can also use a key management system (KMS) to sign the transactions. Currently, we only support Google KMS.

Example for Google KMS format:

1
...
2
"accounts": {
3
"admin-account": {
4
"address": "service",
5
"key": {
6
"type": "google-kms",
7
"index": 0,
8
"signatureAlgorithm": "ECDSA_P256",
9
"hashAlgorithm": "SHA3_256",
10
"resourceID": "projects/flow/locations/us/keyRings/foo/bar/cryptoKeyVersions/1"
11
}
12
}
13
}
14
...

Deployments

The deployments section defines where the project deploy command will deploy specified contracts. This configuration property acts as the glue that ties together accounts, contracts and networks, all of which are referenced by name.

In the deployments section we specify the network, account name and list of contracts to be deployed to that account.

Format specifying the deployment is:

1
...
2
"deployments": {
3
"NETWORK": {
4
"ACCOUNT NAME": ["CONTRACT NAME"]
5
}
6
}
7
8
...
1
...
2
3
"deployments": {
4
"emulator": {
5
"emulator-account": [
6
"NonFungibleToken",
7
"Kibble",
8
"KittyItems",
9
"KittyItemsMarket"
10
]
11
},
12
"testnet": {
13
"admin-account": ["NonFungibleToken"],
14
"user-account": [
15
"Kibble",
16
"KittyItems",
17
"KittyItemsMarket"
18
]
19
}
20
}
21
22
...

Networks

Use this section to define networks and connection parameters for that specific network.

Format for networks is:

1
...
2
"networks": {
3
"NETWORK NAME": "ADDRESS"
4
}
5
...
1
...
2
"networks": {
3
"NETWORK NAME": {
4
"host": "ADDRESS",
5
"key": "ACCESS NODE NETWORK KEY"
6
}
7
}
8
...
1
...
2
3
"networks": {
4
"emulator": "127.0.0.1:3569",
5
"mainnet": "access.mainnet.nodes.onflow.org:9000",
6
"testnet": "access.devnet.nodes.onflow.org:9000",
7
"testnetSecure": {
8
"host": "access-001.devnet30.nodes.onflow.org:9001",
9
"key": "ba69f7d2e82b9edf25b103c195cd371cf0cc047ef8884a9bbe331e62982d46daeebf836f7445a2ac16741013b192959d8ad26998aff12f2adc67a99e1eb2988d"
10
},
11
}
12
13
...

Emulators

The default emulator CLI is automatically configured with name being "default" and values of serviceAccount: "emulator-account" and port: "3569". The default emulator configuration will not show up on flow.json.

To customize emulator values, add emulator section like the example below:

1
...
2
3
"emulators": {
4
"custom-emulator": {
5
"port": 3600,
6
"serviceAccount": "emulator-account"
7
}
8
}
9
10
...