@graviton-network/graviton

0.1.8 • Public • Published

npm npm CircleCI GitHub license

Graviton.js

A pure and powerful JavaScript Graviton library.

Documentation

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:

Generate a random address

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @graviton-network/graviton

Weekly Downloads

8

Version

0.1.8

License

MIT

Unpacked Size

330 kB

Total Files

12

Last publish

Collaborators

  • gravitino