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
- 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).
- Use a separate wallet via --with-wallet NAME, which resolves a suffixed wallet path (and LINERA_WALLET_NAME env), keeping both.
- Or point creation at another location with --wallet-state-path <new-path>.
- 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
- Setup scripts should check wallet existence first and skip creation when present.
- Use --with-wallet suffixes for multi-network setups instead of swapping files.
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
- Keystore already exists: {}
- Cannot apply default storage because the feature 'rocksdb' w
- cannot have both a json string and file
- Cannot process inbox for follow-only chain {chain_id}. Use `
- Default wallet directory is not supported in this platform:
AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22).
Data as JSON: /api/errors/92dbd8e72d4c1917.
Report an issue: GitHub.