Skip to content

Instantly share code, notes, and snippets.

@MrHell0
Created April 21, 2022 04:16
Show Gist options
  • Save MrHell0/60c3cbf23072e0b85a38bb79ccc1ff38 to your computer and use it in GitHub Desktop.
Save MrHell0/60c3cbf23072e0b85a38bb79ccc1ff38 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
// requires installing node-fetch `npm install node-fetch`
const fetch = require('node-fetch');
const myNodeId = 'NodeID-Hdc3Czu3AzW5rHvSAyLztNevu6bDNoKqo';
async function main() {
const body = `{
"jsonrpc":"2.0",
"id" :1,
"method" :"info.peers",
"params": {
"chain":"2hUULz82ZYMKwjBHZybVRyouk38EmcW7UKP4iocf9rghpvfm84"
}
}`;
const response = await fetch('http://127.0.0.1:9650/ext/info', {
method: 'post',
body: body,
headers: {'Content-Type': 'application/json'}
})
const myNode = (await response.json())['result']['peers'].find(p => p['nodeID'] == myNodeId);
if (myNode) {
console.log(`Success! Found node ${myNodeId}`);
} else {
console.log(`Failed: Node ${myNodeId} not found`);
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment