constbyteball=require('byteball');// Connect to mainnet official node 'wss://byteball.org/bb'constclient=newbyteball.Client();// Connect to a custom nodeconstclient=newbyteball.Client('wss://byteball.org/bb');// Connect to testnetconstoptions= { testnet:true };constclient=newbyteball.Client('wss://byteball.org/bb-test', options);
Close the client:
client.close();
All API methods follow this pattern:
// If the last argument is a function it is treated as a callbackclient.api.getJoint('oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=',function(err, result) {console.log(err, result);});// If a callback is not provided, a Promise is returnedclient.api.getJoint('oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=').then(function(result) {console.log(result);});
Transaction
To compose and post unit you need first to create a Byteball wallet and fund it with the native currency ‘bytes’. The generated WIF will be used on Byteball.js. Click on the link below to learn more:
Sending a payment:
constwif='5JBFvTeSY5...'; // WIF string generated (private key)constparams= { outputs: [ { address:'NX2BTV43XN6BOTCYZUUFU6TK7DVOC4LU',// The Byteball address of the recipient amount:1000// The amount he receives } ]};client.post.payment(params, wif,function(err, result) {console.log(result); // The unit hash is returned});