-
Notifications
You must be signed in to change notification settings - Fork 4
/
eth2weth-complete.js
60 lines (49 loc) · 1.37 KB
/
eth2weth-complete.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
const WanX = require('../');
/**
* Requirements:
* - Wanchain and Ethereum accounts are unlocked
* - Ethereum account has enough to cover the value defined in `opts` plus gas
* - Wanchain account has enough to cover the gas to redeem the token
*/
const config = {
wanchain: { url: 'http://localhost:18545' },
ethereum: { url: 'http://localhost:28545' },
};
const wanx = new WanX('testnet', config);
// New crosschain transaction
// ethereum, inbound
const cctx = wanx.newChain('eth', true);
// Generate a new redeemKey
const redeemKey = wanx.newRedeemKey();
// Define the transaction opts
const opts = {
from: '0x026a6301477c59ab17d11cade5fd00e5c8c6fa90',
to: '0x017ab346a4bb19f46c99bf19b6592828435540b0',
value: '1210000000000000000',
storeman: {
wan: '0x06daa9379cbe241a84a65b217a11b38fe3b4b063',
eth: '0x41623962c5d44565de623d53eb677e0f300467d2',
},
redeemKey,
};
// Do inbound ETH to WETH transaction
// send = lock + redeem:
cctx.send(opts);
// Handle events
cctx.on('info', info => {
console.log('this is the info', info);
});
cctx.on('error', err => {
console.log('this is the error', err);
cctx.removeAllListeners();
clearInterval(loop);
});
cctx.on('complete', () => {
console.log('COMPLETE!!!');
cctx.removeAllListeners();
clearInterval(loop);
});
// Loop to keep script alive
let loop = setInterval(() => {
console.log('tick');
}, 5000);