WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 40 additions & 33 deletions docs/build/tools/flow-cli/flow.json/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ The `networks` section defines which Flow networks your project can connect to.
```

**Common Networks:**
- `emulator`: Your local development environment
- `testnet`: Flow's test network for development and testing
- `mainnet`: Flow's production network
- `emulator`: Your local development environment.
- `testnet`: Flow's test network for development and testing.
- `mainnet`: Flow's production network.

**Secure Connections:**
For enhanced security, you can specify network keys:
Expand All @@ -65,7 +65,7 @@ For enhanced security, you can specify network keys:

The `accounts` section defines the accounts you can use for transactions and deployments.

#### Simple Account Format
#### Simple account format

```json
"accounts": {
Expand All @@ -76,7 +76,7 @@ The `accounts` section defines the accounts you can use for transactions and dep
}
```

#### Advanced Account Format
#### Advanced account format

For more control over key management:

Expand All @@ -96,10 +96,10 @@ For more control over key management:
```

**Key Types:**
- `hex`: Standard hex-encoded private key
- `file`: Read key from a separate file
- `bip44`: Derive from mnemonic phrase
- `google-kms`: Use Google Cloud KMS
- `hex`: Standard hex-encoded private key.
- `file`: Read key from a separate file.
- `bip44`: Derive from mnemonic phrase.
- `google-kms`: Use Google Cloud KMS.

**File-Based Keys:**
For better security, you can store private keys in separate files:
Expand All @@ -116,7 +116,7 @@ For better security, you can store private keys in separate files:
}
```

The key file should contain only the hex-encoded private key (e.g., `ae1b44c0f5e8f6992ef2348898a35e50a8b0b9684000da8b1dade1b3bcd6ebee`).
The key file should contain only the hex-encoded private key (for example, `ae1b44c0f5e8f6992ef2348898a35e50a8b0b9684000da8b1dade1b3bcd6ebee`).

**Special Address Values:**
- `"service"`: Use the default service account (emulator only)
Expand All @@ -125,7 +125,7 @@ The key file should contain only the hex-encoded private key (e.g., `ae1b44c0f5e

The `contracts` section maps contract names to their source files.

#### Simple Contract Format
#### Simple contract format

```json
"contracts": {
Expand All @@ -134,7 +134,7 @@ The `contracts` section maps contract names to their source files.
}
```

#### Advanced Contract Format with Aliases
#### Advanced contract format with aliases

Use aliases when contracts are already deployed on specific networks:

Expand All @@ -151,13 +151,13 @@ Use aliases when contracts are already deployed on specific networks:
```

**When to Use Aliases:**
- For core contracts already deployed on mainnet/testnet
- To avoid redeploying dependencies
- To use the official versions of common contracts
- For core contracts already deployed on mainnet or testnet.
- To avoid dependency redeployment.
- To use the official versions of common contracts.

#### Cadence Import Aliasing
#### Cadence import aliasing

When deploying the same contract to multiple addresses with different names, use the `canonical` field to reference the original contract. This allows you to import multiple instances of the same contract with different identifiers.
When you deploy the same contract to multiple addresses with different names, use the `canonical` field to reference the original contract. This allows you to import multiple instances of the same contract with different identifiers.

```json
"contracts": {
Expand Down Expand Up @@ -209,9 +209,9 @@ The `deployments` section defines which contracts get deployed to which accounts
**Format:** `"NETWORK": { "ACCOUNT": ["CONTRACT1", "CONTRACT2"] }`

**Important Notes:**
- Don't deploy contracts that have aliases defined for that network
- Contracts are deployed in dependency order automatically
- You can deploy the same contract to multiple accounts (but not in the same deploy command)
- Don't deploy contracts that have aliases defined for that network.
- Contracts are deployed in dependency order automatically.
- You can deploy the same contract to multiple accounts (but not in the same deploy command).

### Emulators

Expand All @@ -226,7 +226,7 @@ Customize emulator settings (optional):
}
```

## Complete Example
## Complete example

Here's a complete `flow.json` for a project with multiple contracts and networks:

Expand Down Expand Up @@ -272,9 +272,9 @@ Here's a complete `flow.json` for a project with multiple contracts and networks
}
```

## Managing Configuration
## Manage configuration

Instead of editing `flow.json` manually, use the CLI commands:
Rather than edit `flow.json` manually, use the CLI commands:

