hyperledger/fabric · error

chaincode '%s' has not been initialized for this version, mu

Error message

chaincode '%s' has not been initialized for this version, must call as init first

What it means

CheckInvocation guard: the chaincode requires initialization (EnforceInit) and its version's 'initialized' state key is not set, but the invocation did not use IsInit — the transaction is rejected until init runs.

Source

Thrown at core/chaincode/chaincode_support.go:263

	if input.IsInit {
		if !cii.EnforceInit {
			return "", 0, errors.Errorf("chaincode '%s' does not require initialization but called as init", chaincodeName)
		}

		if !needsInitialization {
			return "", 0, errors.Errorf("chaincode '%s' is already initialized but called as init", chaincodeName)
		}

		err = txParams.TXSimulator.SetState(chaincodeName, InitializedKeyName, []byte(cii.Version))
		if err != nil {
			return "", 0, errors.WithMessage(err, "could not set 'initialized' key")
		}

		return cii.ChaincodeID, pb.ChaincodeMessage_INIT, nil
	}

	if needsInitialization {
		return "", 0, errors.Errorf("chaincode '%s' has not been initialized for this version, must call as init first", chaincodeName)
	}

	return cii.ChaincodeID, pb.ChaincodeMessage_TRANSACTION, nil
}

// execute executes a transaction and waits for it to complete until a timeout value.
func (cs *ChaincodeSupport) execute(cctyp pb.ChaincodeMessage_Type, txParams *ccprovider.TransactionParams, namespace string, input *pb.ChaincodeInput, h *Handler) (*pb.ChaincodeMessage, error) {
	input.Decorations = txParams.ProposalDecorations

	payload, err := proto.Marshal(input)
	if err != nil {
		return nil, errors.WithMessage(err, "failed to create chaincode message")
	}

	ccMsg := &pb.ChaincodeMessage{
		Type:      cctyp,
		Payload:   payload,
		Txid:      txParams.TxID,

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Invoke the chaincode once with the init flag (--isInit) for the deployed version before normal invocations
  2. Upgrade/redeploy the chaincode if the init-compatible version was never initialized
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/chaincode/chaincode_support.go:263 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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