hyperledger/fabric · error
chaincode %s not found
Error message
chaincode %s not found
What it means
ChaincodeEndorsementInfo returns this error when the state query succeeds but returns nil bytes, meaning no chaincode definition with that name exists in the lscc namespace on the channel. Unlike 1216, the ledger is fine — the chaincode simply is not defined/deployed there.
Source
Thrown at core/scc/lscc/lscc.go:262
// chaincode under these conditions. More info on
// https://jira.hyperledger.org/browse/FAB-3156
if fsData.InstantiationPolicy != nil {
if !bytes.Equal(fsData.InstantiationPolicy, cd.InstantiationPolicy) {
return fmt.Errorf("Instantiation policy mismatch for cc %s", cd.ChaincodeID())
}
}
return nil
}
func (lscc *SCC) ChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*lifecycle.ChaincodeEndorsementInfo, error) {
chaincodeDataBytes, err := qe.GetState("lscc", chaincodeName)
if err != nil {
return nil, errors.Wrapf(err, "could not retrieve state for chaincode %s", chaincodeName)
}
if chaincodeDataBytes == nil {
return nil, errors.Errorf("chaincode %s not found", chaincodeName)
}
chaincodeData := &ccprovider.ChaincodeData{}
err = proto.Unmarshal(chaincodeDataBytes, chaincodeData)
if err != nil {
return nil, errors.Wrapf(err, "chaincode %s has bad definition", chaincodeName)
}
ls := &LegacySecurity{
Support: lscc.Support,
PackageCache: &lscc.PackageCache,
}
err = ls.SecurityCheckLegacyChaincode(chaincodeData)
if err != nil {
return nil, errors.WithMessage(err, "failed security checks")
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Verify the chaincode name spelling and that the definition was committed on that channel (peer chaincode list --installed / queryinstalled)
- Commit the chaincode definition first (lifecycle approve/commit) before querying endorsement info
- Confirm you are querying the correct channel and a peer joined to it
- If the chaincode was migrated/renamed, use the new name
Example fix
// before
info, err := lscc.ChaincodeEndorsementInfo("mychannel", "mycc2", qe) // typo'd name
// after
name := "mycc"
info, err := lscc.ChaincodeEndorsementInfo("mychannel", name, qe)
if err != nil && strings.Contains(err.Error(), "not found") { /* handle undefined chaincode */ } Defensive patterns
Strategy: validation
Validate before calling
// Go: check definition exists before requesting endorsement info
raw, err := qe.GetState("lscc", chaincodeName)
if err != nil { return err }
if raw == nil {
return fmt.Errorf("chaincode %q is not defined on this channel; approve/commit first", chaincodeName)
} Try / catch
// Go
info, err := lscc.ChaincodeEndorsementInfo(channelID, name, qe)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf("chaincode %s not found", name)) {
return fmt.Errorf("no definition for %q: commit it via lifecycle or correct the name", name)
}
return err
} Prevention
- Commit the chaincode definition (approveformyorg + commit) before querying endorsement info
- Double-check chaincode name spelling and target channel in CLI/SDK calls
- Verify with `peer chaincode list --channelID` that the definition exists
- Confirm the queried peer is joined to the channel where the chaincode is defined
When it happens
Trigger: Calling ChaincodeEndorsementInfo(channelID, chaincodeName, qe) with a chaincodeName that was never installed/defined on the channel, or after it was removed; also querying the wrong channel where the chaincode isn't defined.
Common situations: Typo in the chaincode name in CLI/SDK calls; querying before the chaincode definition was committed; querying a peer not joined to the channel where the chaincode is defined; referencing a removed/renamed chaincode.
Related errors
- lscc's state for [%s] not found.
- Upgrading non-existent chaincode %s
- organization %s not found
- no such block number [%d] in index
- failed unmarshalling lscc read value into ChaincodeData
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/74027ee49635b980.
Report an issue: GitHub.