Skip to content

Instantly share code, notes, and snippets.

@tinybike
Created July 13, 2016 09:12
Show Gist options
  • Select an option

  • Save tinybike/42451d0c8501f493e07bfa1efe6c9f1c to your computer and use it in GitHub Desktop.

Select an option

Save tinybike/42451d0c8501f493e07bfa1efe6c9f1c to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var W3CWebSocket = require("websocket").w3cwebsocket;
var websocket = new W3CWebSocket("ws://127.0.0.1:8546");
websocket.onerror = function () {
console.log("websocket error :(");
};
websocket.onclose = function () {
console.log("websocket closed");
};
websocket.onmessage = function (msg) {
console.log("websocket message:", msg.data);
};
websocket.onopen = function () {
console.log("websocket open");
websocket.send(JSON.stringify({"id":1,"jsonrpc":"2.0","method":"eth_gasPrice","params":[]}));
websocket.send(JSON.stringify({"id":2,"jsonrpc":"2.0","method":"eth_coinbase","params":[]}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment