How to code a javascript JSON RPC from scratch, problem with the response

Viewed 264

I'm trying to code a json rpc from scratch. I tried using a fetch, but what the server returns is not the information I want. I believe I need to stay connected waiting for a return from the server. My purpose is to make a request to ganache and get a response. From the ganache log I see that he received the request, but I don't know how to get his return. My initial code was as follows.

const nodeFetch = require('node-fetch')

async function run() {

const retorno = await nodeFetch('HTTP://127.0.0.1:7545', {
method: 'POST',
body: JSON.stringify({
    "jsonrpc": "2.0",
    "method": "eth_accounts",
    "params": [],
    "id": 1
}),
headers: {
    'Content-Type':'application/json'
}
})

console.log(retorno)}
 run();

The answer I get is

enter image description here

Thx

0 Answers
Related