Skip to content

Instantly share code, notes, and snippets.

@alexander-elgin
Created October 5, 2018 08:11
Show Gist options
  • Save alexander-elgin/e7d8db20442104c192a0a44c2c1e69c7 to your computer and use it in GitHub Desktop.
Save alexander-elgin/e7d8db20442104c192a0a44c2c1e69c7 to your computer and use it in GitHub Desktop.
Transfer Dash funds using InstantSend
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.0001;
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/sendix`, {
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