-
Notifications
You must be signed in to change notification settings - Fork 10
/
reveal.js
executable file
·94 lines (80 loc) · 2.19 KB
/
reveal.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
#!/usr/bin/env node
'use strict';
const { formatEther } = require('ethers').utils;
const program = require('commander');
const numbro = require('numbro');
const util = require('util');
const { gray, red, yellow, green, cyan } = require('chalk');
const lookup = require('./lib/lookup');
require('dotenv-safe').config();
// perform as CLI tool if args given
if (require.main === module) {
(async () => {
require('pretty-error').start();
program
.option('-h, --hash <value>', 'Transaction hash (include 0x prefix)')
.option('-n, --network [value]', 'Network to use', 'mainnet')
.option('-a, --`abiContract` [value]', 'Alternative contract that would have the ABI')
.parse(process.argv);
const { hash, network } = program;
console.log(gray('txn:', `https://etherscan.io/tx/${hash}`));
const {
to,
from,
blockNumber,
timestamp,
contract,
method,
decodedLogs,
gasUsed,
status,
errorMessage,
revertReason,
value,
} = await lookup({
hash,
network,
etherscanKey: process.env.ETHERSCAN_API_KEY,
providerURI: process.env.PROVIDER_URI,
infuraProjectID: process.env.INFURA_PROJECT_ID,
});
console.log(gray('from:', from));
console.log(gray('to:', to));
console.log(gray('block:', blockNumber));
console.log(gray('date:', new Date(timestamp * 1000)));
if (contract) console.log(gray('contract:', contract));
if (method)
console.log(
gray(
'method:',
typeof method === 'string'
? method
: util.inspect(method, { showHidden: true, depth: null })
)
);
if (decodedLogs && decodedLogs.length)
console.log(
gray(
'logs:',
util.inspect(decodedLogs, {
showHidden: true,
depth: null,
})
)
);
if (Number(formatEther(value)) > 0) console.log(gray('value:', formatEther(value), 'ETH'));
console.log(
gray(
`Gas used: ${numbro(gasUsed).format({ average: true })} (${numbro(gasUsed).format('0,0')})`
)
);
console.log(gray('Status:'), status > 0 ? green('success') : red('failure'));
if (errorMessage) {
console.log('ES error:', cyan(errorMessage));
}
if (revertReason) {
console.log('Revert reason:', yellow(revertReason));
}
})();
}
module.exports = lookup;