Last active
July 20, 2020 08:05
-
-
Save dashameter/390fdcc382b43123277479ef4816ea17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const express = require('express'); | |
const Dash = require('dash'); | |
const cors = require('cors'); | |
const app = express(); | |
app.use(cors({ origin: true })); | |
const clientOpts = { | |
network: 'testnet', | |
wallet: { | |
mnemonic:"<seed with balance>" | |
} | |
}; | |
app.get('/drip/:address', async (req, res) => { | |
console.log("Drip requested by:", req.params.address) | |
const client = new Dash.Client(clientOpts); | |
const account = await client.wallet.getAccount(); | |
try { | |
const address = account.getUnusedAddress().address | |
const transaction = account.createTransaction({ | |
recipients: [ | |
{ | |
recipient: req.params.address, | |
satoshis: 1000000 | |
}, | |
{ | |
recipient: req.params.address, | |
satoshis: 1000000 | |
}, | |
{ | |
recipient: req.params.address, | |
satoshis: 1000000 | |
}, | |
] | |
}); | |
const result = await account.broadcastTransaction(transaction); | |
console.log('Transaction broadcast!\nTransaction ID:', result); | |
return res.status(200).send("drop: " + req.params.address); | |
} catch (e) { | |
console.error('Something went wrong:', e); | |
return res.status(200).send(e.message); | |
} finally { | |
client.disconnect(); | |
} | |
}); | |
exports.evofaucet = functions.https.onRequest(app); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment