hyperledger/fabric · error

no chaincode spec is provided, channel id [%s]

Error message

no chaincode spec is provided, channel id [%s]

What it means

Returned by getChannelAndChaincodeFromSignedProposal (internal/pkg/gateway/evaluate.go:143) when the invocation spec extracted from the proposal has a nil ChaincodeSpec. The proposal parsed successfully and had a channel, but the chaincode invocation details are missing. The gateway cannot determine what chaincode to query.

Source

Thrown at internal/pkg/gateway/evaluate.go:143

	channelHeader, err := protoutil.UnmarshalChannelHeader(header.GetChannelHeader())
	if err != nil {
		return "", "", false, err
	}
	payload, err := protoutil.UnmarshalChaincodeProposalPayload(proposal.GetPayload())
	if err != nil {
		return "", "", false, err
	}
	spec, err := protoutil.UnmarshalChaincodeInvocationSpec(payload.GetInput())
	if err != nil {
		return "", "", false, err
	}

	if len(channelHeader.GetChannelId()) == 0 {
		return "", "", false, fmt.Errorf("no channel id provided")
	}

	if spec.GetChaincodeSpec() == nil {
		return "", "", false, fmt.Errorf("no chaincode spec is provided, channel id [%s]", channelHeader.GetChannelId())
	}

	if spec.GetChaincodeSpec().GetChaincodeId() == nil {
		return "", "", false, fmt.Errorf("no chaincode id is provided, channel id [%s]", channelHeader.GetChannelId())
	}

	if len(spec.GetChaincodeSpec().GetChaincodeId().GetName()) == 0 {
		return "", "", false, fmt.Errorf("no chaincode name is provided, channel id [%s]", channelHeader.GetChannelId())
	}

	return channelHeader.GetChannelId(), spec.GetChaincodeSpec().GetChaincodeId().GetName(), len(payload.TransientMap) > 0, nil
}

func getResultFromProposalResponse(proposalResponse *peer.ProposalResponse) ([]byte, error) {
	responsePayload := &peer.ProposalResponsePayload{}
	if err := proto.Unmarshal(proposalResponse.GetPayload(), responsePayload); err != nil {
		return nil, errors.Wrap(err, "failed to deserialize proposal response payload")
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Populate ChaincodeSpec (chaincode id/name, type, input args) when constructing the ChaincodeInvocationSpec.
  2. Use protoutil.CreateChaincodeSpec / SDK proposal builders so the spec is always set.
  3. Log/inspect payload.GetInput() to verify the incoming proposal content before calling Evaluate.
  4. Fix client code that sends a zero-value ChaincodeInvocationSpec.

Example fix

// before
invocationSpec := &peer.ChaincodeInvocationSpec{} // nil ChaincodeSpec
// after
invocationSpec := &peer.ChaincodeInvocationSpec{
    ChaincodeSpec: &peer.ChaincodeSpec{
        Type: peer.ChaincodeSpec_NODE,
        ChaincodeId: &peer.ChaincodeID{Name: "mycc"},
        Input: &peer.ChaincodeInput{Args: [][]byte{[]byte("query")}},
    },
}
Defensive patterns

Strategy: validation

Validate before calling

func validateChaincodeSpec(sp *peer.SignedProposal) error {
    proposal, _ := protoutil.UnmarshalProposal(sp.GetProposalBytes())
    payload, err := protoutil.UnmarshalPayload(proposal.GetPayload())
    if err != nil {
        return err
    }
    spec, err := protoutil.UnmarshalChaincodeInvocationSpec(payload.GetInput())
    if err != nil {
        return err
    }
    if spec.GetChaincodeSpec() == nil {
        return errors.New("proposal invocation spec missing chaincode spec")
    }
    return nil
}

Type guard

func hasChaincodeSpec(spec *peer.ChaincodeInvocationSpec) bool {
    return spec != nil && spec.GetChaincodeSpec() != nil
}

Prevention

When it happens

Trigger: Evaluate called with a proposal whose ChaincodeInvocationSpec has no ChaincodeSpec set — e.g. payload.Input marshalled with an empty or default ChaincodeInvocationSpec.

Common situations: Manually building the payload without invoking spec.ChaincodeSpec = &peer.ChaincodeSpec{...}; deserializing a proposal created by a tool that omits the spec; template proposals copied without the invocation section.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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