ipfs/kubo · error

listing keys failed: %w

Error message

listing keys failed: %w

What it means

The Key().List RPC call made by `ipfs key list` failed — kubo could not enumerate the node's keypairs. The wrapped error is the underlying cause, typically the daemon is unreachable or the repo/keystore could not be read.

Source

Thrown at core/commands/keystore.go:603

	},
	Options: []cmds.Option{
		cmds.BoolOption("l", "Show extra information about keys."),
		ke.OptionIPNSBase,
	},
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
		keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.OptionIPNSBase.Name()].(string))
		if err != nil {
			return fmt.Errorf("cannot get key encoder: %w", err)
		}

		api, err := cmdenv.GetApi(env, req)
		if err != nil {
			return err
		}

		keys, err := api.Key().List(req.Context)
		if err != nil {
			return fmt.Errorf("listing keys failed: %w", err)
		}

		list := make([]KeyOutput, 0, len(keys))

		for _, key := range keys {
			list = append(list, KeyOutput{
				Name: key.Name(),
				Id:   keyEnc.FormatID(key.ID()),
			})
		}

		return cmds.EmitOnce(res, &KeyOutputList{list})
	},
	Encoders: cmds.EncoderMap{
		cmds.Text: keyOutputListEncoders(),
	},
	Type: KeyOutputList{},
}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Start the daemon: `ipfs daemon`, then retry `ipfs key list`
  2. Check you target the right node: verify $IPFS_PATH and `--api` address / `ipfs --api=/ip4/127.0.0.1/tcp/5001 key list`
  3. Read the wrapped `%w` cause in the full error output and fix that underlying issue (connection refused, repo locked, etc.)
  4. Confirm the API address in `ipfs config Addresses.API` matches what the client uses

Example fix

// before
$ ipfs key list
Error: listing keys failed: connection refused
// after
$ ipfs daemon &
$ ipfs key list
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the daemon API is reachable before running key commands
resp, err := http.Post(apiAddr+"/api/v0/id", "", nil)
if err != nil {
    return fmt.Errorf("daemon not reachable at %s; start it with `ipfs daemon`", apiAddr)
}
resp.Body.Close()

Try / catch

if err := runKeyList(); err != nil {
    var wrapped interface{ Unwrap() error }
    if errors.As(err, &unwrapped) && strings.Contains(unwrapped.Error(), "connection refused") {
        // start daemon or fix --api address, then retry
    }
}

Prevention

When it happens

Trigger: `ipfs key list` while the daemon is not running (no API at $IPFS_PATH/api), wrong `--api` target, the daemon shut down mid-call, or repo/keystore read failure on the node side.

Common situations: Forgetting to start `ipfs daemon` before CLI commands; pointing at the wrong port with `--api`; node crash or lock contention in scripts.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/24c12e855bd8433c. Report an issue: GitHub.