Graviton.js
A pure and powerful JavaScript Graviton library.
Getting started
To install and run Graviton.js, follow this quick start guide
Install
Graviton.js was designed to work both in the browser and in Node.js.
Node.js
To install Graviton.js on Node.js, open your terminal and run:
npm i @graviton-network/graviton --save
Usage
Ways to initiate WebSocket client:
const graviton = require('@graviton-network/graviton');
// Connect to mainnet official node 'wss://universe.graviton.network'
const client = new graviton.Client();
// Connect to a custom node
const client = new graviton.Client('wss://universe.graviton.network');
// Connect to testnet
const options = { testnet: true };
const client = new graviton.Client('wss://testnet.graviton.network', options);
Close the client:
client.close();
All API methods follow this pattern:
// If the last argument is a function it is treated as a callback
client.api.getJoint('JOINTKEY', function(err, result) {
console.log(err, result);
});
// If a callback is not provided, a Promise is returned
client.api.getJoint('JOINTKEY').then(function(result) {
console.log(result);
});
Transaction
To compose and post unit you need first to create a Graviton wallet and fund it with the native currency ‘bytes’. The generated WIF will be used on Graviton.js. Click on the link below to learn more:
Sending a payment:
const wif = 'FFFFFFFFFF...'; // WIF string generated (private key)
const params = {
outputs: [
{
address: 'WALLET_ADDRESS', // The Graviton 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
});
License
MIT.