hyperledger/fabric · error
could not fetch approved chaincode definition (name: '%s', s
Error message
could not fetch approved chaincode definition (name: '%s', sequence: '%d') on channel '%s'
What it means
QueryApprovedChaincodeDefinition looked in the org's private (org-scoped) state for the approved definition at the requested name and sequence, and found no metadata entry — i.e., this org has not approved that chaincode at that sequence on that channel.
Source
Thrown at core/chaincode/lifecycle/lifecycle.go:582
privateName := fmt.Sprintf("%s#%d", ccname, nextSequence)
_, ok, err := ef.Resources.Serializer.DeserializeMetadata(NamespacesName, privateName, orgState)
if err != nil {
return nil, errors.WithMessagef(err, "could not deserialize namespace metadata for next sequence %d", nextSequence)
}
if ok {
requestedSequence = nextSequence
}
}
logger.Infof("Attempting to fetch approved definition (name: '%s', sequence: '%d') on channel '%s'", ccname, requestedSequence, chname)
privateName := fmt.Sprintf("%s#%d", ccname, requestedSequence)
metadata, ok, err := ef.Resources.Serializer.DeserializeMetadata(NamespacesName, privateName, orgState)
if err != nil {
return nil, errors.WithMessagef(err, "could not deserialize namespace metadata for %s", privateName)
}
if !ok {
return nil, errors.Errorf("could not fetch approved chaincode definition (name: '%s', sequence: '%d') on channel '%s'", ccname, requestedSequence, chname)
}
return ef.fetchApprovedChaincodeDefinition(ccname, requestedSequence, metadata, orgState)
}
// QueryApprovedChaincodeDefinitions returns all approved chaincode definitions in Org state for the specified channel.
// The return value is a map where the key is a combination of chaincode namespace and sequence number in the format "<namespace>#<sequence_number>",
// and the value is the corresponding ApprovedChaincodeDefinition object.
func (ef *ExternalFunctions) QueryApprovedChaincodeDefinitions(chname string, orgState ReadRangeableState) (map[string]*ApprovedChaincodeDefinition, error) {
// Get all metadatas for the channel
metadatas, err := ef.Resources.Serializer.DeserializeAllMetadata(NamespacesName, orgState)
if err != nil {
return nil, errors.WithMessage(err, "could not fetch metadatas")
}
// Get all approved chaincode definitions using the metadatas
definitions := map[string]*ApprovedChaincodeDefinition{}
for privateName, metadata := range metadatas {View on GitHub (pinned to 2736b63f8f)
Solutions
- Confirm the sequence number matches what was approved (querycommitted / checkcommitreadiness)
- Run the query on a peer belonging to the org that performed the approval
- Verify chaincode name and channel name spelling; if not yet approved, run approveformyorg first
Example fix
// before
queryApproved("mycc", seq=3) // org approved seq 2 only
// after
queryApproved("mycc", seq=2) // match the approved sequence Defensive patterns
Strategy: validation
Validate before calling
// Confirm this org approved the exact sequence before querying
approved, err := orgApprovedSequences(ch, ccname) // from org private state / checkcommitreadiness
if !contains(approved, requestedSequence) {
return fmt.Errorf("org has no approved definition for %s seq %d; run approveformyorg first", ccname, requestedSequence)
} Try / catch
def, err := ef.QueryApprovedChaincodeDefinition(ch, ccname, myOrg, seq)
if err != nil && strings.Contains(err.Error(), "could not fetch approved chaincode definition") {
// run approveformyorg at that sequence, or correct the sequence/name
} Prevention
- Query on a peer of the org that executed the approval
- Wait for the approve transaction to commit before querying
- Keep sequence numbers in shared deployment state to avoid mismatches
When it happens
Trigger: Calling QueryApprovedChaincodeDefinition with a sequence the org never approved, a chaincode name typo, querying on a peer whose org has not approved, or querying before approval completed.
Common situations: Operators checking the wrong org's peer; querying with the wrong --sequence; race between approve transaction commit and the query; channel name mismatch.
Related errors
- query iterator not found
- application config does not exist for channel '%s'
- unknown chaincode '%s' for channel '%s'
- could not find chaincode with package id '%s'
- requested sequence is 0, but first definable sequence number
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/fa9e5cc745ec0e8e.
Report an issue: GitHub.