Search code examples
blockchainethereumsolidityhardhat

Hardhat node, error in browser on localhost


I'm trying to debug & test a smart contract I developed, however doing so on testnets takes a lot of time and I wanted to test properly on local node.

I can create the node and deploy the contract, transfer from account to another in metamask, every thing works fine, except when I go to http://127.0.0.1:8545/ in browser, I get this error:

{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error: Unexpected end of JSON input"}}

I've tried both brave & chrome, I tried creating a different hardhat project, same error.

What can I do? Thanks!


Solution

  • This is an expected output. It's a response to the empty request body:

    # request
    curl 'http://127.0.0.1:8545/' --data-raw ''
    
    # response
    {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error: Unexpected end of JSON input"}}
    

    If you sent a valid JSON-RPC request body (which is generally not possible from the browser address bar, unless you have installed some kind of browser extension), you'd get a valid response:

    # request
    curl 'http://127.0.0.1:8545' --data-raw '{"jsonrpc":"2.0","method":"net_listening","params":[],"id":1}'
    
    # response
    {"jsonrpc":"2.0","id":1,"result":true}