dfx

The DFINITY command-line execution environment (dfx) is the primary tool for creating, deploying, and managing the applications you develop for the Internet Computer blockchain.

Use the dfx parent command with flags and subcommands to specify the operations you want to perform with or without optional arguments.

Basic usage

dfx [option] [subcommand] [flag]

Flags

You can use the following optional flags with the dfx parent command or with any of the dfx subcommands.

Flag Description

-h, --help

Displays usage information.

-q`, --quiet

Suppresses informational messages.

-v, --verbose

Displays detailed information about operations.

-V, --version

Displays version information.

Options

You can use the following options with the dfx command.

Option Description

--identity <identity>

Specifies the user identity to use when running a command.

--logfile <logfile>

Writes log file messages to the specified log file name if you use the --log file logging option.

--log <logmode>

Specifies the logging mode to use. + You can set the log mode to one of the following:

- stderr to log messages to the standard error facility.

- tee to write messages to both standard output and to a specified file name.

- file to write messages to a specified file name.

The default logging mode is stderr.

Subcommands

Use the following subcommands to specify the operation you want to perform or to view usage information for a specific command.

For reference information and examples, select an appropriate subcommand.

Command Description

bootstrap

Starts the bootstrap server you want to use to serve front-end assets for your project.

build

Builds canister output from the source code in your project.

cache

Manages the dfx cache on the local computer.

canister

Manages canisters deployed on a network replica.

config

Sets or changes configuration options for your current project.

deploy

Deploys all or a specific canister from the code in your project. By default, all canisters are deployed.

help

Displays usage information for a specified subcommand.

identity

Enables you to create and manage the identities used to communicate with the Internet Computer network.

ledger

Enables you to interact with accounts in the ledger canister running on the Internet Computer.

new

Creates a new project.

ping

Sends a response request to a specified Internet Computer network to determine network connectivity. If the connection is successful, the Internet Computer replies with its status.

replica

Starts a local network replica process.

start

Starts the local network replica and a web server for the current project.

stop

Stops the local network replica.

upgrade

Upgrades the version of dfx installed on the local computer to the latest version available.

dfx wallet

Enables you to manage cycles, controllers, custodians, and addresses for the default cycles wallet associated with the currently-selected identity.

Examples

You can use the dfx parent command to display usage information or version information. For example, to display information about the version of dfx you currently have installed, you can run the following command:

dfx --version

To view usage information for a specific subcommand, specify the subcommand and the --help flag. For example, to see usage information for dfx build, you can run the following command:

dfx build --help

Using logging options

You can use the --verbose and --quiet flags to increment or decrement the logging level. If you don’t specify any logging level, CRITICAL, ERROR, WARNING, and INFO messages are logged by default. Specifying one verbose flag (-v) increases the log level to include DEBUG messages. Specifying two verbose flags (-vv)increases the logging level to include both DEBUG and TRACE messages.

Adding a --quiet flag decreases the logging level. For example, to remove all messages, you can run a command similar the following:

dfx -qqqq build

Keep in mind that using TRACE level logging (--vv) generates a lot of log messages that can affect performance and should only be used when required for troubleshooting or analysis.

To output log messages to a file named newlog.txt and display the messages on your terminal when creating a new project, you can run a command similar to the following:

dfx --log tee --logfile newlog.txt new hello_world

Specifying a user identity

If you create user identities with the dfx identity new command, you can then use the --identity comment-line option to change the user context when running other dfx commands.

In the most common use case, you use the --identity option to call specific canister functions to test access controls for specific operations.

For example, you might want to test whether the devops user identity can call the modify_profile function for the accounts canister by running the following command:

dfx --identity devops canister call accounts modify_profile '("Kris Smith")'