Created
September 29, 2018 16:09
-
-
Save alexander-elgin/32bfe5718ed777edf9c932c6e5981ab7 to your computer and use it in GitHub Desktop.
Transfer DASH Funds
This file contains hidden or 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 axios = require('axios'); | |
const dashcore = require('dashcore-lib'); | |
const API_BASE_URL = 'https://testnet-insight.dashevo.org/insight-api-dash'; | |
const sender = { | |
address: 'yRtqi4khyBHknDGarrsgrJLdvDipmbcbXx', | |
privateKey: '6e38851a2df2866b95e87aa7cb1c37356a5f6a2546ba7249b86a656288ed18dd' | |
}; | |
const recipient = { | |
address: 'yMoj6nPsL5rUrqTz6hc1irYUQRf5rRectP' | |
}; | |
const amount = 0.01; | |
const minerFee = dashcore.Unit.fromMilis(0.128).toSatoshis(); | |
void async function() { | |
try { | |
const privateKey = new dashcore.PrivateKey(sender.privateKey); | |
const senderAddress = privateKey.toAddress(dashcore.Networks.testnet); | |
const utxosData = await axios.get(`${API_BASE_URL}/addr/${senderAddress.toString()}/utxo`); | |
const utxos = utxosData.data.map(utxo => new dashcore.Transaction.UnspentOutput(utxo)); | |
const transaction = new dashcore.Transaction() | |
.from(utxos) | |
.to(dashcore.Address.fromString(recipient.address), dashcore.Unit.fromMilis(amount).toSatoshis()) | |
.change(senderAddress) | |
.sign(privateKey); | |
const broadcastResult = await axios.post(`${API_BASE_URL}/tx/send`, { | |
rawtx: transaction.toString(), | |
}); | |
console.log(broadcastResult.data); | |
console.log('success'); | |
} catch (error) { | |
console.error(error); | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment