Simple Example: Creating a User and Wallet

In this walk-through, we will see how in a matter of a few commands we can set up the means to add a user to the HollaEx network and then create a Bitcoin wallet for them.

The Code

To begin, we need to lay the groundwork that all our scripts using the Network Tools will have in common as discussed on the 'Accessing the Network Tool Library' page previously. Following this, the meat of our code is all performed in a single asynchronous function. Check the comments for an explanation of what each line does.

When using the createUser function, the newly added user will only exist on the HollaEx Network, and not the Exchange Kit itself. Check the note at the bottom of the list on the 'Functions' page for more details.

Some of the lines in the following code are not strictly necessary and have been addded just used to monitor the output of what we have done.

//using the index file, get access to the functions we will be using throughout
//Note: make sure the index file is pointed in the correct relative folder to this
//script
const Network = require('../index');

const network = new Network({
    apiUrl: 'https://api.hollaex.network',
    apiKey: '<YOUR_API_KEY>',
    apiSecret: '<YOUR_API__SECRET_KEY>',
    activation_code: '<YOUR_ACTIVATION_CODE>',
});

//main function for adding user and their address
(async () => {
	try {
		//initialise the network
		const init = await network.init();
		
		//check user list before addition of new user
		console.log(await network.getUsers())	
			
		//create new user
		await network.createUser('[email protected]')
		
		//compare our list with the new user added
		console.log(await network.getUsers())
		
		//store this list in variable
		let newUserList = await network.getUsers()
		
		//get the newest (first) item in this array
		let newestUser = newUserList.data[0]
		
		//See our new users information before adding a crypto wallet
		console.log(await network.getUser(newestUser.id))
		
		//create btc address for the newest user
		await network.createUserCryptoAddress(newestUser.id, 'btc')
		
		//compare user data now with a btc wallet address
		console.log(await network.getUser(newestUser.id))
		
	} catch (err) {
		console.log(err)
	}
	

}) ();

The Output

Running the above script through the terminal, in the scripts directory with node add-user-wallet.js gives the following output. Some unessential lines have been omitted for readability.

Check the comments for information on what this output is, and where it came from

Summary

This very simple example shows how with only two necessary functions, createUser and createUserCryptoAddress, we have been able to access the HollaEx crypto infrastructure with ease. This of course is only the start of what is possible with the Network Tools, and you are encouraged to try them out yourself and see what is possible!

Last updated