Send Funds
Overview
Once you have a wallet and some funds (tutorial), another common task is sending Dash to an address. (Sending Dash to a contact or a DPNS identity requires the Dashpay app, which has not been registered yet.)
Code
const Dash = require('dash');
const clientOpts = {
network: 'evonet',
wallet: {
mnemonic: 'your wallet mnemonic goes here'
}
};
const client = new Dash.Client(clientOpts);
async function sendFunds() {
const account = await client.wallet.getAccount();
await account.isReady();
try {
const transaction = account.createTransaction({
recipient: 'yNPbcFfabtNmmxKdGwhHomdYfVs6gikbPf', // Evonet faucet
satoshis: 100000000, // 1 Dash
});
const result = await account.broadcastTransaction(transaction);
console.log('Transaction broadcast!\nTransaction ID:', result);
} catch (e) {
console.error('Something went wrong:', e);
} finally {
client.disconnect();
}
}
sendFunds();
What's Happening
After initializing the Client, we build a new transaction with account.createTransaction
. It requires a recipient and an amount in satoshis (often called "duffs" in Dash). 100 million satoshis equals one Dash. We pass the transaction to account.broadcastTransaction
and wait for it to return. Then we output the result, which is a transaction ID. After that we disconnect from the Client so node can exit.
Updated over 4 years ago
What’s Next