Deploy a Project
_10flow project deploy
This command automatically deploys your project's contracts based on the
configuration defined in your flow.json file.
Important: Use Flow CLI commands to configure your project instead of manually editing flow.json.
Before using this command, read about how to
configure project contracts and deployment targets using CLI commands.
Example Usage
_10> flow project deploy --network=testnet_10_10Deploying 2 contracts for accounts: my-testnet-account_10_10NonFungibleToken -> 0x8910590293346ec4_10KittyItems -> 0x8910590293346ec4_10_10✨ All contracts deployed successfully
Note: The flow.json configuration shown below is created automatically when you use CLI commands.
You should use flow config add contract and flow config add deployment to configure your project
rather than manually editing the file. See Add Project Contracts for details.
Your flow.json file might look something like this:
_13{_13 ..._13 "contracts": {_13 "NonFungibleToken": "./cadence/contracts/NonFungibleToken.cdc",_13 "KittyItems": "./cadence/contracts/KittyItems.cdc"_13 },_13 "deployments": {_13 "testnet": {_13 "my-testnet-account": ["KittyItems", "NonFungibleToken"]_13 }_13 },_13 ..._13}
Here's a sketch of the contract source files:
Initialization Arguments
Deploying contracts that take initialization arguments requires adding those arguments to the deployment configuration.
Note: For basic deployments, use flow config add deployment to configure your contracts.
Initialization arguments are an advanced feature that may require manual editing of flow.json
after the basic deployment is configured with CLI commands.
Each deployment can be specified as an object containing
name and args keys specifying arguments to be
used during the deployment. Example:
_16{_16 "deployments": {_16 "testnet": {_16 "my-testnet-account": [_16 "NonFungibleToken",_16 {_16 "name": "Foo",_16 "args": [_16 { "type": "String", "value": "Hello World" },_16 { "type": "UInt32", "value": "10" }_16 ]_16 }_16 ]_16 }_16 }_16}
⚠️ Security Warning: Never put raw private keys in flow.json. Always use .pkey files for key storage.
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, NonFungibleToken will always be deployed before KittyItems since KittyItems imports NonFungibleToken.
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.
Contracts Importing from Other Contracts
In the example above, the KittyItems contract would be rewritten like this:
Contracts Importing from Dependencies
When your contracts import from the dependencies section, the deploy command uses the network-specific aliases defined in those dependencies.
Example flow.json with dependencies:
_35{_35 "contracts": {_35 "ExampleConnectors": {_35 "source": "cadence/contracts/ExampleConnectors.cdc",_35 "aliases": {_35 "testing": "0000000000000007"_35 }_35 }_35 },_35 "dependencies": {_35 "FlowToken": {_35 "source": "mainnet://1654653399040a61.FlowToken",_35 "hash": "cefb25fd19d9fc80ce02896267eb6157a6b0df7b1935caa8641421fe34c0e67a",_35 "aliases": {_35 "emulator": "0ae53cb6e3f42a79",_35 "mainnet": "1654653399040a61",_35 "testnet": "7e60df042a9c0868"_35 }_35 },_35 "FungibleToken": {_35 "source": "mainnet://f233dcee88fe0abe.FungibleToken",_35 "hash": "23c1159cf99b2b039b6b868d782d57ae39b8d784045d81597f100a4782f0285b",_35 "aliases": {_35 "emulator": "ee82856bf20e2aa6",_35 "mainnet": "f233dcee88fe0abe",_35 "testnet": "9a0766d93b6608b7"_35 }_35 }_35 },_35 "deployments": {_35 "testnet": {_35 "testnet-account": ["ExampleConnectors"]_35 }_35 }_35}
Original contract source:
Rewritten for testnet deployment:
Rewritten for mainnet deployment:
The deploy command automatically uses the addresses from the dependencies section's aliases for the target network. Notice how the addresses change based on the network—testnet uses 0x9a0766d93b6608b7 for FungibleToken, while mainnet uses 0xf233dcee88fe0abe. Contracts in the dependencies section are not deployed—they're assumed to already exist on the network at the addresses specified in their aliases.
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.
Important: Never put raw private keys in flow.json. Always use .pkey files for key storage.
Note: Use flow config add account to create accounts in your main flow.json file.
The merging feature is useful for separating sensitive account information into a separate file that you can exclude from version control.
Example usage:
_10flow project deploy -f flow.json -f private.json
Example configuration files:
When using multiple configuration files with overlapping fields, the rightmost file takes precedence. In this example, the resulting merged configuration will be:
_18{_18 "accounts": {_18 "admin-account": {_18 "address": "f1d6e0586b0a20c7",_18 "key": {_18 "type": "file",_18 "location": "admin-account-private.pkey"_18 }_18 },_18 "test-account": {_18 "address": "f8d6e0586b0a20c8",_18 "key": {_18 "type": "file",_18 "location": "test-account.pkey"_18 }_18 }_18 }_18}
Security best practice: Ensure .pkey files are added to .gitignore to prevent accidentally committing private keys to version control.
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.
Show Update Diff
- Flag:
--show-diff - Valid inputs:
true,false - Default:
false
Shows a diff to approve before updating between deployed contract and new contract updates.
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.
Version Check
- Flag:
--skip-version-check - Default:
false
Skip version check during start up to speed up process for slow connections.