Setup: Using the transferAsset function
Before you can run you gotta walk, let's get some initial funds in our test accounts and see the benefits of the transferAsset function, as opposed to using pure trades
Transfer Assets Script
//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();
let userList = await network.getUsers();
//finding the three accounts IDs we want to use
let accountB = await network.getUser(userList.data[0].id);
let accountA = await network.getUser(userList.data[1].id);
let accountAdmin = await network.getUser(userList.data[2].id);
//view the details of the three ids we will use
console.log(accountA);
console.log(accountB);
console.log(accountAdmin);
//transfer assets between accounts on the network (fee free!)
//first parameter is the sender ID, second is the receiver ID
//third parameter is what we want to transfer, and fouth is amount
//so here we are sending 100 XHT from the admin to account A
await network.transferAsset(accountAdmin.id, accountA.id, 'xht', 100);
//and here, 100 XHT from admin to account B
await network.transferAsset(accountAdmin.id, accountB.id, 'usdt', 20);
//refresh the accounts to show the new balances
accountB = await network.getUser(userList.data[0].id);
accountA = await network.getUser(userList.data[1].id);
accountAdmin = await network.getUser(userList.data[2].id);
//lets have a look at the new balances of accounts
console.log(accountA);
console.log(accountB);
console.log(accountAdmin);
} catch (err) {
console.log(err);
}
})();
Transfer Assets Script: The Output
Last updated