-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
54 lines (47 loc) · 1.42 KB
/
index.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
const express = require('express')
const cors = require('cors');
const app = express()
const port = 3000
const RippleAPI = require('ripple-lib').RippleAPI
const rippledUri = process.env['RIPPLED_URI']
const address = process.env['FUNDING_ADDRESS']
const secret = process.env['FUNDING_SECRET']
const amount = process.env['XRP_AMOUNT']
app.use(cors());
app.post('/accounts', (req, res) => {
const api = new RippleAPI({
server: rippledUri
});
api.connect().then(() => {
console.log('Connected...')
const account = api.generateAddress()
console.log('Generated new account:', account.address)
return api.preparePayment(address, {
source: {
address: address,
maxAmount: {
value: amount,
currency: 'XRP'
}
},
destination: {
address: account.address,
amount: {
value: amount,
currency: 'XRP'
}
}
}, {maxLedgerVersionOffset: 5}).then(prepared => {
const {signedTransaction} = api.sign(prepared.txJSON, secret);
console.log('Payment transaction signed...');
api.submit(signedTransaction).then(() => {
console.log(`Funded ${account.address} with ${amount} XRP`)
res.send({
account: account,
balance: Number(amount)
})
})
})
}).catch(err => { console.log(err) })
})
app.listen(port, () => console.log(`Altnet faucet listening on port ${port}!`))