NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.04k stars 1.36k forks source link

Null params are not supported in JSON RPC calls #5383

Closed blackyblack closed 1 month ago

blackyblack commented 1 month ago

Version of Hardhat

2.19.1

What happened?

"Invalid request" response is received when params field is set to null. Other public RPC providers process such params successfully.

Minimal reproduction steps

Send POST request to hardhat node: {"jsonrpc":"2.0","method":"eth_chainId","params": null,"id":1}

Expected result:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": "0x89"
}

Hardhat result:

{
    "jsonrpc": "2.0",
    "id": null,
    "error": {
        "code": -32600,
        "message": "Invalid request",
        "data": {
            "message": "Invalid request"
        }
    }
}

Search terms

params, null

fvictorio commented 1 month ago

null is not a valid params value (see JSON-RPC 2.0 Spec).

My guess is that most providers accept it because most providers use geth, and geth's JSON unmarshalling doesn't tell apart missing values from values set to null.

I think it makes sense for us to follow the spec here.

blackyblack commented 1 month ago

There is no direct prohibition for null value according to spec. And null is a valid JSON literal. Or you can show me where spec fordbids null value to prove me wrong.

fvictorio commented 1 month ago

JSON can represent four primitive types (Strings, Numbers, Booleans, and Null) and two structured types (Objects and Arrays)

params A Structured value that holds the parameter values to be used during the invocation of the method. This member MAY be omitted.

blackyblack commented 1 month ago

You are right. Thanks.