Dependency Manager
The Dependency Manager in the Flow CLI streamlines the development process when you use contracts from outside your project. It eliminates the manual tasks of copying, pasting, and updating contracts that you use or build upon, such as core contracts or any other ecosystem contracts.
For example, if you wanted to build a new application using the FlowToken
contract, you would traditionally need to locate the contract on the network, copy it into your local project, and add it to your flow.json
. You would repeat this process for each import (dependency) it relies on, like the NonFungibleToken
contract. The Dependency Manager simplifies this process with a few straightforward commands.
install
The install
command allows you to install dependencies and all their sub-dependencies with ease. You can use it to install specific dependencies or to install all dependencies listed in your flow.json
.
Installing Specific Dependencies
If you know the address and name of the contract you want to install (which can often be found via the Contract Browser), you can use the following syntax:
_10flow dependencies install testnet://7e60df042a9c0868.FlowToken
In this command, the string testnet://7e60df042a9c0868.FlowToken
used as the source
in the flow.json
is broken down as:
- Network:
testnet
- Address:
7e60df042a9c0868
- Contract Name:
FlowToken
This specifies the remote source of the contract on the network that will be used as the source of truth.
Installing Core Contracts Using Simplified Syntax
For core contracts, you can use a simplified syntax that defaults to the Flow Mainnet:
_10flow dependencies install FlowToken
This command is functionally equivalent to:
_10flow dependencies install mainnet://1654653399040a61.FlowToken
Installing Multiple Dependencies
You can also install multiple dependencies at once. For example:
_10flow dependencies install testnet://7e60df042a9c0868.FlowToken NonFungibleToken
This command installs both the FlowToken
contract from Testnet and the NonFungibleToken
contract from Mainnet.
Installing Dependencies from flow.json
If you run the install
command without specifying any dependencies, it will install all the dependencies listed in your flow.json
file and ensure they are up to date:
_10flow dependencies install
This command checks all the dependencies specified in your flow.json
, installs them, and updates them if there have been changes on the network.
Example flow.json
Entry
After installing, your flow.json
might include an entry like:
_10{_10 "dependencies": {_10 "FlowToken": {_10 "source": "testnet://7e60df042a9c0868.FlowToken",_10 "aliases": {_10 "emulator": "0ae53cb6e3f42a79"_10 }_10 }_10 }_10}
Other Things to Note
- After installation, a local folder named
imports
will be created. It's recommended to add this folder to your.gitignore
, as it stores your dependencies locally. - If the contracts change on the network, the Dependency Manager will prompt you to update the local dependencies in your
imports
folder. The hash saved in the dependency object is used for this check, so avoid removing it. - Dependencies function just like local contracts. You can add them to
deployments
in yourflow.json
and runflow project deploy
. You can also import them in your scripts, transactions, and contracts (e.g.,import "FlowToken"
). - Core contract aliases are automatically added for you across all networks.
discover
The discover
command helps you interactively find and install core contracts for your project. Core contracts are standard smart contracts maintained by the Flow Foundation and are commonly used across the Flow ecosystem (learn more about core contracts here).
To use the discover
command, run:
_10flow dependencies discover
You'll be presented with a list of available core contracts to install:
_14Select any core contracts you would like to install or skip to continue._14Use arrow keys to navigate, space to select, enter to confirm or skip, q to quit:_14_14> [ ] FlowEpoch_14 [ ] FlowIDTableStaking_14 [ ] FlowClusterQC_14 [ ] FlowDKG_14 [ ] FlowServiceAccount_14 [ ] NodeVersionBeacon_14 [ ] RandomBeaconHistory_14 [ ] FlowStorageFees_14 [ ] FlowFees_14 [ ] FungibleTokenSwitchboard_14 [ ] EVM
After selecting the contracts, press enter
to confirm. The selected contracts will be added to your flow.json
file and will be accessible in your project.