Command-Line Interface Documentation

Cannon’s command-line interface (CLI) allows users to deploy, upgrade, and configure protocols using cannonfiles with the build command, publish the resulting packages, run packages locally, and more. Find the code for the CLI on GitHub.

Installation

Run one of the following commands in your terminal to install (or upgrade) Cannon:

npm i -g @usecannon/cli

Now you can use all of the following commands your terminal with cannon <command>. You can also use the CLI without installing it using npx: npx @usecannon/cli <command>. If no command is specified, the CLI will execute the run command. The Hardhat plug-in exposes some of the commands as Hardhat tasks.

Basic Commands

run#

Utility for instantly loading cannon packages in standalone contexts

cannon run [global options] ...[<name>[:<semver>] ...[<key>=<value>]]

ArgumentDescription
<packageNames...>List of packages to load, optionally with custom settings for each one
OptionDescription
-n --provider-url [url]RPC endpoint to fork off of
--buildSpecify to rebuild generated artifacts with latest, even if no changed settings have been defined.
--upgrade-from [cannon-package:0.0.1]Specify a package to use as a new base for the deployment.
--registry-priority <registry>Change the default registry to read from first. Default: onchain
--preset <preset>Load an alternate setting preset
--logsShow RPC logs instead of an interactive prompt
--fund-addresses <fundAddresses...>Pass a list of addresses to receive a balance of 10,000 ETH
--impersonate <address>Impersonate all calls from the given signer instead of a real wallet. Only works with --fork (default: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")
--mnemonic <phrase>Use the specified mnemonic to initialize a chain of signers while running
--private-key [key]Specify a comma separated list of private keys which may be needed to sign a transaction

setup#

Initialize cannon settings file

cannon setup

build#

Build a package from a Cannonfile

cannon build [options] [cannonfile] [settings...]

ArgumentDescription
[cannonfile]Path to a cannonfile (default: "cannonfile.toml")
[settings...]Custom settings for building the cannonfile
OptionDescription
-n --provider-url [url]RPC endpoint to execute the deployment on
-c --chain-id <number>The chain id to run against
-p --preset <preset>The preset label for storing the build with the given settings
--dry-runSimulate building on a local fork rather than deploying on the real network
--private-key [key]Specify a comma separated list of private keys which may be needed to sign a transaction
--wipeClear the existing deployment state and start this deploy from scratch.
--upgrade-from [cannon-package:0.0.1]Specify a package to use as a new base for the deployment.
--registry-priority <registry>Change the default registry to read from first. Default: onchain
--gas-price <gasPrice>Specify a gas price to use for the deployment
--max-gas-fee <maxGasFee>Specify max fee per gas (EIP-1559) for deployment
--max-priority-gas-fee <maxpriorityGasFee>Specify max fee per gas (EIP-1559) for deployment
--skip-compileSkip the compilation step and use the existing artifacts
--write-script <writeScript>(Experimental) Path to write all the actions taken as a script that can be later executed
--write-script-format <writeScriptFormat>(Experimental) Format in which to write the actions script (Options: json, ethers) (default: "ethers")
-q --quietSuppress extra logging
-vprint logs for builder,equivalent to DEBUG=cannon:builder
-vvprint logs for builder and its definition section,equivalent to DEBUG=cannon:builder,cannon:builder:definition
-vvvprint logs for builder and its all sub sections,equivalent to DEBUG=cannon:builder*
-vvvvprint all cannon logs,equivalent to DEBUG=cannon:*

verify#

Verify a package on Etherscan

cannon verify [options] <packageName>

ArgumentDescription
<packageName>Name and version of the Cannon package to verify
OptionDescription
-a --api-key <apiKey>Etherscan API key
-c --chain-id <chainId>Chain ID of deployment to verify (default: "1")
-p --preset <preset>Preset of the deployment to verify

publish#

Publish a Cannon package to the registry

cannon publish [options] <packageName>

ArgumentDescription
<packageName>Name and version of the package to publish
OptionDescription
-n --registry-provider-url [url]RPC endpoint to publish to
--private-key <key>Private key to use for publishing the registry package
--chain-id <number>The chain ID of the package to publish
--preset <preset>The preset of the packages to publish
-t --tags <tags>Comma separated list of labels for your package
--gas-limit <gasLimit>The maximum units of gas spent for the registration transaction
--value <value>Value in wei to send with the transaction
--max-fee-per-gas <maxFeePerGas>The maximum value (in gwei) for the base fee when submitting the registry transaction
--max-priority-fee-per-gas <maxPriorityFeePerGas>The maximum value (in gwei) for the miner tip when submitting the registry transaction
-q --quietOnly output final JSON object at the end, no human readable output
--include-provisionedIncludes provisioned packages when publishing to the registry
--skip-confirmSkip confirmation and package selection prompts

Advanced Commands

alter#

Change a cannon package outside of the regular build process.

cannon alter [options] <packageName> <command> [options...]

ArgumentDescription
<packageName>Name and version of the Cannon package to alter
<command>Alteration command to execute. Current options: set-url, set-contract-address, mark-complete, mark-incomplete
[options...]Additional options for your alteration command
OptionDescription
-c --chain-id <chainId>Chain ID of deployment to alter
-p --preset <preset>Preset of the deployment to alter

fetch#

Fetch cannon package data from an IPFS hash and store it in the local registry.

cannon fetch [options] <packageName> <ipfsHash>

ArgumentDescription
<packageName>Name of the package to fetch data for
<ipfsHash>IPFS hash to fetch deployment data from
OptionDescription
-c --chain-id <chainId>Chain ID of deployment to fetch
--meta-hash <metaHash>IPFS hash to fetch deployment metadata from

inspect#

Inspect the details of a Cannon package

cannon inspect [options] <packageName>

ArgumentDescription
<packageName>Name and version of the cannon package to inspect
OptionDescription
-c --chain-id <chainId>Chain ID of the variant to inspect (default: "13370")
-p --preset <preset>Preset of the variant to inspect
-j --jsonOutput as JSON
-w --write-deployments <writeDeployments>Path to write the deployments data (address and ABIs), like "./deployments"
-q --quietSuppress extra logging
--registry-priority <registry>Change the default registry to read from first. Default: onchain

prune#

Clean cannon storage of excessive/transient build files older than a certain age

cannon prune [options]

OptionDescription
--filter-package <packageName>Only keep deployments in local storage which match the given package name. Default: do not filter
--filter-variant <variant>Only keep deployments which match the specifiec variant(s). Default: do not filter
--keep-age <seconds>Number of seconds old a package must be before it should be deleted (default: "2592000")
--dry-runPrint out information about prune without committing
-y --yesSkip confirmation prompt

trace#

Get a full stack trace for a transaction hash or explicit transaction call

cannon trace [options] <packageName> <transactionHash OR bytes32Data>

ArgumentDescription
<packageName>Name and version of the cannon package to use
<transactionHash OR bytes32Data>base 16 encoded transaction data to input to a function call, or transaction hash
OptionDescription
-c --chain-id <chainId>Chain ID of the variant to inspect (default: "13370")
-f --from <source>Caller for the transaction to trace
-t --to <target>Contract which should be called
-v --value <value>Amonut of gas token to send in the traced call
-b --block-number <value>The block to simulate when the call is on
-p --preset <preset>Preset of the variant to inspect (default: "main")
-n --provider-url [url]RPC endpoint to fork off of
-j --jsonOutput as JSON

decode#

decode transaction data using the ABIs of the given Cannon package

cannon decode [options] <packageName> <bytes32Data...>

ArgumentDescription
<packageName>Name and version of the cannon package to use
<bytes32Data...>bytes32 encoded transaction data to decode
OptionDescription
-c --chain-id <chainId>Chain ID of the variant to inspect (default: "13370")
-p --preset <preset>Preset of the variant to inspect (default: "main")
-j --jsonOutput as JSON

test#

Run forge tests on a cannon deployment. To pass arguments through to `forge test`, use `--`.

cannon test [cannonfile] [-- forge options...]

ArgumentDescription
[cannonfile]Path to a cannonfile (default: "cannonfile.toml")
[forge options...]Additional options to send to forge
OptionDescription
-n --provider-url [url]RPC endpoint to fork off of
-c --chain-idChain ID to connect to and run fork tests with
-p --preset <preset>The preset label for storing the build with the given settings (default: "main")
--wipeClear the existing deployment state and start this deploy from scratch.
--upgrade-from [cannon-package:0.0.1]Specify a package to use as a new base for the deployment.
--registry-priority <registry>Change the default registry to read from first. Default: onchain

interact#

Start an interactive terminal against a set of active cannon deployments

cannon interact [options] <packageName>

ArgumentDescription
<packageName>Package to deploy, optionally with custom settings
OptionDescription
-c --chain-id <chainId>Chain ID of deployment to interact with
-n --provider-url [url]RPC endpoint to execute the deployment on
-p --preset <preset>Load an alternate setting preset (default: "main")
--mnemonic <phrase>Use the specified mnemonic to initialize a chain of signers while running
--private-key [key]Specify a comma separated list of private keys which may be needed to sign a transaction
--gas-price <gasPrice>Specify a gas price to use for the deployment
--max-gas-fee <maxGasFee>Specify max fee per gas (EIP-1559) for deployment
--max-priority-gas-fee <maxpriorityGasFee>Specify max fee per gas (EIP-1559) for deployment

clean#

Delete packages cache directories

cannon clean [options]

OptionDescription
--no-confirmDo not ask for confirmation before deleting

plugin list#

List all installed Cannon plug-ins

cannon plugin list

plugin add#

Add a Cannon plug-in

cannon plugin add <name>

ArgumentDescription
<name>npm package name of the Cannon plug-in

plugin remove#

Remove a Cannon plug-in

cannon plugin remove <name>

ArgumentDescription
<name>npm package name of the Cannon plug-in

Supported byOptimismandSafe