linera-io/linera-protocol · warning

Wallet already exists: {}

Error message

Wallet already exists: {}

What it means

create_wallet() refuses to overwrite: the wallet file at the resolved path (from --wallet-state-path, or the default location honoring LINERA_WALLET / wallet suffix via --with-wallet) already exists on disk. This is a guard against clobbering an existing wallet's keys and chain state during genesis creation (e.g. 'linera wallet create' / project create).

Source

Thrown at linera-service/src/cli/common_options.rs:123

    pub fn keystore_path(&self) -> Result<PathBuf, Error> {
        linera_wallet_json::paths::keystore_path(self.keystore_path.as_ref(), &self.suffix())
    }

    /// Reads and returns the wallet.
    pub fn wallet(&self) -> Result<Wallet, Error> {
        Ok(Wallet::read(&self.wallet_path()?)?)
    }

    /// Reads and returns the keystore.
    pub fn keystore(&self) -> Result<linera_wallet_json::Keystore, Error> {
        Ok(linera_wallet_json::Keystore::read(&self.keystore_path()?)?)
    }

    /// Creates and saves a new wallet from the given genesis configuration.
    pub fn create_wallet(&self, genesis_config: GenesisConfig) -> Result<Wallet, Error> {
        let wallet_path = self.wallet_path()?;
        if wallet_path.exists() {
            bail!("Wallet already exists: {}", wallet_path.display());
        }
        let wallet = Wallet::create(&wallet_path, genesis_config)?;
        wallet.save()?;
        Ok(wallet)
    }

    /// Creates and saves a new keystore, optionally seeded for deterministic testing.
    pub fn create_keystore(
        &self,
        testing_prng_seed: Option<u64>,
    ) -> Result<linera_wallet_json::Keystore, Error> {
        let keystore_path = self.keystore_path()?;
        if keystore_path.exists() {
            bail!("Keystore already exists: {}", keystore_path.display());
        }
        Ok(linera_wallet_json::Keystore::create(
            &keystore_path,
            testing_prng_seed,

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. If you intended a fresh wallet: back up and remove/rename the existing file at the printed path (it contains your keys — do not delete blindly).
  2. Use a separate wallet via --with-wallet NAME, which resolves a suffixed wallet path (and LINERA_WALLET_NAME env), keeping both.
  3. Or point creation at another location with --wallet-state-path <new-path>.
  4. If the existing wallet is the one you want, skip creation and just use it.

Example fix

# before
$ linera wallet create --genesis genesis.json
Error: Wallet already exists: /home/user/.config/linera/wallet.json

# after (keep both)
$ linera wallet create --with-wallet testnet2 --genesis genesis.json
# or start over (keys are lost!)
$ mv ~/.config/linera/wallet.json ~/.config/linera/wallet.json.bak && linera wallet create --genesis genesis.json
Defensive patterns

Strategy: validation

Validate before calling

// Before create_wallet:
let path = options.wallet_path()?;
if path.exists() {
    // decide: reuse it, or target a different wallet via --with-wallet / --wallet-state-path
    anyhow::bail!("refusing to overwrite existing wallet at {}", path.display());
}

Try / catch

match options.create_wallet(genesis) {
    Ok(w) => w,
    Err(e) if e.to_string().contains("Wallet already exists") => {
        options.wallet()? // intended reuse path
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Running a create/genesis command twice; the default wallet path already holding a wallet from an earlier run or another network; LINERA_WALLET env var pointing at an existing file; a leftover wallet in a shared container/home directory.

Common situations: Re-running setup scripts that assume a clean machine; switching networks (devnet to testnet) without moving the old wallet; container images that persist $HOME between runs.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/92dbd8e72d4c1917. Report an issue: GitHub.