Created
April 21, 2022 04:16
-
-
Save MrHell0/60c3cbf23072e0b85a38bb79ccc1ff38 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 | |
// 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