hyperledger/fabric · error

failed to get transaction context

Error message

failed to get transaction context

What it means

HandleInvokeChaincode was called for a non-system chaincode but no valid transaction simulator/ledger context could be obtained for the channel+txid, so the invocation cannot execute against the ledger.

Source

Thrown at core/chaincode/handler.go:1118

	// Get the chaincodeID to invoke. The chaincodeID to be called may
	// contain composite info like "chaincode-name:version/channel-name"
	// We are not using version now but default to the latest
	targetInstance := ParseName(chaincodeSpec.ChaincodeId.Name)

	// If targetInstance is not an SCC, isValidTxSim should be called which will return an err.
	// We do not want to propagate calls to user CCs when the original call was to a SCC
	// without a channel context (ie, no ledger context).
	if !h.BuiltinSCCs.IsSysCC(targetInstance.ChaincodeName) {
		// normal path - UCC invocation with an empty ("") channel: isValidTxSim will return an error
		return h.isValidTxSim("", txid, "could not get valid transaction")
	}

	// Calling SCC without a ChannelID, then the assumption this is an external SCC called by the client (special case) and no UCC involved,
	// so no Transaction Simulator validation needed as there are no commits to the ledger, get the txContext directly if it is not nil
	txContext := h.TXContexts.Get(channelID, txid)
	if txContext == nil {
		return nil, errors.New("failed to get transaction context")
	}

	return txContext, nil
}

func (h *Handler) HandlePutState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) {
	putState := &pb.PutState{}
	if err := proto.Unmarshal(msg.Payload, putState); err != nil {
		return nil, errors.Wrap(err, "unmarshal failed")
	}

	if err := h.putState(putState, txContext); err != nil {
		return nil, errors.WithStack(err)
	}

	return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Verify the invocation carries a valid channel context (channel exists, txid not already cleaned up)
  2. Retry the transaction; if persistent, check transaction-context lifecycle logs on the peer
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at core/chaincode/handler.go:1118 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/cb110b8aa8025bd2. Report an issue: GitHub.