Deploy a Flow Project

How to deploy Flow project contracts with the CLI

1
flow project deploy

This command automatically deploys your project's contracts based on the configuration defined in your flow.json file.

Before using this command, read about how to configure project contracts and deployment targets.

Example Usage

1
> flow project deploy --network=testnet
2
3
Deploying 2 contracts for accounts: my-testnet-account
4
5
NonFungibleToken -> 0x8910590293346ec4
6
KittyItems -> 0x8910590293346ec4
7
8
✨ All contracts deployed successfully

In the example above, your flow.json file might look something like this:

1
{
2
...
3
"contracts": {
4
"NonFungibleToken": "./cadence/contracts/NonFungibleToken.cdc",
5
"KittyItems": "./cadence/contracts/KittyItems.cdc"
6
},
7
"deployments": {
8
"testnet": {
9
"my-testnet-account": ["KittyItems", "NonFungibleToken"]
10
}
11
},
12
...
13
}

Here's a sketch of the contract source files:

1
pub contract NonFungibleToken {
2
// ...
3
}
1
import NonFungibleToken from "./NonFungibleToken.cdc"
2
3
pub contract KittyItems {
4
// ...
5
}

Initialization Arguments

Deploying contracts that take initialization arguments can be achieved with adding those arguments to the configuration.

Each deployment can be specified as an object containing name and args key specifying arguments to be used during the deployment. Example:

1
...
2
"deployments": {
3
"testnet": {
4
"my-testnet-account": [
5
"NonFungibleToken", {
6
"name": "Foo",
7
"args": [
8
{ "type": "String", "value": "Hello World" },
9
{ "type": "UInt32", "value": "10" }
10
]
11
}]
12
}
13
}
14
...

⚠️ Warning: before proceeding, we recommend reading the Flow CLI security guidelines to learn about the best practices for private key storage.

Dependency Resolution

The deploy command attempts to resolve the import statements in all contracts being deployed.

After the dependencies are found, the CLI will deploy the contracts in a deterministic order such that no contract is deployed until all of its dependencies are deployed. The command will return an error if no such ordering exists due to one or more cyclic dependencies.

In the example above, Foo will always be deployed before Bar.

Address Replacement

After resolving all dependencies, the deploy command rewrites each contract so that its dependencies are imported from their target addresses rather than their source file location.

The rewritten versions are then deployed to their respective targets, leaving the original contract files unchanged.

In the example above, the KittyItems contract would be rewritten like this:

1
import NonFungibleToken from 0xf8d6e0586b0a20c7
2
3
pub contract KittyItems {
4
// ...
5
}

Merging Multiple Configuration Files

You can use the -f flag multiple times to merge several configuration files.

If there is an overlap in any of the fields in the configuration between two or more configuration files, the value of the overlapped field in the resulting configuration will come from the configuration file that is on the further right order in the list of configuration files specified in the -f flag

Let's look at an example of deploy commands with multiple configuration files below

1
{
2
"accounts": {
3
"admin-account": {
4
"address": "f8d6e0586b0a20c7",
5
"key": "21c5dfdeb0ff03a7a73ef39788563b62c89adea67bbb21ab95e5f710bd1d40b7"
6
},
7
"test-account": {
8
"address": "f8d6e0586b0a20c8",
9
"key": "52d5dfdeb0ff03a7a73ef39788563b62c89adea67bbb21ab95e5f710bd1d51c9"
10
}
11
}
12
}
1
{
2
"accounts":{
3
"admin-account":{
4
"address":"f1d6e0586b0a20c7",
5
"key":"3335dfdeb0ff03a7a73ef39788563b62c89adea67bbb21ab95e5f710bd1d40b7"
6
}
7
}
8
}

In the example above, when we try to use the deploy command with multiple configuration files and there is an overlap in the admin-account account in accounts field of the configuration, the resulting configuration will be like this

flow project deploy -f flow.json -f private.json

1
{
2
"accounts":{
3
"admin-account":{
4
"address":"f1d6e0586b0a20c7",
5
"key":"3335dfdeb0ff03a7a73ef39788563b62c89adea67bbb21ab95e5f710bd1d40b7"
6
},
7
"test-account":{
8
"address":"f8d6e0586b0a20c8",
9
"key":"52d5dfdeb0ff03a7a73ef39788563b62c89adea67bbb21ab95e5f710bd1d51c9"
10
}
11
}
12
}

Flags

Allow Updates

  • Flag: --update
  • Valid inputs: true, false
  • Default: false

Indicate whether to overwrite and upgrade existing contracts. Only contracts with difference with existing contracts will be overwritten.

Host

  • Flag: --host
  • Valid inputs: an IP address or hostname.
  • Default: 127.0.0.1:3569 (Flow Emulator)

Specify the hostname of the Access API that will be used to execute the command. This flag overrides any host defined by the --network flag.

Network Key

  • Flag: --network-key
  • Valid inputs: A valid network public key of the host in hex string format

Specify the network public key of the Access API that will be used to create a secure GRPC client when executing the command.

Network

  • Flag: --network
  • Short Flag: -n
  • Valid inputs: the name of a network defined in the configuration (flow.json)
  • Default: emulator

Specify which network you want the command to use for execution.

Filter

  • Flag: --filter
  • Short Flag: -x
  • Valid inputs: a case-sensitive name of the result property.

Specify any property name from the result you want to return as the only value.

Output

  • Flag: --output
  • Short Flag: -o
  • Valid inputs: json, inline

Specify the format of the command results.

Save

  • Flag: --save
  • Short Flag: -s
  • Valid inputs: a path in the current filesystem.

Specify the filename where you want the result to be saved

Log

  • Flag: --log
  • Short Flag: -l
  • Valid inputs: none, error, debug
  • Default: info

Specify the log level. Control how much output you want to see during command execution.

Configuration

  • Flag: --config-path
  • Short Flag: -f
  • Valid inputs: a path in the current filesystem.
  • Default: flow.json

Specify the path to the flow.json configuration file. You can use the -f flag multiple times to merge several configuration files.