├── LICENSE ├── README.md ├── getIpcPath.js ├── main.js ├── package.json └── web3Extensions.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ethereum-console 2 | 3 | Commandline console for Ethereum nodes. 4 | 5 | `ethconsole` connects to a running Ethereum node via IPC/WS/HTTP 6 | and provides an interactive javascript console containing the `web3` (1.x) object with admin extensions. 7 | 8 | Note that the admin/debug additions are not yet official and may change over time. 9 | 10 | Run `$ ethconsole --help` for help. 11 | 12 | ## Installation / Usage 13 | 14 | $ npm install -g ethereum-console 15 | ... 16 | 17 | $ ethconsole 18 | ETHEREUM CONSOLE 19 | Connecting to node at /Users/xyz/Library/Ethereum/geth.ipc 20 | ... Connection successful! 21 | 22 | Use the "web3" object to interact. 23 | You can find the documentation here: http://web3js.readthedocs.io/en/1.0/ 24 | 25 | ΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞ 26 | Network: MAIN 27 | Current block: 5285047 [0x8a22bd], March 19th 2018, 20:46:37 28 | ΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞ 29 | 30 | > web3.admin.nodeInfo() 31 | ... 32 | 33 | ### CPP Ethereum Test Interface 34 | 35 | `ethconsole` provides access to the cpp-ethereum test interface, which can 36 | be used to test smart contracts that depend on timing and blocks being 37 | mined. 38 | 39 | # Install the development version of cpp-ethereum on Ubuntu: 40 | # sudo add-apt-repository -y ppa:ethereum/ethereum-qt 41 | # sudo add-apt-repository -y ppa:ethereum/ethereum 42 | # sudo add-apt-repository -y ppa:ethereum/ethereum-dev 43 | # sudo apt-get -y update 44 | # sudo apt-get -y install eth 45 | # 46 | # Start eth in test-mode using data directory /tmp/test 47 | $ eth --test -d /tmp/test & 48 | # Wait for it to start up... 49 | # Run the example: 50 | $ ethconsole /tmp/test/geth.ipc cppTestExample.js 51 | 52 | These testing interfaces exist in cpp-ethereum: 53 | 54 | web3.test.setChainParams({}, cb(err, bool)) 55 | set chain parameters using the json chain description 56 | you can use the function chainParams() from the cppTestExample.js to create such a description 57 | web3.test.mineBlocks(x, cb(err, bool)) 58 | start mining and stop again after exactly x blocks 59 | web3.test.modifyTimestamp(x, cb(err, bool)) 60 | set the timestamp of the current block to x 61 | web3.test.rewindToBlock(x, cb(err, bool)) 62 | rewind the blockchain to block number x 63 | web3.test.addBlock(x, cb(err, bool) 64 | inject an RLP-encoded block 65 | -------------------------------------------------------------------------------- /getIpcPath.js: -------------------------------------------------------------------------------- 1 | /** 2 | Gets the right IPC path 3 | 4 | @module getIpcPath 5 | */ 6 | 7 | var fs = require("fs"); 8 | 9 | module.exports = function() { 10 | var p = require('path'); 11 | var path = process.env.HOME; 12 | 13 | var macDefaultDir = "/Library/Ethereum/geth.ipc"; 14 | var linuxDefaultDir = "/.ethereum/geth.ipc"; 15 | 16 | if(process.platform === 'darwin') { 17 | if(fs.existsSync(path + macDefaultDir)) 18 | path += macDefaultDir; 19 | else 20 | if(fs.existsSync(path + linuxDefaultDir)) 21 | path += linuxDefaultDir; 22 | else 23 | path += macDefaultDir; 24 | } 25 | 26 | if(process.platform === 'freebsd' || 27 | process.platform === 'linux' || 28 | process.platform === 'sunos') 29 | path += linuxDefaultDir; 30 | 31 | if(process.platform === 'win32') 32 | path = '\\\\.\\pipe\\geth.ipc'; 33 | 34 | return path; 35 | }; 36 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Run by default in interactive mode. When called in script mode, process.exit() should be called in your script to exit the nodejs app. 5 | Arguments: 6 | - a path which target a JavaScript file to execute (.js extension). 7 | - a path which target an ipc path. 8 | */ 9 | 10 | 11 | var net = require('net'); 12 | var repl = require('repl'); 13 | var promisify = require("repl-promised").promisify; 14 | var moment = require('moment'); 15 | var fs = require('fs') 16 | var vm = require('vm'); 17 | var ipcpath = require('./getIpcPath.js'); 18 | require('es6-shim'); 19 | 20 | var Web3 = require('web3'); 21 | var web3Extensions = require('./web3Extensions.js'); 22 | 23 | // Arguments 24 | var ipcPath = ipcpath(); 25 | var wsPath, httpPath, jsScript; 26 | processArguments(); 27 | 28 | 29 | // select provider 30 | var provider, providerPath; 31 | if (wsPath) { 32 | providerPath = wsPath; 33 | provider = new Web3.providers.WebsocketProvider(providerPath); 34 | } else if (httpPath) { 35 | providerPath = httpPath; 36 | provider = new Web3.providers.HttpProvider(providerPath); 37 | } else if (ipcPath) { 38 | providerPath = ipcPath; 39 | provider = new Web3.providers.IpcProvider(providerPath, net); 40 | } 41 | 42 | process.on('uncaughtException', function(err) { 43 | console.error("Uncaught exception: " + err); 44 | }); 45 | 46 | console.log("ETHEREUM CONSOLE"); 47 | console.log("Connecting to node at " + providerPath); 48 | 49 | if (wsPath || httpPath) { 50 | console.log("\nWARNING! You're connecting through an unsecure connection!\n"+ 51 | "Using this console API allows you to send passwords over this connection,\n"+ 52 | "please make sure to secure your connection to prevent loss of funds!\n\n"+ 53 | "Additionally you need to activate in your node extra debug APIs manually.\n"); 54 | } 55 | 56 | var web3 = new Web3(provider); 57 | web3Extensions.extend(web3, global); 58 | global.web3 = web3; 59 | 60 | // attach main modules globally 61 | ['eth','bzz','shh','utils'].forEach(function(type) { 62 | global[type] = web3[type]; 63 | }); 64 | 65 | 66 | 67 | web3.eth.net.getNetworkType() 68 | .then(function(type){ 69 | console.log("... Connection successful!\n"); 70 | 71 | console.log("Use the \"web3\" object to interact.\nYou can find the documentation here: http://web3js.readthedocs.io/en/1.0/\n"); 72 | 73 | 74 | console.log("ΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞ"); 75 | console.log("Network: " + type.toUpperCase()); 76 | return web3.eth.getBlock('latest'); 77 | }) 78 | .then(function(block) { 79 | console.log("Current block: "+ block.number + " [" + block.hash.substr(0,8) +"], "+ moment.unix(block.timestamp).format('MMMM Do YYYY, HH:mm:ss') +""); 80 | }) 81 | .then(function(){ 82 | 83 | console.log("ΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞ\n"); 84 | 85 | if (jsScript) 86 | executeScript(jsScript); 87 | else { 88 | 89 | // log latest block 90 | // web3.eth.subscribe('newBlockHeaders', function(error, block){ 91 | // console.log("Block "+ block.hash.substr(0,8) +" arrived: " + block.number + " ("+ moment.unix(block.timestamp).format('MMMM Do YYYY, HH:mm:ss') +")"); 92 | // }); 93 | 94 | promisify(repl.start({ 95 | prompt: "> ", 96 | input: process.stdin, 97 | output: process.stdout 98 | })); 99 | } 100 | }) 101 | .catch(function(e){ 102 | console.error("\nERROR"); 103 | console.error(String(e)); 104 | console.log('Exit due to error.'); 105 | process.exit(); 106 | }); 107 | 108 | 109 | function processArguments() 110 | { 111 | for (var k = 2; k < process.argv.length; k++) { 112 | var arg = process.argv[k]; 113 | 114 | if (arg === "help" || arg === "--help" || arg === "-h") 115 | help(); 116 | else if (arg.startsWith("ipc:") || arg.endsWith(".ipc")) 117 | ipcPath = arg.startsWith("ipc:") ? arg.substring(4) : arg; 118 | else if (arg.startsWith("ws://")) 119 | wsPath = arg; 120 | else if (arg.startsWith("http://") || arg.startsWith("https://")) 121 | httpPath = arg; 122 | else if (arg.endsWith(".js")) 123 | jsScript = arg; 124 | else { 125 | console.log("Argument not recognized: " + arg +"\n"); 126 | help(); 127 | process.exit(); 128 | } 129 | } 130 | } 131 | 132 | function executeScript(jsScript) { 133 | console.log("Executing " + jsScript + " ...\n"); 134 | 135 | fs.readFile(jsScript, 'utf8', function (err, data) { 136 | if (err) { 137 | console.log(err); 138 | process.exit(); 139 | } else { 140 | var script = new vm.Script(data); 141 | script.runInThisContext(); 142 | } 143 | }); 144 | } 145 | 146 | function help(){ 147 | console.log( 148 | "web3.js based console that connects to an Ethereum node via IPC/WS/HTTP.\n" + 149 | "Defaults to IPC path: " + ipcpath() + "\n\n" + 150 | "Usage: ethconsole \n\n" + 151 | "Arguments:\n" + 152 | " connect to a Websocket (ws://...), HTTP endpoint (http://..), or IPC socket (use ipc:// if path does not end with \".ipc\").\n"+ 153 | " Defaults to the default IPC endpoint for geth.\n"+ 154 | " execute the given JavaScript file non-interactively.\n" + 155 | " The script has to call process.exit() in order to terminate the console.\n"); 156 | } 157 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ethereum-console", 3 | "version": "1.0.4", 4 | "description": "Commandline console for Ethereum nodes", 5 | "main": "main.js", 6 | "bin": { 7 | "ethconsole": "./main.js" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git://github.com/ethereum/ethereum-console.git" 15 | }, 16 | "keywords": [ 17 | "console", 18 | "ethereum", 19 | "web3" 20 | ], 21 | "author": "Ethereum Foundation", 22 | "authors": [ 23 | { 24 | "name": "Christian Reitwiessner", 25 | "email": "c@ethereum.org", 26 | "url": "https://github.com/chriseth" 27 | }, 28 | { 29 | "name": "Fabian Vogelsteller", 30 | "email": "fabian@ethereum.org", 31 | "homepage": "http://frozeman.de" 32 | } 33 | ], 34 | "license": "MIT", 35 | "bugs": { 36 | "url": "https://github.com/ethereum/ethereum-console/issues" 37 | }, 38 | "dependencies": { 39 | "es6-shim": "^0.35.1", 40 | "moment": "^2.21.0", 41 | "repl-promised": "^0.1.0", 42 | "web3": "1.0.0-beta.31" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /web3Extensions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The go-ethereum Authors 2 | // This file is part of the go-ethereum library. 3 | // 4 | // The go-ethereum library is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Lesser General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // The go-ethereum library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Lesser General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public License 15 | // along with the go-ethereum library. If not, see . 16 | 17 | 18 | // var Modules = map[string]string{ 19 | // "admin": Admin_JS, 20 | // "chequebook": Chequebook_JS, 21 | // "clique": Clique_JS, 22 | // "debug": Debug_JS, 23 | // "eth": Eth_JS, 24 | // "miner": Miner_JS, 25 | // "net": Net_JS, 26 | // "personal": Personal_JS, 27 | // "rpc": RPC_JS, 28 | // "shh": Shh_JS, 29 | // "swarmfs": SWARMFS_JS, 30 | // "txpool": TxPool_JS, 31 | // } 32 | 33 | 34 | module.exports = { 35 | extend: function(web3, global) { 36 | 37 | web3.extend({ 38 | property: 'chequebook', 39 | methods: [ 40 | { 41 | name: 'deposit', 42 | call: 'chequebook_deposit', 43 | params: 1, 44 | inputFormatter: [null] 45 | }, 46 | { 47 | name: 'balance', 48 | call: 'chequebook_balance', 49 | outputFormatter: web3.utils.toDecimal 50 | }, 51 | { 52 | name: 'cash', 53 | call: 'chequebook_cash', 54 | params: 1, 55 | inputFormatter: [null] 56 | }, 57 | { 58 | name: 'issue', 59 | call: 'chequebook_issue', 60 | params: 2, 61 | inputFormatter: [null, null] 62 | }, 63 | ] 64 | }); 65 | 66 | web3.extend({ 67 | property: 'clique', 68 | methods: [ 69 | { 70 | name: 'getSnapshot', 71 | call: 'clique_getSnapshot', 72 | params: 1, 73 | inputFormatter: [null] 74 | }, 75 | { 76 | name: 'getSnapshotAtHash', 77 | call: 'clique_getSnapshotAtHash', 78 | params: 1 79 | }, 80 | { 81 | name: 'getSigners', 82 | call: 'clique_getSigners', 83 | params: 1, 84 | inputFormatter: [null] 85 | }, 86 | { 87 | name: 'getSignersAtHash', 88 | call: 'clique_getSignersAtHash', 89 | params: 1 90 | }, 91 | { 92 | name: 'propose', 93 | call: 'clique_propose', 94 | params: 2 95 | }, 96 | { 97 | name: 'discard', 98 | call: 'clique_discard', 99 | params: 1 100 | }, 101 | { 102 | name: 'proposals', 103 | call: 'clique_proposals' 104 | }, 105 | ] 106 | }); 107 | 108 | 109 | web3.extend({ 110 | property: 'admin', 111 | methods: [ 112 | { 113 | name: 'addPeer', 114 | call: 'admin_addPeer', 115 | params: 1 116 | }, 117 | { 118 | name: 'removePeer', 119 | call: 'admin_removePeer', 120 | params: 1 121 | }, 122 | { 123 | name: 'exportChain', 124 | call: 'admin_exportChain', 125 | params: 1, 126 | inputFormatter: [null] 127 | }, 128 | { 129 | name: 'importChain', 130 | call: 'admin_importChain', 131 | params: 1 132 | }, 133 | { 134 | name: 'sleepBlocks', 135 | call: 'admin_sleepBlocks', 136 | params: 2 137 | }, 138 | { 139 | name: 'startRPC', 140 | call: 'admin_startRPC', 141 | params: 4, 142 | inputFormatter: [null, null, null, null] 143 | }, 144 | { 145 | name: 'stopRPC', 146 | call: 'admin_stopRPC' 147 | }, 148 | { 149 | name: 'startWS', 150 | call: 'admin_startWS', 151 | params: 4, 152 | inputFormatter: [null, null, null, null] 153 | }, 154 | { 155 | name: 'stopWS', 156 | call: 'admin_stopWS' 157 | }, 158 | { 159 | name: 'nodeInfo', 160 | call: 'admin_nodeInfo' 161 | }, 162 | { 163 | name: 'peers', 164 | call: 'admin_peers' 165 | }, 166 | { 167 | name: 'datadir', 168 | call: 'admin_datadir' 169 | }, 170 | ] 171 | }); 172 | 173 | 174 | web3.extend({ 175 | property: 'debug', 176 | methods: [ 177 | { 178 | name: 'printBlock', 179 | call: 'debug_printBlock', 180 | params: 1 181 | }, 182 | { 183 | name: 'getBlockRlp', 184 | call: 'debug_getBlockRlp', 185 | params: 1 186 | }, 187 | { 188 | name: 'setHead', 189 | call: 'debug_setHead', 190 | params: 1 191 | }, 192 | { 193 | name: 'seedHash', 194 | call: 'debug_seedHash', 195 | params: 1 196 | }, 197 | { 198 | name: 'dumpBlock', 199 | call: 'debug_dumpBlock', 200 | params: 1 201 | }, 202 | { 203 | name: 'chaindbProperty', 204 | call: 'debug_chaindbProperty', 205 | params: 1, 206 | outputFormatter: console.log 207 | }, 208 | { 209 | name: 'chaindbCompact', 210 | call: 'debug_chaindbCompact', 211 | }, 212 | { 213 | name: 'metrics', 214 | call: 'debug_metrics', 215 | params: 1 216 | }, 217 | { 218 | name: 'verbosity', 219 | call: 'debug_verbosity', 220 | params: 1 221 | }, 222 | { 223 | name: 'vmodule', 224 | call: 'debug_vmodule', 225 | params: 1 226 | }, 227 | { 228 | name: 'backtraceAt', 229 | call: 'debug_backtraceAt', 230 | params: 1, 231 | }, 232 | { 233 | name: 'stacks', 234 | call: 'debug_stacks', 235 | params: 0, 236 | outputFormatter: console.log 237 | }, 238 | { 239 | name: 'freeOSMemory', 240 | call: 'debug_freeOSMemory', 241 | params: 0, 242 | }, 243 | { 244 | name: 'setGCPercent', 245 | call: 'debug_setGCPercent', 246 | params: 1, 247 | }, 248 | { 249 | name: 'memStats', 250 | call: 'debug_memStats', 251 | params: 0, 252 | }, 253 | { 254 | name: 'gcStats', 255 | call: 'debug_gcStats', 256 | params: 0, 257 | }, 258 | { 259 | name: 'cpuProfile', 260 | call: 'debug_cpuProfile', 261 | params: 2 262 | }, 263 | { 264 | name: 'startCPUProfile', 265 | call: 'debug_startCPUProfile', 266 | params: 1 267 | }, 268 | { 269 | name: 'stopCPUProfile', 270 | call: 'debug_stopCPUProfile', 271 | params: 0 272 | }, 273 | { 274 | name: 'goTrace', 275 | call: 'debug_goTrace', 276 | params: 2 277 | }, 278 | { 279 | name: 'startGoTrace', 280 | call: 'debug_startGoTrace', 281 | params: 1 282 | }, 283 | { 284 | name: 'stopGoTrace', 285 | call: 'debug_stopGoTrace', 286 | params: 0 287 | }, 288 | { 289 | name: 'blockProfile', 290 | call: 'debug_blockProfile', 291 | params: 2 292 | }, 293 | { 294 | name: 'setBlockProfileRate', 295 | call: 'debug_setBlockProfileRate', 296 | params: 1 297 | }, 298 | { 299 | name: 'writeBlockProfile', 300 | call: 'debug_writeBlockProfile', 301 | params: 1 302 | }, 303 | { 304 | name: 'mutexProfile', 305 | call: 'debug_mutexProfile', 306 | params: 2 307 | }, 308 | { 309 | name: 'setMutexProfileRate', 310 | call: 'debug_setMutexProfileRate', 311 | params: 1 312 | }, 313 | { 314 | name: 'writeMutexProfile', 315 | call: 'debug_writeMutexProfile', 316 | params: 1 317 | }, 318 | { 319 | name: 'writeMemProfile', 320 | call: 'debug_writeMemProfile', 321 | params: 1 322 | }, 323 | { 324 | name: 'traceBlock', 325 | call: 'debug_traceBlock', 326 | params: 2, 327 | inputFormatter: [null, null] 328 | }, 329 | { 330 | name: 'traceBlockFromFile', 331 | call: 'debug_traceBlockFromFile', 332 | params: 2, 333 | inputFormatter: [null, null] 334 | }, 335 | { 336 | name: 'traceBlockByNumber', 337 | call: 'debug_traceBlockByNumber', 338 | params: 2, 339 | inputFormatter: [null, null] 340 | }, 341 | { 342 | name: 'traceBlockByHash', 343 | call: 'debug_traceBlockByHash', 344 | params: 2, 345 | inputFormatter: [null, null] 346 | }, 347 | { 348 | name: 'traceTransaction', 349 | call: 'debug_traceTransaction', 350 | params: 2, 351 | inputFormatter: [null, null] 352 | }, 353 | { 354 | name: 'preimage', 355 | call: 'debug_preimage', 356 | params: 1, 357 | inputFormatter: [null] 358 | }, 359 | { 360 | name: 'getBadBlocks', 361 | call: 'debug_getBadBlocks', 362 | params: 0, 363 | }, 364 | { 365 | name: 'storageRangeAt', 366 | call: 'debug_storageRangeAt', 367 | params: 5, 368 | }, 369 | { 370 | name: 'getModifiedAccountsByNumber', 371 | call: 'debug_getModifiedAccountsByNumber', 372 | params: 2, 373 | inputFormatter: [null, null], 374 | }, 375 | { 376 | name: 'getModifiedAccountsByHash', 377 | call: 'debug_getModifiedAccountsByHash', 378 | params: 2, 379 | inputFormatter:[null, null], 380 | }, 381 | ] 382 | }); 383 | 384 | 385 | web3.extend({ 386 | property: 'eth', 387 | methods: [ 388 | 389 | { 390 | name: 'resend', 391 | call: 'eth_resend', 392 | params: 3, 393 | inputFormatter: [web3.extend.formatters.inputTransactionFormatter, web3.utils.fromDecimal, web3.utils.fromDecimal] 394 | }, 395 | { 396 | name: 'submitTransaction', 397 | call: 'eth_submitTransaction', 398 | params: 1, 399 | inputFormatter: [web3.extend.formatters.inputTransactionFormatter] 400 | }, 401 | { 402 | name: 'getRawTransaction', 403 | call: 'eth_getRawTransactionByHash', 404 | params: 1 405 | }, 406 | { 407 | name: 'getRawTransactionFromBlock', 408 | call: function(args) { 409 | return (web3.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 410 | }, 411 | params: 2, 412 | inputFormatter: [web3.extend.formatters.inputBlockNumberFormatter, web3.utils.toHex] 413 | }, 414 | { 415 | name: 'pendingTransactions', 416 | call: 'eth_pendingTransactions', 417 | outputFormatter: function(txs) { 418 | var formatted = []; 419 | for (var i = 0; i < txs.length; i++) { 420 | formatted.push(web3.extend.formatters.outputTransactionFormatter(txs[i])); 421 | formatted[i].blockHash = null; 422 | } 423 | return formatted; 424 | } 425 | }, 426 | ] 427 | }); 428 | 429 | 430 | web3.extend({ 431 | property: 'miner', 432 | methods: [ 433 | { 434 | name: 'start', 435 | call: 'miner_start', 436 | params: 1, 437 | inputFormatter: [null] 438 | }, 439 | { 440 | name: 'stop', 441 | call: 'miner_stop' 442 | }, 443 | { 444 | name: 'setEtherbase', 445 | call: 'miner_setEtherbase', 446 | params: 1, 447 | inputFormatter: [web3.extend.formatters.inputAddressFormatter] 448 | }, 449 | { 450 | name: 'setExtra', 451 | call: 'miner_setExtra', 452 | params: 1 453 | }, 454 | { 455 | name: 'setGasPrice', 456 | call: 'miner_setGasPrice', 457 | params: 1, 458 | inputFormatter: [web3.utils.fromDecimal] 459 | }, 460 | { 461 | name: 'getHashrate', 462 | call: 'miner_getHashrate' 463 | }, 464 | ], 465 | properties: [] 466 | }); 467 | 468 | 469 | web3.eth.extend({ 470 | property: 'personal', 471 | methods: [ 472 | { 473 | name: 'importRawKey', 474 | call: 'personal_importRawKey', 475 | params: 2 476 | }, 477 | { 478 | name: 'openWallet', 479 | call: 'personal_openWallet', 480 | params: 2 481 | }, 482 | { 483 | name: 'deriveAccount', 484 | call: 'personal_deriveAccount', 485 | params: 3 486 | }, 487 | // Remove after web3.js release 488 | { 489 | name: 'signTransaction', 490 | call: 'personal_signTransaction', 491 | params: 2, 492 | inputFormatter: [web3.extend.formatters.inputTransactionFormatter, null] 493 | }, 494 | { 495 | name: 'listWallets', 496 | call: 'personal_listWallets' 497 | }, 498 | ] 499 | }) 500 | 501 | 502 | web3.extend({ 503 | property: 'rpc', 504 | methods: [ 505 | { 506 | name: 'modules', 507 | call: 'rpc_modules' 508 | }, 509 | ] 510 | }); 511 | 512 | 513 | 514 | web3.extend({ 515 | property: 'swarmfs', 516 | methods: 517 | [ 518 | { 519 | name: 'mount', 520 | call: 'swarmfs_mount', 521 | params: 2 522 | }, 523 | { 524 | name: 'unmount', 525 | call: 'swarmfs_unmount', 526 | params: 1 527 | }, 528 | { 529 | name: 'listmounts', 530 | call: 'swarmfs_listmounts', 531 | params: 0 532 | }, 533 | ] 534 | }); 535 | 536 | 537 | web3.extend({ 538 | property: 'txpool', 539 | methods: [ 540 | { 541 | name: 'content', 542 | call: 'txpool_content' 543 | }, 544 | { 545 | name: 'inspect', 546 | call: 'txpool_inspect' 547 | }, 548 | { 549 | name: 'status', 550 | call: 'txpool_status', 551 | outputFormatter: function(status) { 552 | status.pending = web3.utils.toDecimal(status.pending); 553 | status.queued = web3.utils.toDecimal(status.queued); 554 | return status; 555 | } 556 | }, 557 | ] 558 | }); 559 | 560 | 561 | ['txpool','swarmfs','rpc','miner','debug','admin','chequebook'].forEach(function(type) { 562 | global[type] = web3[type]; 563 | }); 564 | global.personal = web3.eth.personal; 565 | } 566 | }; --------------------------------------------------------------------------------