hyperledger/fabric · error
empty JSON chaincode parameters must contain the following k
Error message
empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'
What it means
This error is thrown by checkChaincodeCmdParams when the --ctor JSON string is empty or cannot be parsed into a non-empty map, i.e. the chaincode call parameters are missing entirely. The CLI requires constructor parameters to contain 'Args', or 'Function' and 'Args'. An empty payload gives the chaincode nothing to execute.
Source
Thrown at internal/peer/chaincode/common.go:306
// Generic JSON with interface{}
if chaincodeCtorJSON != "{}" {
var f any
err := json.Unmarshal([]byte(chaincodeCtorJSON), &f)
if err != nil {
return errors.Wrap(err, "chaincode argument error")
}
m := f.(map[string]any)
sm := make(map[string]any)
for k := range m {
sm[strings.ToLower(k)] = m[k]
}
_, argsPresent := sm["args"]
_, funcPresent := sm["function"]
if !argsPresent || (len(m) == 2 && !funcPresent) || len(m) > 2 {
return errors.New("non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'")
}
} else {
return errors.New("empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'")
}
return nil
}
func validatePeerConnectionParameters(cmdName string) error {
if connectionProfile != common.UndefinedParamValue {
networkConfig, err := common.GetConfig(connectionProfile)
if err != nil {
return err
}
if len(networkConfig.Channels[channelID].Peers) != 0 {
peerAddresses = []string{}
tlsRootCertFiles = []string{}
for peer, peerChannelConfig := range networkConfig.Channels[channelID].Peers {
if peerChannelConfig.EndorsingPeer {
peerConfig, ok := networkConfig.Peers[peer]
if !ok {View on GitHub (pinned to 2736b63f8f)
Solutions
- Pass a valid ctor: --ctor '{"Args":["Init"]}'
- If the chaincode takes no arguments, still pass --ctor '{"Args":[]}'
- Check shell quoting so the JSON isn't dropped: quote the whole argument
- Verify the command variable in scripts isn't empty before exec
Example fix
// before
peer chaincode invoke -C mychannel -n mycc --ctor ''
// after
peer chaincode invoke -C mychannel -n mycc --ctor '{"Args":["Init","a","1","b","2"]}' Defensive patterns
Strategy: validation
Validate before calling
[ -n "$CTOR" ] && echo "$CTOR" | jq -e 'type == "object" and (has("Args") or has("args"))' >/dev/null || { echo 'ctor must be non-empty JSON with Args'; exit 1; } Prevention
- Never omit --ctor for invoke/query commands
- For no-arg calls use {"Args":[]}
- Quote ctor variables in shell: "${CTOR}"
- Add a pre-flight check in scripts that CTOR is set and valid JSON
When it happens
Trigger: Running a peer chaincode command with --ctor '' or omitting --ctor entirely, or passing a value that parses to an empty map (e.g. '{}' is empty JSON object yielding empty map).
Common situations: Forgetting the --ctor flag on invoke/query, shell quoting dropping the argument, scripts building the command with an empty variable, or migrating commands where the ctor was removed accidentally.
Related errors
- non-empty JSON chaincode parameters must contain the followi
- Must supply channel ID
- Must supply genesis block file
- Must supply genesis block path
- the required parameter 'snapshotpath' is empty. Rerun the co
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/dc4add0c67a0e18e.
Report an issue: GitHub.