ipfs/kubo · error

unrecognized multihash function: %s

Error message

unrecognized multihash function: %s

What it means

`ipfs block put --mhtype <name>` (or Import.HashFunction config) must name a multihash function present in the mh.Names registry. The given string is not a known multihash name, so hashing cannot proceed. Default comes from cfg.Import.HashFunction when the option is empty.

Source

Thrown at core/commands/block.go:201

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

		cfg, err := nd.Repo.Config()
		if err != nil {
			return err
		}

		mhtype, _ := req.Options[mhtypeOptionName].(string)
		if mhtype == "" {
			mhtype = cfg.Import.HashFunction.WithDefault(config.DefaultHashFunction)
		}

		mhtval, ok := mh.Names[mhtype]
		if !ok {
			return fmt.Errorf("unrecognized multihash function: %s", mhtype)
		}

		mhlen, ok := req.Options[mhlenOptionName].(int)
		if !ok {
			return errors.New("missing option \"mhlen\"")
		}

		cidCodec, _ := req.Options[blockCidCodecOptionName].(string)
		format, _ := req.Options[blockFormatOptionName].(string) // deprecated

		// use of legacy 'format' needs to suppress 'cid-codec'
		if format != "" {
			if cidCodec != "" && cidCodec != "raw" {
				return fmt.Errorf("unable to use %q (deprecated) and a custom %q at the same time", blockFormatOptionName, blockCidCodecOptionName)
			}
			cidCodec = "" // makes it no-op
		}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Use a valid multihash name, e.g. --mhtype sha2-256 or --mhtype sha2-512
  2. List valid choices from the multihash registry (sha2-256, sha2-512, sha3-512, blake2b-256, identity, etc.)
  3. Check the Import.HashFunction config value if no --mhtype was passed: ipfs config Import.HashFunction

Example fix

// before
ipfs block put --mhtype sha256 data.bin
// after
ipfs block put --mhtype sha2-256 data.bin
Defensive patterns

Strategy: validation

Validate before calling

// shell: whitelist allowed hash names before passing --mhtype
case "$MH" in
  sha2-256|sha2-512|sha3-512|blake2b-256|blake2b-512|identity) ;;
  *) echo "unsupported mhtype: $MH" >&2; exit 1 ;;
esac
ipfs block put --mhtype "$MH" data.bin

Prevention

When it happens

Trigger: Run `ipfs block put --mhtype sha3512` (typo); --mhtype with a codec name instead of a hash name; mh.Names[mhtype] lookup fails for any misspelled or unsupported hash function.

Common situations: Typos in multihash names; users assuming any multicodec name is valid (e.g. passing 'blake3' variants not compiled in); scripts copying flags between commands where the option means something else.

Related errors


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