Configuring chains

Add and manage custom chains with ZKsync CLI

You can define named chains to use with ZKsync CLI to interact with when running commands.

Every ZKsync CLI command requires a chain to execute transactions on, and by default, the ZKsync Mainnet, ZKsync Sepolia Testnet, in-memory local node, and Dockerized local node are provided. You can add and edit additional chains using the zksync-cli config chains sub-command.

Using a custom chain

The ZKsync CLI prompts with a list of default chains as well as your custom chains whenever you run a command without the --chain option. To pass in a chain to a ZKsync CLI command with the --chain option, use the chain key to refer to the chain of choice.

zksync-cli wallet balance --chain example-chain

Creating a new chain

The CLI prompts you to select an existing chain to edit or the option to add a new chain. Use the arrow keys to navigate to "+ Add new chain" and press Enter to select.

? Select a chain (Use arrow keys)
 My ZKchain - my-zkchain
  Custom Chain - custom-chain
  ──────────────
  + Add new chain

The CLI then prompts you with several questions for the new chain. The Chain name is a visual label to identify the chain you are adding, and the Chain key is the id to use for referencing the chain when using the --chain option.

If the chain connects to L1, the CLI will also require the L1 details to setup your new chain configuration.

The following is an example of adding a chain for ZKsync Sepolia connected to Ethereum Sepolia. This configuration is already available in ZKsync CLI by default; you do not need to add this configuration.
? Select a chain Add new chain
? Chain id 300
? Chain name Example Chain
? Chain key example-chain
? Chain RPC URL https://sepolia.era.zksync.dev
? Chain explorer URL (optional) https://sepolia.explorer.zksync.io/
? Is this chain connected to L1
  No - skip adding L1 chain info
 Yes - add L1 chain info
? Is this chain connected to L1 Yes
? L1 Chain id 11155111
? L1 Chain name Sepolia
? L1 Chain key sepolia
? L1 Chain RPC URL https://rpc.ankr.com/eth_sepolia
? L1 Chain explorer URL (optional) https://sepolia.etherscan.io/
 Chain "Example Chain" saved

Edit an existing chain

You can edit an existing custom chain by selecting an existing chain from the prompt after running zksync-cli config chains. Select a chain and the CLI will prompt if you want to Edit or Delete the chain. Press Enter to select the Edit option.

? Select a chain example-chain
? What do you want to do? (Use arrow keys)
 Edit
  Delete

The CLI then goes through the prompt similar to creating a new chain, however the initial value will be displayed in parentheses.

? Chain id (300)

To change the initial value, enter a new value and press Enter to move to the next question. To leave the initial value unchanged, press Enter with an empty value.


Made with ❤️ by the ZKsync Community