Create and Fund a Wallet
Overview
In order to make changes on Dash platform, you need a wallet with a balance. This tutorial explains how to generate a new wallet, retrieve an address from it, and transfer test funds to the address from a faucet.
Prerequisites
- node.js (v12+)
- Basic familiarity with JavaScript asychronous functions using async/await
- The Dash JavaScript SDK is initialized (covered in Connecting to EvoNet)
Code
const Dash = require('dash');
const clientOpts = {
network: 'evonet',
wallet: {
mnemonic: null, // this indicates that we want a new wallet to be generated
// if you want to get a new address for an existing wallet
// replace 'null' with an existing wallet mnemonic
},
};
const client = new Dash.Client(clientOpts);
const createWallet = async () => {
const account = await client.getWalletAccount();
const mnemonic = client.wallet.exportWallet();
const address = account.getUnusedAddress();
console.log('Mnemonic:', mnemonic);
console.log('Unused address:', address.address);
};
createWallet()
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
Mnemonic: thrive wolf habit timber birth service crystal patient tiny depart tower focus
Unused address: yXF7LsyajRvJGX96vPHBmo9Dwy9zEvzkbh
Please save your mnemonic for the next step and for re-use in subsequent tutorials throughout the documentation.
What's Happening
Once we connect to Evonet, we output the newly generated mnemonic from client.wallet.exportWallet()
and an unused address from the wallet from account.getUnusedAddress()
.
Next Step
Using the Evonet faucet at http://faucet.evonet.networks.dash.org/, send test funds to the "unused address" from the console output. You will need to wait until the funds are confirmed to use them. There is an Evonet block explorer running at http://insight.evonet.networks.dash.org:3001/insight/ which can be used to check confirmations.
Updated almost 4 years ago