This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcli.js
106 lines (91 loc) · 2.89 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const program = require('commander')
const config = require('./config')
const web3 = require('./ethconn')
const generalSrv = require('./services/ethnode/general')(web3)
const addressSrv = require('./services/ethnode/address')(web3)
const txSrv = require('./services/ethnode/tx')(web3)
program
.version('0.0.1')
.description('Ethereum Node API console')
program
.command('status')
.description('See the status of the App and the network/connection')
.action(() => {
console.log('Status')
console.log('------')
var status = generalSrv.getStatus()
// connection status
console.log('Connected: ' + status.connected)
if (status.connected) {
// coinbase info
console.log('Coinbase: ' + status.coinbase)
console.log('Coinbase balance: ' + status.coinbase_balance)
}
})
program
.command('balance <account>')
.description('Get the balance of an account')
.action((account) => {
console.log('Account: ' + account)
addressSrv.getBalance(account)
.then(function (result) {
console.log('Account balance: ' + result.balance)
}, function (err) {
console.log('An error occurred: ' + err)
})
})
program
.command('account-send <from> <to> <wei>')
.description('Send ether (wei) from one account to another address')
.action((from, to, wei) => {
// prepare the Tx parameters
var tx = {
from: from,
to: to,
value: wei
}
web3.eth.sendTransaction(tx, (err, txHash) => {
if (err) {
console.log('Error creating tx: ' + err)
} else {
console.log('Tx hash: ' + txHash)
}
})
})
program
.command('send <from> <fromKey> <to> <wei>')
.description('Send (wei) from an address to another')
.option('-gp, --gas_price [price]', 'Gas price for the Tx')
.option('-gl, --gas_limit [limit]', 'Gas price for the Tx')
.action((from, fromKey, to, wei, options) => {
console.log('Gas price: ' + (options.gas_price || 1))
console.log('Gas limit: ' + (options.gas_limit || 90000))
console.log('Value: ' + wei)
console.log('Chain ID: ' + config.eth.chain_id)
txSrv.send(from, fromKey, to, wei)
.then(function (result) {
console.log(result)
}, function (err) {
console.log(err)
})
// var result = await txSrv.send(from, fromKey, to, wei)
// console.log(result);
})
program
.command('transaction <txhash>')
.description('Gets the transaction information')
.action((txhash) => {
var tx = web3.eth.getTransaction(txhash)
console.log('Transaction: ' + txhash)
console.log(tx)
})
program
.command('block <blockid>')
.description('Gets the block information')
.option('-tx, --showtx', 'Include all transactions as objects')
.action((blockid, options) => {
var block = web3.eth.getBlock(blockid, options.showtx)
console.log('Block: ' + blockid)
console.log(block)
})
program.parse(process.argv)