Skip to content

fix: skip coldkey creation in wallet create when coldkey already exists#862

Open
shardi-b wants to merge 1 commit intoopentensor:mainfrom
shardi-b:fix/wallet-create-skip-existing-coldkey
Open

fix: skip coldkey creation in wallet create when coldkey already exists#862
shardi-b wants to merge 1 commit intoopentensor:mainfrom
shardi-b:fix/wallet-create-skip-existing-coldkey

Conversation

@shardi-b
Copy link

Description

Fixes #861 - btcli wallet create unconditionally attempts to create a new coldkey even when one already exists for the wallet, causing confusing behavior.

Changes Made

  • Added a check in wallet_create() to verify if the coldkey file already exists before attempting creation
  • When coldkey exists and --overwrite is not set, prints an informational message and skips to hotkey creation
  • When --overwrite is explicitly passed, existing behavior is preserved (coldkey gets recreated)

Issue Link

Testing

Manual Testing

  1. Created a wallet: btcli wallet create --wallet-name test-wallet
  2. Ran same command to add new hotkey: btcli wallet create --wallet-name test-wallet --wallet-hotkey new-hotkey
  3. Before fix: Shows coldkey mnemonic, prompts to overwrite coldkey file, errors if declined
  4. After fix: Prints "Coldkey already exists, skipping coldkey creation", then only creates the hotkey

Test Results: Fix verified manually - coldkey creation is skipped, only hotkey mnemonic shown, no overwrite prompt.

Automated Testing

Test Command(s):

# Existing e2e tests in tests/e2e_tests/test_wallet_creations.py cover wallet creation flows

Root Cause

In bittensor_cli/src/commands/wallets.py, the wallet_create function called wallet.create_new_coldkey() unconditionally without checking if a coldkey already existed:

# Before (buggy)
wallet.create_new_coldkey(...)  # Always runs, even if coldkey exists
wallet.create_new_hotkey(...)

# After (fixed)  
if wallet.coldkey_file.exists_on_device() and not overwrite:
    console.print("Coldkey already exists, skipping...")
else:
    wallet.create_new_coldkey(...)
wallet.create_new_hotkey(...)

This pattern (coldkey_file.exists_on_device()) is already used elsewhere in the codebase (e.g., line 604, 873) for the same purpose.

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • New and existing unit tests pass locally with my changes

When running `btcli wallet create` on an existing wallet, the command
unconditionally tried to create a new coldkey, causing a confusing
overwrite prompt and displaying an unwanted coldkey mnemonic. Now checks
if coldkey file exists before attempting creation, and only creates the
hotkey when a coldkey is already present.

Fixes opentensor#861

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wallet create: unconditionally creates coldkey even when one already exists

1 participant