Created
April 3, 2017 15:35
-
-
Save bas-vk/6642a3f110a270917619171ab02203a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var net = require("net"); | |
var client = net.connect({ | |
path: "/home/bas/.ethereum/geth.ipc" //"/tmp/dd/geth.ipc" | |
}, function() { | |
createNewBlocksSubscription(); | |
// createSyncingSubscription(); | |
createPendingTxSubscription(); | |
// createLogsSubscription(); | |
}); | |
var i = 0; | |
client.on("data", function(data) { | |
console.log(data.toString()); | |
i++; | |
if (false && i == 5) { | |
var subId = JSON.parse(data.toString()).params.subscription; | |
var req = { | |
id: 2, | |
method: "eth_unsubscribe", | |
jsonrpc: "2.0", | |
params: [subId] | |
} | |
console.log('{"unsubscribe": "' + subId + '"}'); | |
client.write(JSON.stringify(req)); | |
} | |
}); | |
function createPendingTxSubscription() { | |
var request = { | |
jsonrpc: "2.0", | |
id: 1, | |
method: "eth_subscribe", | |
params: ["newPendingTransactions"] | |
}; | |
client.write(JSON.stringify(request)); | |
} | |
function createLogsSubscription() { | |
var options = { | |
address: "0x9a295ef207dee10098c519166d7a61be35157c2b" | |
, topics: ["0x7924ea7ce0cbde761ca0f724e5f9819ca057962490ce5712d7929babe905cc6c", "0x0000000000000000000000000000000000000000000000000000000000000002"] | |
} | |
var request = { | |
jsonrpc: "2.0", | |
id: 1, | |
method: "eth_subscribe", | |
params: ["logs", options] | |
}; | |
client.write(JSON.stringify(request)); | |
} | |
function createNewBlocksSubscription() { | |
var request = { | |
jsonrpc: "2.0", | |
id: 1, | |
method: "eth_subscribe", | |
params: ["newHeads"] | |
}; | |
client.write(JSON.stringify(request)); | |
} | |
function createSyncingSubscription() { | |
var request = { | |
jsonrpc: "2.0", | |
id: 1, | |
method: "eth_subscribe", | |
params: ["syncing"] | |
}; | |
client.write(JSON.stringify(request)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment