forked from flightwallet/decode-eth-tx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (114 loc) · 4.47 KB
/
index.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<html>
<head>
<script src="ethereumjs-tx-1.3.3.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js" integrity="sha256-nWBTbvxhJgjslRyuAKJHK+XcZPlCnmIAAMixz6EefVk=" crossorigin="anonymous"></script>
<!-- <script src="https://cdn.rawgit.com/ethereumjs/browser-builds/2fb69a714afe092b06645286f14b94f41e5c062c/dist/ethereumjs-tx.js"></script> -->
<!-- <script src="https://cdn.rawgit.com/ethereumjs/browser-builds/master/dist/ethereumjs-tx.js"></script> -->
<title>Decode and Publish Ethereum Raw Transaction</title>
</head>
<body>
<script type="text/javascript">
function decodeMyTx() {
var serializedTx = document.getElementById("inputarea").value.trim();
var outputtext = ''
try {
const rawTx = decodeTx(serializedTx)
outputtext = JSON.stringify(rawTx, null, " ");
} catch (err) {
outputtext = `Decode Error: ${err.toString()}`
}
document.getElementById("outputarea").value = outputtext
}
async function publishMyTx() {
var serializedTx = document.getElementById("inputarea").value.trim();
// eb01843b9aca008252089417da6a8b86578cec4525945a355e8384025fa5af880de0b6b3a7640000001c8080
var outputtext = ''
try {
const result = await publishTx(serializedTx)
.on('transactionHash', hash => console.log('tx hash', hash))
console.log('result', result)
outputtext = result.toString()
} catch (err) {
outputtext = `Publish Error: ${err.toString()}`
}
document.getElementById("outputarea").value = outputtext
}
function publishTx(hex) {
return web3.eth.sendSignedTransaction(hex)
}
function decodeTx(hex) {
var tx = new ethereumjs.Tx(hex);
console.log('tx', tx)
var rawTx = {
nonce: parseInt(tx.nonce.toString('hex') || '0',16),
gasPrice: parseInt(tx.gasPrice.toString('hex'),16),
gasLimit: parseInt(tx.gasLimit.toString('hex'),16),
to: '0x'+tx.to.toString('hex'),
value: parseInt(tx.value.toString('hex') || '0', 16),
data: tx.data.toString('hex'),
};
if (tx.r.length) {
rawTx = {
...rawTx,
from: '0x'+tx.from.toString('hex'),
r: tx.r.toString('hex'),
v: tx.v.toString('hex'),
s: tx.s.toString('hex'),
}
}
return rawTx
}
window.onload = () => {
const NETWORK = 'TESTNET'
const WEB3_PROVIDERS = {
MAINNET: new Web3.providers.HttpProvider(`https://mainnet.infura.io/JCnK5ifEPH9qcQkX0Ahl`),
TESTNET: new Web3.providers.HttpProvider(`https://rinkeby.infura.io/JCnK5ifEPH9qcQkX0Ahl`),
LOCALNET: new Web3.providers.HttpProvider(`http://localhost:7545`),
}
web3 = new Web3(WEB3_PROVIDERS[NETWORK])
}
</script>
<h1>Decode Ethereum serialized transaction</h1>
<textarea name="inputarea" id="inputarea" cols="100" rows="10">
0xf86d820144843b9aca0082520894b78777860637d56543da23312c7865024833f7d188016345785d8a0000802ba0e2539a5d9f056d7095bd19d6b77b850910eeafb71534ebd45159915fab202e91a007484420f3968697974413fc55d1142dc76285d30b1b9231ccb71ed1e720faae
</textarea>
<br />
<input type="submit" value="Decode" onclick="decodeMyTx()"/>
<input type="submit" value="Publish" onclick="publishMyTx()"/>
<br />
<textarea name="outputarea" id="outputarea" cols="100" rows="20">
</textarea>
<br />
<a href="https://github.com/flightwallet/decode-eth-tx">Source code</a>
·
<a href="https://flightwallet.org">flightwallet.org</a>
·
original idea and code by <a href="https://reddit.com/user/dontmindme42">u/dontmindme42</a>
<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
try {
w.yaCounter50897126 = new Ya.Metrika2({
id:50897126,
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
} catch(e) { }
});
var n = d.getElementsByTagName("script")[0],
s = d.createElement("script"),
f = function () { n.parentNode.insertBefore(s, n); };
s.type = "text/javascript";
s.async = true;
s.src = "https://mc.yandex.ru/metrika/tag.js";
if (w.opera == "[object Opera]") {
d.addEventListener("DOMContentLoaded", f, false);
} else { f(); }
})(document, window, "yandex_metrika_callbacks2");
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/50897126" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
</body>