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('hello4@gmail.com')
		
		//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

//from the initial getUsers command (line 22), the following object is obtained 
//giving the IDs and all emails of the exchange's users
{ count: 22,
  data:
   [ { id: 161537, email: 'hello2@gmail.com' }, 
     { id: 161535, email: 'hello1@gmail.com' },
     //~~
     { id: 161045, email: 'test1@email.com' },
     { id: 161044, email: 'test@email.com' },
     
//following the createUser command (line 25) the string we input as a parameter 
//has now been used to add a new user, we can inspect our list by again getting 
//using getUsers (line 28)
{ count: 23,
  data:
   [ { id: 161582, email: 'hello4@gmail.com' }, //<-- The newely added user
     { id: 161537, email: 'hello2@gmail.com' },
     //~~
     { id: 161045, email: 'test1@email.com' },
     { id: 161044, email: 'test@email.com' },
     
//Using the getUser command (line 37) and supplying the newest user's ID, we can 
//inspect the deatails of this new user, before the btc address is added
{ id: 161582,
  email: 'hello4@gmail.com',
  balance:
   { btc_balance: 0,
     btc_available: 0,
     //~~
     xht_balance: 0,
     xht_available: 0 },
  wallet: [] } //<-- This user currently has no addresses
  
//following the createUserCryptoAddress and requesting it for btc and for this
//newest user (line 40) and then again using getUser (line 43) we can now see 
//the new address created
{ id: 161582,
  email: 'hello4@gmail.com',
  balance:
   { btc_balance: 0,
     btc_available: 0,
     //~~
     xht_balance: 0,
     xht_available: 0 },
  wallet:
   [ { currency: 'btc',
       address: '3FR4Ab7Gc1LgDWsELSvsgwYVp8AzaMtUsJ', //<-- newly created address
       network: 'btc',
       standard: null,
       is_valid: true,
       created_at: '2022-05-30T15:26:46.439Z' } ] }

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