RPC error HTTP 400: Invalid JSON-RPC request

Last updated:

At a glance

Error details
PropertyValue
Applies toEvery network, HTTP and WebSocket
HTTP status400
JSON-RPC codes-32700, -32600, -32602
REST bodyerror: invalid_params
Reaches a nodeNo
RetryableNo: fix the request

Cause

Most JSON-RPC errors arrive on HTTP 200, so a 400 is worth noticing: the request was rejected as a request. It comes from checks that run before an upstream is chosen. A body that opens as a batch but is not valid JSON gets -32700. A missing jsonrpc, id or method field gets -32600. On BNB Smart Chain, an eth_getLogs filter that fails admission gets -32602 with the reason in the message, and REST routes answer invalid_params in the plain envelope.

Solution

  1. Read the code and the message; the message names the field or the limit on the request.
  2. Log the exact bytes you sent. String-built JSON, a trailing comma or an unescaped quote in a parameter are the usual causes.
  3. Check the object has jsonrpc: "2.0", an id, a method and a params array or object of the shape the method expects.
  4. Set Content-Type: application/json, and test the same body with curl to rule out your HTTP client.

A quick way to isolate it

Save the failing body to a file and send it with curl. If curl gets the same 400, the body is wrong. If curl succeeds, look at what your client adds or changes: compression, a proxy, or a framework that re-serializes the body.

curl -i https://triport.io/sol \
  -H "x-token: $TRIPORT_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @body.json

Example

{
  "jsonrpc": "2.0",
  "id": null,
  "error": {
    "code": -32600,
    "message": "invalid JSON-RPC request"
  }
}

FAQ

Why do I get HTTP 200 for some JSON-RPC errors and 400 for others?
A request that reaches a node returns the node's error inside a 200 response. A 400 means the gateway refused the request first, so no node saw it.
Is an empty batch a 400?
No. An empty array [] gets a single -32600 error object on HTTP 200, because the request arrived intact.