forked from miguelmota/ethereum-input-data-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
35 lines (25 loc) · 832 Bytes
/
main.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
const InputDataDecoder = require('../index');
const abiInput = document.querySelector('#abiInput');
const dataInput = document.querySelector('#dataInput');
const output = document.querySelector('#output');
function decode() {
output.value = ''
const abi = JSON.parse(abiInput.value.trim());
const decoder = new InputDataDecoder(abi);
// if copied and pasted from etherscan only get data we need
const data = dataInput.value.trim()
.replace(/(?:[\s\S]*MethodID: (.*)[\s\S])?[\s\S]?\[\d\]:(.*)/gi, '$1$2')
dataInput.value = data
const result = decoder.decodeData(data);
console.log(result)
try {
output.value = JSON.stringify(result, null, 2);
} catch(error) {
}
}
document.querySelector('#decode')
.addEventListener('click', function(event) {
event.preventDefault();
decode();
});
decode();