Invoke all method instance of geth using json rpc call

Posted By : Md Imroz Alam | 10-Apr-2017

We can invoke all method instance of geth using json-rpc call.

we are just going to invoke this eth.coinbase method using normal api call by nodejs.

Following are the request body of an api

var sendData = {
    "jsonrpc": "2.0",
    "method": "eth_coinbase",
    "params": [],
    "id": new Date().getTime()
};
var bodyJson = JSON.stringify(sendData);
var options = {
    url: "http://localhost:8454", // local geth instance 
    method: "POST",
    headers: {
        'Content-type': 'application/json',
    },
    body: bodyJson
};
var request = require('request');
request(options, function(error, response, body) {
    if (error) {
        console.log("Error : ", error);
    } else {
        var body = JSON.parse(body);
        if (body.error) {
            console.log("error: ", body.error);
        } else {
            console.log("result: ", body.result); // body.result will return geth coinbase account address  
        }
    }
})

There is a refrence link about json-rpc of geth instance method https://github.com/ethereum/wiki/wiki/JSON-RPC

We can also request by terminal ( following line of code).

// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_coinbase","params":[],"id":1}'

// Result
{
  "id":1,
  "jsonrpc": "2.0",
  "result": "0x306e52t7a49eeb85d32cf465507dd71d507100c1"
}

There is no of error list and their code for json-rpc , reference link https://github.com/ethereum/wiki/wiki/JSON-RPC-Error-Codes-Improvement-Proposal

I hope this will be helpful

Thanks

About Author

Author Image
Md Imroz Alam

Md. Imroz Alam is a bright Web App Developer, he has good knowledge of Java, J2SE, Jsp, Servlet, jdbc. His hobbies are watching movie, playing carom.

Request for Proposal

Name is required

Comment is required

Sending message..