hyperledger/fabric · error

could not find chaincode with package id '%s'

Error message

could not find chaincode with package id '%s'

What it means

GetInstalledChaincode scans the locally installed chaincode packages for a matching PackageID and throws this when no installed package matches. The package ID is derived from hashing the package contents, so only packages installed on this peer's filesystem can be found.

Source

Thrown at core/chaincode/lifecycle/cache.go:424

// GetInstalledChaincode returns all of the information about a specific
// installed chaincode.
func (c *Cache) GetInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error) {
	c.mutex.RLock()
	defer c.mutex.RUnlock()

	for _, lc := range c.localChaincodes {
		if lc.Info == nil {
			// the update function adds an entry to localChaincodes
			// even if it isn't yet installed
			continue
		}
		if lc.Info.PackageID == packageID {
			return lc.ToInstalledChaincode(), nil
		}
	}

	return nil, errors.Errorf("could not find chaincode with package id '%s'", packageID)
}

// update should only be called with the write lock already held
func (c *Cache) update(initializing bool, channelID string, dirtyChaincodes map[string]struct{}, qe ledger.SimpleQueryExecutor) error {
	channelCache, ok := c.definedChaincodes[channelID]
	if !ok {
		channelCache = &ChannelCache{
			Chaincodes:        map[string]*CachedChaincodeDefinition{},
			InterestingHashes: map[string]string{},
		}
		c.definedChaincodes[channelID] = channelCache
	}

	publicState := &SimpleQueryExecutorShim{
		Namespace:           LifecycleNamespace,
		SimpleQueryExecutor: qe,
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Run 'peer lifecycle chaincode install <package.tar.gz>' on this peer to install the package.
  2. List installed packages ('peer lifecycle chaincode queryinstalled') and use a PackageID actually present in the output.
  3. Verify CORE_PEER_FILESYSTEMPATH points to the directory containing the installed packages (lifecycle/chaincodes).
  4. Reinstall if the install DB is inconsistent (peer upgraded or filesystem copied partially).

Example fix

// before: hardcoded ID from another peer
pkg, err := cache.GetInstalledChaincode("hash:1234...")
// after: resolve from this peer's installed list
installed, _ := lc.ListInstalledChaincodes()
for _, ic := range installed {
    if ic.PackageID == wantID { pkg, err = cache.GetInstalledChaincode(wantID); break }
}
Defensive patterns

Strategy: validation

Validate before calling

installed, err := lc.ListInstalledChaincodes()
if err != nil { return err }
found := false
for _, ic := range installed {
    if ic.PackageID == packageID { found = true; break }
}
if !found { return fmt.Errorf("package %s not installed on this peer", packageID) }

Try / catch

pkg, err := cache.GetInstalledChaincode(packageID)
if err != nil && strings.Contains(err.Error(), "could not find chaincode with package id") {
    return nil, ErrPackageNotInstalled
}

Prevention

When it happens

Trigger: Calling GetInstalledChaincode(packageID) with a PackageID that was never installed on this peer, or one installed after the call / on a different peer.

Common situations: Copy-pasting a PackageID from another peer's output; package installed but peer restarted with a different peerFileSystem path (CORE_PEER_FILESYSTEMPATH); package removed or install DB out of sync.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/ecbda1eb95be878d. Report an issue: GitHub.