In order to make changes on Hellar 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.
`const Hellar = require('hellar');
const clientOpts = { network: 'mainnet', 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 offlineMode: true, // this indicates we don't want to sync the chain // it can only be used when the mnemonic is set to 'null' }, };
const client = new Hellar.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());
// Handle wallet async errors
client.on('error', (error, context) => {
console.error(Client error: ${error.name}
);
console.error(context);
});`
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.
Once we connect, we output the newly generated mnemonic from client.wallet.exportWallet()
and an unused address from the wallet from account.getUnusedAddress()
.
Using the faucet at https://hellar.io/faucet/, 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 a block explorer running at https://hellar.io/insight/ which can be used to check confirmations.