Skip to content

Instantly share code, notes, and snippets.

@frozeman
Last active January 18, 2018 22:36
Show Gist options
  • Save frozeman/c83cc820fabb80175fb166458c3217e0 to your computer and use it in GitHub Desktop.
Save frozeman/c83cc820fabb80175fb166458c3217e0 to your computer and use it in GitHub Desktop.
Test RPC in node.js
/*
- $ geth --shh
- install node.js and npm
- $ mkdir testFolder
- $ npm install oboe
- $ node
- copy the code below
- exceute: send('eth_blockNumber', []);
*/
var oboe = require('oboe')
var net = require('net');
var client = net.createConnection("/Users/youruser/Library/Ethereum/geth.ipc"); // path for Mac, linux is ~/.ethereum/geth.ipc
client.on("connect", function() {
oboe(client)
// called each time a full json object is parsed
.done(function(newHead){
console.log(newHead);
console.log();
});
});
var id = 0;
send = function(method, params){
client.write('{"id": '+ id++ +', "method": "'+ method +'", "params": '+ JSON.stringify(params) +'}');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment