hyperledger/fabric · error

chaincode '%s' is already initialized but called as init

Error message

chaincode '%s' is already initialized but called as init

What it means

Returned by lifecycle CheckInvocation when a chaincode invocation carries IsInit=true but the chaincode is already initialized (the ledger's 'initialized' key matches the current version). Re-running init on an already-initialized chaincode is rejected to preserve the init/normal-call contract.

Source

Thrown at core/chaincode/chaincode_support.go:251

		value, err := txParams.TXSimulator.GetState(chaincodeName, InitializedKeyName)
		if err != nil {
			return "", 0, errors.WithMessage(err, "could not get 'initialized' key")
		}

		needsInitialization = !bytes.Equal(value, []byte(cii.Version))
	}

	// Note, IsInit is a new field for v2.0 and should only be set for invocations of non-legacy chaincodes.
	// Any invocation of a legacy chaincode with IsInit set will fail.  This is desirable, as the old
	// InstantiationPolicy contract enforces which users may call init.
	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.

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Invoke the chaincode normally (without the --isInit flag) after first initialization
  2. If re-initialization is genuinely needed, use a new chaincode version or an explicit upgrade/init flow
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/chaincode/chaincode_support.go:251 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/c4b715ef03417578. Report an issue: GitHub.