Skip to content

Commit

Permalink
Update Dependency Manager docs for add/install consolidation (#1011)
Browse files Browse the repository at this point in the history
Co-authored-by: Chase Fleming <[email protected]>
  • Loading branch information
chasefleming and chasefleming authored Nov 26, 2024
1 parent 80440ff commit 37c46cb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 49 deletions.
2 changes: 1 addition & 1 deletion docs/build/getting-started/flow-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ For example, let's say we want to format the result of our `GetCounter` script s
To grab it, run:

```zsh
flow dependencies add testnet://8a4dce54554b225d.NumberFormatter
flow dependencies install testnet://8a4dce54554b225d.NumberFormatter
```

When prompted for the account to deploy the contract to, select any account and ignore the prompt for an alias. This is if you wanted to configure a `mainnet` address for the contract.
Expand Down
2 changes: 1 addition & 1 deletion docs/build/guides/account-linking-with-dapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ With your accounts linked, your Flow Wallet now has a set of capabilities relate
Before you can add a script that can handle this, you'll need to import the `HybridCustody` contract using the [Flow Dependency Manager]:

```zsh
flow dependencies add mainnet://d8a7e05a7ac670c0.HybridCustody
flow dependencies install mainnet://d8a7e05a7ac670c0.HybridCustody
```

Choose `none` to skip deploying on the `emulator` and skip adding testnet aliases. There's no point, these NFTs are on mainnet!
Expand Down
105 changes: 58 additions & 47 deletions docs/tools/flow-cli/dependency-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,99 @@ description: Dependency Manager for the Flow Blockchain.
sidebar_position: 11
---

The Dependency Manager in the Flow CLI aids in speeding up and managing the development process when you use contracts from outside your project. It eliminates the manual process of copying, pasting, and updating contracts you are using or building upon. This could include core contracts or any other ecosystem contracts that you use.
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, suppose you wanted to build a new application using the `FlowToken` contract. First, you would have to find the contract on the network you want to use as the source of truth and then copy it into your local project, adding it to your `flow.json`. You would then repeat this process for each import (dependency) it relies on (e.g., the NonFungibleToken contract) to get it working. The Dependency Manager streamlines this process with a few simple commands.
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.

## `add`
## `install`

If you know the address and name of the contract you want to install (this can usually be found easily in the [Contract Browser](https://contractbrowser.com/)), you can install the dependency and all its dependencies with a single CLI command, as shown below (using FlowToken as an example):
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`.

`flow dependencies add testnet://7e60df042a9c0868.FlowToken`
### Installing Specific Dependencies

For core contracts, you can add them to your project using a simplified syntax using only the contract name (learn more about core contracts [here](../../build/core-contracts/index.md)), for example:
If you know the address and name of the contract you want to install (which can often be found via the [Contract Browser](https://contractbrowser.com/)), you can use the following syntax:

`flow dependencies add FlowToken`
```bash
flow dependencies install testnet://7e60df042a9c0868.FlowToken
```

Th command will default to using Flow Mainnet as the source network (i.e. this command is functionally equivalent to `flow dependencies add mainnet://1654653399040a61.FlowToken`).
In this command, the string `testnet://7e60df042a9c0868.FlowToken` used as the `source` in the `flow.json` is broken down as:

> Note: You can also use the shorthand `deps`
- **Network:** `testnet`
- **Address:** `7e60df042a9c0868`
- **Contract Name:** `FlowToken`

In this command, the string that will be used as the `source` in the `flow.json` after installation is `testnet://7e60df042a9c0868.FlowToken`. This can be broken down into three sections for formatting it yourself for another contract:
This specifies the remote source of the contract on the network that will be used as the source of truth.

- **Network**: `testnet`
- **Address**: `7e60df042a9c0868`
- **Contract Name**: `FlowToken`
### Installing Core Contracts Using Simplified Syntax

This is the remote source of the contract on the network that will be used as the source of truth.
For core contracts, you can use a simplified syntax that defaults to the Flow Mainnet:

## `install`
```bash
flow dependencies install FlowToken
```

Another way to install a dependency and its dependencies is to use the `install` command. For this, you can add the dependency in the short format like:
This command is functionally equivalent to:

```bash
flow dependencies install mainnet://1654653399040a61.FlowToken
```
{
"dependencies": {
"FlowToken": "emulator://0ae53cb6e3f42a79.FlowToken"
}
}

```
### Installing Multiple Dependencies

Or the extended format like this:
You can also install multiple dependencies at once. For example:

```bash
flow dependencies install testnet://7e60df042a9c0868.FlowToken NonFungibleToken
```
{
"dependencies": {
"FlowToken": {
"source": "testnet://7e60df042a9c0868.FlowToken",
"aliases": {
"emulator": "0ae53cb6e3f42a79"
}
}
}
}

```
This command installs both the `FlowToken` contract from Testnet and the `NonFungibleToken` contract from Mainnet.

Now you can run the following command from your terminal:
### Installing Dependencies from `flow.json`

```
flow dependencies install
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:

```bash
flow dependencies install
```

This will look at all the dependencies you have in your `flow.json`, install them, and all their dependencies.
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:

```json
{
"dependencies": {
"FlowToken": {
"source": "testnet://7e60df042a9c0868.FlowToken",
"aliases": {
"emulator": "0ae53cb6e3f42a79"
}
}
}
}
```

### Other Things to Note

- After installation, you will have a local folder named `imports` that you should add to `.gitignore`. This folder is where your dependencies will be stored locally.
- If your contracts change on the network, the Dependency Manager will ask if you want to update the local dependencies in your `imports` folder. The hash saved in the dependency object is used for this check, so don't remove it.
- Dependencies will function just like contracts. For instance, you can add them to [`deployments` in your `flow.json`](./deployment/deploy-project-contracts.md) and run `flow project deploy`, as well as import them in your scripts, transactions, and contracts just as you would with a contract you added yourself (e.g., `import "FlowToken"`).
- Core contract aliases will be automatically added for you across all networks.
- 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 your `flow.json`](./deployment/deploy-project-contracts.md) and run `flow 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 is used to interactively discover and install core contracts for your project. Core contracts are a standard set of smart contracts maintained by the Flow Foundation that are commonly used across the Flow ecosystem (learn more about core contracts [here](../../build/core-contracts/index.md)).
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](../../build/core-contracts/index.md)).

To use the `discover` command, run the following command in your project directory:
To use the `discover` command, run:

```
```bash
flow dependencies discover
```

You will then be presented with a list of available core contracts to install, for example:
You'll be presented with a list of available core contracts to install:

```shell
Select any core contracts you would like to install or skip to continue.
Expand All @@ -105,4 +116,4 @@ Use arrow keys to navigate, space to select, enter to confirm or skip, q to quit
[ ] EVM
```

After selecting any contracts you would like to install, you can confirm your selection by pressing `enter`. The selected contracts will be added to your `flow.json` file and accessible in your project.
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.

0 comments on commit 37c46cb

Please sign in to comment.