```bash
# Add an account
Expand All @@ -292,16 +292,23 @@ flow config remove account my-account

## Best Practices

1. **Use CLI commands** when possible instead of manual editing
2. **Keep private keys secure** - consider using file-based keys for production
3. **Use aliases** for core contracts to avoid redeployment
4. **Test on emulator first** before deploying to testnet
5. **Use different accounts** for different networks
6. **Backup your configuration** before making major changes
1. **Use CLI commands** when possible instead of manual editing.
2. **Keep private keys secure** - consider file-based keys for production.
3. **Use aliases** for core contracts to avoid redeployment.
4. **Test on emulator first** before you deploy to testnet.
5. **Use different accounts** for different networks.
6. **Backup your configuration** before you make major changes.

## Related Commands

- [`flow init`](./initialize-configuration.md) - Initialize a new project
- [`flow config add`](./manage-configuration.md) - Add configuration items
- [`flow project deploy`](../deployment/deploy-project-contracts.md) - Deploy contracts
- [`flow accounts create`](../accounts/create-accounts.md) - Create new accounts
- [`flow init`] - Initialize a new project
- [`flow config add`] - Add configuration items
- [`flow project deploy`] - Deploy contracts
- [`flow accounts create`] - Create new accounts

<!-- Reference-style links, will not render on page. -->

[`flow init`]: ./initialize-configuration.md
[`flow config add`]: ./manage-configuration.md
[`flow project deploy`]: ../deployment/deploy-project-contracts.md
[`flow accounts create`]: ../accounts/create-accounts.md
58 changes: 32 additions & 26 deletions docs/build/tools/flow-cli/flow.json/initialize-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ description: How to initialize Flow configuration using CLI
sidebar_position: 1
---

The `flow init` command creates a new Flow project with a basic `flow.json` configuration file. This is the first step in setting up any Flow project.
The `flow init` command creates a new Flow project with a basic `flow.json` configuration file. This is the first step to set up any Flow project.

## Basic Usage
## Basic usage

```shell
flow init
```

This command will:

- Create a new `flow.json` configuration file
- Set up default networks (emulator, testnet, mainnet)
- Create an emulator service account
- Generate a basic project structure with `cadence/` directories
- Give you options for project scaffolding
- Create a new `flow.json` configuration file.
- Set up default networks (emulator, testnet, mainnet).
- Create an emulator service account.
- Generate a basic project structure with `cadence/` directories.
- Give you options for project scaffolding.

## Project Structure
## Project structure

After running `flow init`, you'll have:
After you run `flow init`, you'll have:

```
my-project/
Expand All @@ -35,21 +35,21 @@ my-project/
└── tests/
```

## Configuration Only
## Configuration only

If you only want to generate the `flow.json` file without creating the full project structure, use the `--config-only` flag:
If you only want to generate the `flow.json` file, but not create the full project structure, use the `--config-only` flag:

```shell
flow init --config-only
```

This is useful when:

- You already have a project structure
- You want to add Flow configuration to an existing project
- You're setting up configuration for a specific environment
- You already have a project structure.
- You want to add Flow configuration to a current project.
- You want to set up configuration for a specific environment.

## Global Configuration
## Global configuration

You can create a global `flow.json` file that applies to all Flow projects on your system:

Expand All @@ -67,9 +67,9 @@ flow init --global
1. Local `flow.json` (highest priority)
2. Global `flow.json` (lowest priority)

Local configuration files will override global settings for overlapping properties.
Local configuration files will override global settings for properties that overlap.

## Error Handling
## Error handling

If a `flow.json` file already exists, you'll see this error:

Expand All @@ -79,21 +79,21 @@ If a `flow.json` file already exists, you'll see this error:

**Solutions:**

- Delete the existing `flow.json` file first
- Initialize in a different directory
- Use `--config-only` to create a new config in a different location
- Delete the current `flow.json` file first.
- Initialize in a different directory.
- Use `--config-only` to create a new config in a different location.

## Flags

### Configuration Only
### Configuration only

```shell
flow init --config-only
```

Creates only the `flow.json` file without project structure.

### Global Flags
### Global flags

The following global flags are also available:

Expand All @@ -112,7 +112,7 @@ flow init --yes

## Next Steps

After initializing your configuration:
After you initialize the configuration:

1. **Review the generated `flow.json`** - Understand the default setup
2. **Add your contracts** - Use `flow config add contract`
Expand All @@ -122,6 +122,12 @@ After initializing your configuration:

## Related Commands

- [`flow config add`](./manage-configuration.md) - Add configuration items
- [`flow accounts create`](../accounts/create-accounts.md) - Create new accounts
- [`flow project deploy`](../deployment/deploy-project-contracts.md) - Deploy contracts
- [`flow config add`] - Add configuration items
- [`flow accounts create`] - Create new accounts
- [`flow project deploy`] - Deploy contracts

<!-- Reference-style links, will not render on page. -->

[`flow config add`]: ./manage-configuration.md
[`flow project deploy`]: ../deployment/deploy-project-contracts.md
[`flow accounts create`]: ../accounts/create-accounts.md
Loading