-
Notifications
You must be signed in to change notification settings - Fork 4
/
faucet.js
52 lines (43 loc) · 990 Bytes
/
faucet.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
const fs = require('fs');
const https = require('https');
const ethers = require('ethers');
let w
try {
w = JSON.parse(fs.readFileSync('wallet.json', 'utf8'));
} catch (err) {
console.error(`Could open wallet: ${err.message}`)
}
const data = JSON.stringify({
address: `0x${w.address}`,
amount: 1000000000000000000
})
const h = 'api.bitaps.com';
const p = '/eth/testnet/v1/faucet/send/payment';
console.log(`Getting testnet eth via ${h}${p}`);
const r = https.request({
hostname: h,
port: 443,
path: p,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
const ret = JSON.parse(data);
console.log(`waiting for ${ret.tx_hash}`);
ip.once(ret.tx_hash, (receipt) => {
console.log('tx confirmed')
})
});
})
r.on('error', (error) => {
console.error(error)
})
r.write(data)
r.end()