ipfs/kubo · error

invalid peer id

Error message

invalid peer id

What it means

`ipfs id <peerid>` decodes its first positional argument with `peer.Decode`. If the string is not a valid libp2p peer ID (correct multibase/multihash encoding), the command returns 'invalid peer id'. This is a pure input-parsing failure before any network activity.

Source

Thrown at core/commands/id.go:85

		cmds.StringOption(idFormatOptionName, "Encoding used for peer IDs: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("b58mh"),
	},
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
		keyEnc, err := ke.KeyEncoderFromString(req.Options[idFormatOptionName].(string))
		if err != nil {
			return err
		}

		n, err := cmdenv.GetNode(env)
		if err != nil {
			return err
		}

		var id peer.ID
		if len(req.Arguments) > 0 {
			var err error
			id, err = peer.Decode(req.Arguments[0])
			if err != nil {
				return errors.New("invalid peer id")
			}
		} else {
			id = n.Identity
		}

		if id == n.Identity {
			output, err := printSelf(keyEnc, n)
			if err != nil {
				return err
			}
			return cmds.EmitOnce(res, output)
		}

		offline, _ := req.Options[OfflineOption].(bool)
		if !offline && !n.IsOnline {
			return errors.New(offlineIDErrorMessage)
		}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Verify the peer ID string is complete and correctly copied (no truncation, no whitespace).
  2. If the ID is CIDv1-encoded (starts with 1 or 2, e.g. base36 `k...` or base32 `b...`), pass `--peerid-base=base36` or `base32`.
  3. If you have a multiaddr, extract only the `/p2p/<peerid>` component (or use `/p2p/` part) and pass just the ID.
  4. Cross-check the peer ID with `ipfs key list -l` or `ipfs id` of a node you control.

Example fix

// before
ipfs id k2k4r8k9...            // fails: CIDv1 peer id not decodable as default base
// after
ipfs id --peerid-base=base36 k2k4r8k9...
Defensive patterns

Strategy: validation

Validate before calling

import "github.com/libp2p/go-libp2p/core/peer"

if _, err := peer.Decode(peerIDArg); err != nil {
    return fmt.Errorf("not a valid peer id %q: %w", peerIDArg, err)
}

Try / catch

if _, err := sh.Request("id", peerID).Send(ctx); err != nil {
    if strings.Contains(err.Error(), "invalid peer id") {
        // try alternate peer-id bases
        _, err = sh.Request("id", peerID).Option("peerid-base", "base36").Send(ctx)
    }
}

Prevention

When it happens

Trigger: Passing a truncated or typo'd peer ID; passing a base58 peer ID while it was produced in base36/base32 (CIDv1-style peer IDs, common with new IPNS keys); passing something that is not a peer ID at all (e.g. a CID of content, a multiaddr, or a file path).

Common situations: Copy-paste truncation of long peer IDs; new-style RSA/Ed25519 peer IDs rendered in base36 that need `--peerid-base` set; confusing an IPNS key/CID with a peer ID; empty or whitespace argument from an unexpanded shell variable.

Related errors


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