ipfs/kubo · error
unknowm mhType %d
Error message
unknowm mhType %d
What it means
BlockAPI.Put validates the requested multihash type by looking up px.MhType in the mh.Codes table; if the code is not a registered multihash function it returns this error (note the 'unknowm' typo in the message). The client refuses to ask the daemon to build a block with a hash function it cannot name.
Source
Thrown at client/rpc/block.go:43
func (s *blockStat) Size() int {
return s.BSize
}
func (s *blockStat) Path() path.ImmutablePath {
return path.FromCid(s.cid)
}
func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockPutOption) (iface.BlockStat, error) {
options, err := caopts.BlockPutOptions(opts...)
px := options.CidPrefix
if err != nil {
return nil, err
}
mht, ok := mh.Codes[px.MhType]
if !ok {
return nil, fmt.Errorf("unknowm mhType %d", px.MhType)
}
var cidOptKey, cidOptVal string
switch {
case px.Version == 0 && px.Codec == cid.DagProtobuf:
// ensure legacy --format=v0 passes as BlockPutOption still works
cidOptKey = "format"
cidOptVal = "v0"
default:
// pass codec as string
cidOptKey = "cid-codec"
cidOptVal = mc.Code(px.Codec).String()
}
req := api.core().Request("block/put").
Option("mhtype", mht).
Option("mhlen", px.MhLength).
Option(cidOptKey, cidOptVal).View on GitHub (pinned to 329838acdf)
Solutions
- Use a registered multihash constant, e.g. mh.SHA2_256 (0x12), mh.SHA2_512 (0x40), mh.SHA3_256 (0x16), mh.BLAKE2B_MIN+31, or mh.IDENTITY (0x00 is NOT identity; use mh.IDENTITY for raw identity hashes).
- If you need a custom multihash code, register it with mh.Codes before calling Put so the lookup succeeds.
- Check the value you pass to opts.Block.MhType against the table in github.com/multiformats/go-multihash (mh.Codes) to confirm it is registered.
Example fix
// before
blk, err := api.Block().Put(ctx, r, opts.Block.MhType(0x00).Codec(cid.DagProtobuf).Format("cbor"))
// after
blk, err := api.Block().Put(ctx, r, opts.Block.MhType(mh.SHA2_256).Codec(cid.DagProtobuf).Format("cbor")) Defensive patterns
Strategy: validation
Validate before calling
if _, ok := mh.Codes[mhType]; !ok {
return fmt.Errorf("mhType %d is not a registered multihash code", mhType)
}
// proceed to api.Block().Put with opts.Block.MhType(mhType) Prevention
- Always use named constants (mh.SHA2_256, mh.IDENTITY) instead of numeric literals for MhType
- Register any custom multihash code with mh.Codes before calling Put
- Consult go-multihash mh.Codes when unsure whether a code is supported
When it happens
Trigger: Calling api.Block().Put(ctx, reader, opts.Block.MhType(x).Codec(cidCode).Format(format)) where x is 0, a negative value, or an unregistered/proprietary multihash code not present in mh.Codes.
Common situations: Hand-written constants for MhType (e.g. 0x00 or a typo'd hex value), custom hash functions registered only on the daemon but not in the client's multihash table, or copying option values from an old example that predates the multihash registry.
Related errors
- only sha2-255-32 is allowed with CIDv0
- unknowm mhType %d
- Import.HashFunction unrecognized: %q
- unrecognized hash function: %q
- only dag-pb is allowed with CIDv0
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/77c22bdd7034eb6e.
Report an issue: GitHub.