ethereum-console
Advanced tools
Comparing version 0.0.1 to 0.0.2
111
main.js
#!/usr/bin/env node | ||
/* | ||
Run by default in interactive mode. When called in script mode, process.exit() should be called in your script to exit the nodejs app. | ||
Arguments: | ||
- a path which target a JavaScript file to execute (.js extension). | ||
- a path which target an ipc path. | ||
*/ | ||
var Web3 = require('web3'); | ||
@@ -6,20 +14,99 @@ var web3admin = require('./web3Admin.js'); | ||
var net = require('net'); | ||
var fs = require('fs') | ||
var vm = require('vm'); | ||
var ipcpath = require('./getIpcPath.js'); | ||
var ipcPath = ipcpath(); | ||
var jsScript; | ||
var help = false; | ||
if (!processArguments()) | ||
return; | ||
if (help) | ||
{ | ||
logHelp(); | ||
return; | ||
} | ||
process.on('uncaughtException', function(err) { | ||
console.error("Uncaught exception: " + err); | ||
console.error("Uncaught exception: " + err); | ||
}); | ||
console.log("Connecting to node at " + ipcpath()); | ||
web3 = new Web3(new Web3.providers.IpcProvider(ipcpath(), net)); | ||
console.log("Connecting to node at " + ipcPath); | ||
web3 = new Web3(new Web3.providers.IpcProvider(ipcPath, net)); | ||
web3admin.extend(web3); | ||
web3.eth.getBlockNumber(function(err, number) { | ||
if (err) { | ||
console.error("Could not connect to node. Please start an Ethereum node first."); | ||
} else { | ||
console.log("Connection successful."); | ||
console.log("Current block number: " + number); | ||
console.log("Entering interactive mode."); | ||
var replServer = repl.start({}); | ||
} | ||
web3.eth.getBlockNumber(function(err, number) | ||
{ | ||
if (err) | ||
console.error("Could not connect to node. Please start an Ethereum node first."); | ||
else | ||
{ | ||
console.log("Connection successful."); | ||
console.log("Current block number: " + number); | ||
if (jsScript) | ||
executeScript(); | ||
else | ||
{ | ||
console.log("Entering interactive mode."); | ||
repl.start({}); | ||
} | ||
} | ||
}); | ||
function processArguments() | ||
{ | ||
var notRecognized = false; | ||
for (var k = 2; k < process.argv.length; k++) | ||
{ | ||
var arg = process.argv[k]; | ||
if (arg.endsWith('.js')) | ||
jsScript = arg; | ||
else if (arg === "help" || arg === "--help" || arg === "-h") | ||
help = true; | ||
else if (arg.startsWith("ipc:") || arg.endsWith(".ipc")) | ||
ipcPath = arg.startsWith("ipc:") ? arg.substring(4) : arg; | ||
else | ||
{ | ||
notRecognized = true; | ||
console.log("Argument not recognized " + arg); | ||
} | ||
} | ||
if (notRecognized) | ||
{ | ||
logHelp(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
function executeScript() | ||
{ | ||
console.log("Executing " + jsScript + " ..."); | ||
fs.readFile(jsScript, 'utf8', function (err, data) | ||
{ | ||
if (err) | ||
{ | ||
console.log(err); | ||
process.exit(); | ||
} | ||
else | ||
{ | ||
var script = new vm.Script(data); | ||
script.runInThisContext(); | ||
} | ||
}); | ||
} | ||
function logHelp() | ||
{ | ||
var help = "Usage: ethconsole [javascript file] [ipc socket]\n" + | ||
"Connects to an ethereum node via ipc in order to control it remotely\n" + | ||
"through global variable web3 (web3.admin is also present).\n" + | ||
"If no arguments are given, connects to the ipc socket at " + ipcpath() + "\n" + | ||
"and drops into interactive mode.\n" + | ||
"Arguments:\n" + | ||
" <ipc socket path> connect to the given ipc socket (use ipc://<path> if it does not end with .ipc)\n" + | ||
" <javascript file> execute the given javascript file that has to end in .js non-interactively.\n" + | ||
" The script has to call process.exit() in order to terminate the console.\n" | ||
console.log(help); | ||
} |
{ | ||
"name": "ethereum-console", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Commandline console for Ethereum nodes", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
# ethereum-console | ||
Nodejs text console to control ethereum nodes | ||
Commandline console for Ethereum nodes. | ||
`ethconsole` connects to an Ethereum node running in the background (tested with eth and geth) via IPC | ||
and provides an interactive javascript console containing the `web3` object with admin additions. | ||
Note that the admin additions are not yet official and may change any time. | ||
## Installation / Usage | ||
# npm install -g ethereum-console | ||
npm http GET https://registry.npmjs.org/ethereum-console | ||
npm http 304 https://registry.npmjs.org/ethereum-console | ||
npm http GET https://registry.npmjs.org/web3 | ||
... | ||
# ethconsole | ||
Connecting to node at /home/user/.ethereum/geth.ipc | ||
Connection successful. | ||
Current block number: 1083107 | ||
Entering interactive mode. | ||
> web3.admin.getNodeInfo(function(err, info) { console.log(info.name); } ) | ||
eth/v1.2.0-2192c209/Debug-Linux/clang/int |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16021
377
24
4