-
Notifications
You must be signed in to change notification settings - Fork 4
/
eth2weth-lock-manual.js
77 lines (59 loc) · 2.05 KB
/
eth2weth-lock-manual.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
const WanX = require('../');
const Web3 = require('web3');
const keythereum = require('keythereum');
const utils = require('./utils');
/**
* Requirements:
* - Ethereum account has enough to cover the value defined in `opts` plus gas
*/
const config = {
wanchain: { url: 'http://localhost:18545' },
ethereum: { url: 'http://localhost:28545'},
};
const web3wan = new Web3(new Web3.providers.HttpProvider(config.wanchain.url));
const web3eth = new Web3(new Web3.providers.HttpProvider(config.ethereum.url));
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,
};
// Get Ethereum private keys
const ethDatadir = '/home/user/.ethereum/testnet/';
const ethKeyObject = keythereum.importFromFile(opts.from, ethDatadir);
const ethPrivateKey = keythereum.recover('mypassword', ethKeyObject);
// Do inbound ETH to WETH lock transaction
Promise.resolve([])
.then(sendLock)
.then(confirmLock)
.catch(err => {
console.log('Error:', err);
});
async function sendLock() {
console.log('Starting eth inbound lock', opts);
// Get the raw lock tx
const lockTx = cctx.buildLockTx(opts);
// Send the lock transaction on Ethereum
const receipt = await utils.sendRawEthTx(web3eth, lockTx, opts.from, ethPrivateKey)
console.log('Lock submitted and now pending on storeman');
console.log(receipt);
}
async function confirmLock() {
// Get the current block number on Wanchain
const blockNumber = await web3wan.eth.getBlockNumber();
// Scan for the lock confirmation from the storeman
const log = await cctx.listenLock(opts, blockNumber);
console.log(log);
console.log('COMPLETE!!!');
}