ipfs/kubo · error

cannot get key encoder: %w

Error message

cannot get key encoder: %w

What it means

`ipfs key list` failed to build an encoder for the `--ipns-base` option value. KeyEncoderFromString only accepts bases like base36, base32, base58btc, base16, etc.; any unsupported or misspelled multibase name produces this wrapped error.

Source

Thrown at core/commands/keystore.go:593

			_, err := w.Write([]byte(ko.Id + "\n"))
			return err
		}),
	},
	Type: KeyOutput{},
}

var keyListCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "List all local keypairs.",
	},
	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()),

View on GitHub (pinned to 329838acdf)

Solutions

  1. Use a valid multibase name, e.g. `ipfs key list --ipns-base=base36` (default) or base58btc/base32/base16
  2. Check the supported list in `ipfs key list --help` / multibase docs and fix the value in your script
  3. Remove the flag entirely to use the default

Example fix

// before
$ ipfs key list --ipns-base=base58
Error: cannot get key encoder: ...
// after
$ ipfs key list --ipns-base=base58btc
Defensive patterns

Strategy: validation

Validate before calling

var validBases = map[string]bool{"base36": true, "base32": true, "base58btc": true, "base58flickr": true, "base16": true, "base2": true, "identity": true}
if !validBases[ipnsBase] {
    return fmt.Errorf("invalid --ipns-base %q", ipnsBase)
}

Prevention

When it happens

Trigger: `ipfs key list --ipns-base=base58` (invalid name), `--ipns-base=xyz`, or an empty/garbled value from a script variable.

Common situations: Old scripts written for pre-base36 defaults using `base58` shorthand instead of `base58btc`; typos in CI configuration; copying base names from other tools.

Related errors


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