Skip to content
A lightweight JavaScript library for Libra
JavaScript Shell
Branch: master
Clone or download
Latest commit bfcd400 Jul 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist Update dist Jul 23, 2019
docs Init library (#1) Jun 22, 2019
src Decode data get transactions response (#9) Jul 23, 2019
test Decode data get transactions response (#9) Jul 23, 2019
.editorconfig Init library (#1) Jun 22, 2019
.eslintrc Init library (#1) Jun 22, 2019
.gitignore update proto https://community.libra.org/t/testnet-update-scheduled-f… ( Jul 11, 2019
LICENSE Init library (#1) Jun 22, 2019
README.md Decode data get transactions response (#9) Jul 23, 2019
generate-proto.sh update proto https://community.libra.org/t/testnet-update-scheduled-f… ( Jul 11, 2019
package-lock.json Set v0.0.5 Jul 23, 2019
package.json
rollup.config.js Add util deserialize raw txn bytes (#4) Jun 23, 2019

README.md

npm Join the chat

Libra gRPC

A lightweight JavaScript library for Libra

Node.js

To install Libra gRPC on Node.js, open your terminal and run:

npm install libra-grpc --save

Usage

var libra = require('libra-grpc');

// Init gRPC client
var client = new libra.Client('ac.testnet.libra.org:8000');

// Get account state
var params = {
  address: Buffer.from('435fc8fc85510cf38a5b0cd6595cbb8fbb10aa7bb3fe9ad9820913ba867f79d4', 'hex')
};
client.request('get_account_state', params, function(err, result) {
  console.log(err, result);
});

// If a callback is not provided, a Promise is returned
client.request('get_account_state', params).then(function(result) {
  console.log(result);
});

See more examples

API

Get account state

Get the latest state for an account.

var params = {
  address: Buffer.from('435fc8fc85510cf38a5b0cd6595cbb8fbb10aa7bb3fe9ad9820913ba867f79d4', 'hex')
};
client.request('get_account_state', params, function(err, result) {
  console.log(err, result);
});

Get account transaction

Get the committed transaction by account and sequence number.

var params = {
  account: Buffer.from('435fc8fc85510cf38a5b0cd6595cbb8fbb10aa7bb3fe9ad9820913ba867f79d4', 'hex'),
  sequence_number: 1,
  fetch_events: true
};
client.request('get_account_transaction_by_sequence_number', params, function(err, result) {
  console.log(err, result);
});

Get events

Get event by account and path.

var params = {
  access_path: {
    address: Buffer.from('435fc8fc85510cf38a5b0cd6595cbb8fbb10aa7bb3fe9ad9820913ba867f79d4', 'hex')
  },
  start_event_seq_num: 2,
  ascending: true,
  limit: 10
};
client.request('get_events_by_event_access_path', params, function(err, result) {
  console.log(err, result);
});

Get transactions

Get the committed transaction by range

var params = {
  start_version: 1,
  limit: 10,
  fetch_events: true
};
client.request('get_transactions', params, function(err, result) {
  console.log(err, result);
});

Getting help

If you believe you're experiencing a bug with or want to report incorrect documentation, open an issue on our issue tracker. For a more real-time avenue of communication, check out the Discord or Telegram servers. There you'll find community members who can help answer about development questions.

License

MIT.

You can’t perform that action at this time.