Skip to content
Latchkey

Anchor "Error: Unable to read keypair file" in CI

Anchor read the wallet path from Anchor.toml (or the Solana config) and could not open the keypair file there. In CI the default ~/.config/solana/id.json does not exist unless a keypair is generated first.

What this error means

anchor build or anchor test fails with "Error: Unable to read keypair file" and a path such as /home/runner/.config/solana/id.json.

Anchor
Error: Unable to read keypair file (/home/runner/.config/solana/id.json): No such file or directory (os error 2)

Common causes

No keypair exists at the configured path

A fresh runner has no Solana keypair, so the default id.json referenced by the wallet setting is missing.

Anchor.toml points at a path not present in CI

The [provider] wallet value references a file that exists locally but was never created or provided on the runner.

How to fix it

Generate a keypair before building

Create a throwaway keypair at the expected path so Anchor can read it.

Terminal
solana-keygen new --no-bip39-passphrase -o ~/.config/solana/id.json

Point the wallet at an existing file

Set the provider wallet in Anchor.toml to a path you create in CI.

Anchor.toml
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

How to prevent it

  • Generate a keypair as a setup step before anchor commands.
  • Keep the wallet path in Anchor.toml consistent with what CI creates.
  • Never commit real keypairs; generate throwaway ones for CI.

Frequently asked questions

What causes ""Unable to read keypair file""?
A fresh runner has no Solana keypair, so the default id.json referenced by the wallet setting is missing.
How do I fix "Unable to read keypair file"?
Create a throwaway keypair at the expected path so Anchor can read it.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card