hyperledger/fabric · error

could not fetch chaincode-source metadata for %s

Error message

could not fetch chaincode-source metadata for %s

What it means

This error is thrown by the lifecycle approved-chaincode lookup when the chaincode-source metadata key (e.g. <name>#<sequence> in the org's private collection state) cannot be found during deserialization. The serializer reported no entry exists for that private name, meaning the peer does not have the approved chaincode definition recorded for that sequence. It surfaces to users as 'could not fetch chaincode-source metadata for <name>#<seq>' from QueryApprovedChaincodeDefinition(s).

Source

Thrown at core/chaincode/lifecycle/lifecycle.go:638

	privateName := fmt.Sprintf("%s#%d", ccname, sequence)
	// Verify that metadata type is chaincode parameters type
	if metadata.Datatype != ChaincodeParametersType {
		return nil, errors.Errorf("not a chaincode parameters type: %s", metadata.Datatype)
	}

	// Get chaincode parameters for the requested sequence
	ccParameters := &ChaincodeParameters{}
	if err := ef.Resources.Serializer.Deserialize(NamespacesName, privateName, metadata, ccParameters, orgState); err != nil {
		return nil, errors.WithMessagef(err, "could not deserialize chaincode parameters for %s", privateName)
	}

	// Get package ID for the requested sequence
	metadata, ok, err := ef.Resources.Serializer.DeserializeMetadata(ChaincodeSourcesName, privateName, orgState)
	if err != nil {
		return nil, errors.WithMessagef(err, "could not deserialize chaincode-source metadata for %s", privateName)
	}
	if !ok {
		return nil, errors.Errorf("could not fetch chaincode-source metadata for %s", privateName)
	}
	if metadata.Datatype != ChaincodeLocalPackageType {
		return nil, errors.Errorf("not a chaincode local package type: %s", metadata.Datatype)
	}

	ccLocalPackage := &ChaincodeLocalPackage{}
	if err := ef.Resources.Serializer.Deserialize(ChaincodeSourcesName, privateName, metadata, ccLocalPackage, orgState); err != nil {
		return nil, errors.WithMessagef(err, "could not deserialize chaincode package for %s", privateName)
	}

	// Convert to lb.ChaincodeSource
	// An empty package ID means that the chaincode won't be invocable
	var ccsrc *lb.ChaincodeSource
	if ccLocalPackage.PackageID != "" {
		ccsrc = &lb.ChaincodeSource{
			Type: &lb.ChaincodeSource_LocalPackage{
				LocalPackage: &lb.ChaincodeSource_Local{
					PackageId: ccLocalPackage.PackageID,

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Run 'peer lifecycle chaincode approveformyorg' for the exact name and sequence on this org before querying
  2. Verify the sequence number with 'peer lifecycle chaincode checkcommitreadiness' or querycommitted to see the committed sequence
  3. Confirm you are querying the peer of the org whose approval you expect; approvals are org-private
  4. Check the chaincode name spelling matches exactly what was approved

Example fix

// before: query before approval
peer lifecycle chaincode queryapproved --channelID mychannel --name mycc
// error
// after: approve first, then query
peer lifecycle chaincode approveformyorg -C mychannel --name mycc --version 1.0 --sequence 1 --package-id <pkgID>
peer lifecycle chaincode queryapproved -C mychannel --name mycc
Defensive patterns

Strategy: validation

Validate before calling

// Before querying, verify the org approved this name+sequence:
// peer lifecycle chaincode checkcommitreadiness -C mychannel --name mycc --version 1.0 --sequence 1
// exit code / output shows which orgs approved; only query where your org shows true.
const approved = checkCommitReadinessOutput.Approvals[orgMSP];
if (approved !== true) throw new Error('approveformyorg required before queryapproved');

Try / catch

try {
  def := lifecycle.QueryApprovedChaincodeDefinition(channel, name, seq)
} catch (err) {
  if strings.Contains(err.Error(), "could not fetch chaincode-source metadata") {
    // treat as 'not approved on this org'
  }
}

Prevention

When it happens

Trigger: Calling QueryApprovedChaincodeDefinition/QueryApprovedChaincodeDefinitions for a name+sequence that the local org never approved, or querying with the wrong sequence number, or the org's metadata key is missing from its collection state (approval exists under a different sequence).

Common situations: Operator runs peer lifecycle chaincode queryapproved without first running approveformyorg on this peer; sequence number incremented but the new approval not committed on this org; querying on a different org's peer that has not approved; typo in chaincode name.

Related errors


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