• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    TypeScript
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A javascript client for libra built with typescript

Build Status

NOTE: This library is currently not being maintained. This is because of my current busy schedule and Libra not being stable and having a lot of breaking changes occurring. I'll resume maintaining and updating it when Libra becomes more stable. In the meantime, you can use some of the other libraries like Kulap libra. Thank you ❣️

Libra Core

Libra Core is a javascript library client that can be used to interact with libra nodes. It is built using typescript.

This is still under heavy testing, so please report any issues that you might encounter using it.

The end goal is to make it usable both in node and on browser clients too, but currently it is mostly compatible with node.

Table of Content

Prepare

  • Node ^v12.0.0 is required for sha3-256. You can use nvm to download/use node v12 by following.
nvm install 12
nvm use 12

Installation

To install with npm run:

npm install libra-core

Usage

You would most likely interact with these two modules

import { LibraWallet, LibraClient } from 'libra-core';

Creating an Account

In order to create a libra account, you would need to instantiate the LibraWallet like:

// you may need to use require for node
import { LibraWallet, Account as LibraAccount } from 'libra-core';

// please don't use this mnemonic outside of this sample code
// also mnemonics are optional. If you don't specify one a random mnemonic is generated and used.
const wallet = new LibraWallet({
        mnemonic: 'upgrade salt toy stable drop paddle'
      });

// generate a new account
const account = wallet.newAccount();

// or if you have your secret key you can create an account from it
// const secretKey = 'pub-hex-secret-key-here' 
// const account = LibraAccount.fromSecretKey(secretKey);


// you can see your address by:
console.log(account.getAddress().toHex());

Minting Amount

Currently minting only works for testnet and uses the faucet service.

To mint you need to create a LibraClient and use it to mint

import { LibraClient, LibraNetwork } from 'libra-core';

async function main() {
  const client = new LibraClient({ network: LibraNetwork.Testnet });

  const account = wallet.newAccount();

  // mint 2 libracoins to users accounts
  await client.mintWithFaucetService(account.getAddress(), 20e6);
}

await main();

Checking an address balance

async function main() {
  const client = new LibraClient({ network: LibraNetwork.Testnet });

  const accountAddress = '854563c50d20788fb6c11fac1010b553d722edb0c02f87c2edbdd3923726d13f';
  const accountState = await client.getAccountState(accountAddress);

  // log account balance
  console.log(accountState.balance.toString());

  // Account state has other information that you could be interested in such as `sequenceNumber`.
}

await main();

Transferring Libra Coins

async function main() {
  const client = new LibraClient({ network: LibraNetwork.Testnet });
  const wallet = new LibraWallet({
    mnemonic:
     'lend arm arm addict trust release grid unlock exhibit surround deliver front link bean night dry tuna pledge expect net ankle process mammal great',

  });
  const account = wallet.newAccount();
  const account2Address = '854563c50d20788fb6c11fac1010b553d722edb0c02f87c2edbdd3923726d13f';
  const response = await client.transferCoins(account, account2Address, 1e6);

  // wait for transaction confirmation
  await response.awaitConfirmation(client);
}

await main();

Executing Transactions with Custom Program

You can execute a program using client.execute() take a look at how client.transferCoins() uses it for transfer transactions. You are welcome to help contribute to making this documentation better.

Query Transaction with Sequence Number

async function main() {
  const client = new LibraClient({ network: LibraNetwork.Testnet });
  const accountAddress = '7f58df27522872ecfac340c5c072427e6f8083ca3c79bb748cdd1ae073dacc42';
  const sequenceNumber = 43; //can also use a string for really large sequence numbers;

  const transaction = await client.getAccountTransaction(accountAddress, sequenceNumber);
}

await main();

Development

  • Clone the repository
  • Run npm install to install the dependency
  • Test with npm test
  • You might need to run npm install -g grpc-tools if you want to regenerate protobuffer classes

Contribution

  • If you notices a bug or anomaly, please open an issue to track it.
  • If you intend on working on a feature that doesn't have an issue yet. Please open an issue first so we can track its progress together.

License

MIT

More Repositories

1

pinata-sdk

Rust SDK for the Pinata IPFS platform
Rust
22
star
2

realtime-app-architecture-kotlin

Kotlin
14
star
3

SendNGNTDapp

Send NGNT without ETH using Gas Station Network
TypeScript
14
star
4

paystack-php

PHP Library for Paystack.co
PHP
13
star
5

who-is-typing-pusher

Tutorial to implement who is typing feature.
JavaScript
9
star
6

laravel-realtime-map

PHP
8
star
7

angular-realtime-map

TypeScript
7
star
8

libra-core-wallet

Typescript Library for Libra Wallet both browser and client.
TypeScript
7
star
9

FDR

A ERC20 Token for raising funds.
JavaScript
6
star
10

slack-ping-bot

A Pinging bot for Slack
JavaScript
5
star
11

k4indie

A Kubernetes operator providing Heroku-like experience for Indie Hackers
Go
5
star
12

kotlin-realtime-counter-pusher

Kotlin
4
star
13

ImageQuantizationUsingJS

JavaScript
4
star
14

AdvancedNodeStarter

Sample App for a course on Node
JavaScript
2
star
15

collab-editor

Android Collaborative Editor
Java
2
star
16

sockethook-rust

A Webhook-to-WebSocket proxy in Rust
Rust
2
star
17

events-tracking-api

Node.JS API for handling Github Events
JavaScript
2
star
18

who-is-typing-android-pusher

Android Code for Who's typing Pusher Tutorial
Java
2
star
19

Ayo-Game

My implementation of Ayo Olopon. An african game. Really Cool.
Python
1
star
20

etl_for_terminal_data

JavaScript
1
star
21

rust-algorand-sdk

Rust
1
star
22

GoStructures

Data Structure implemented in Go
Go
1
star
23

Hacker-Hearth-Help-Ashu

C++
1
star
24

kotlin-realtime-counter-server-pusher

Code for Pusher Reatlime Counter Tutorial in Kotlin
Kotlin
1
star
25

marketprotocol_subgraph

The Graph subgraph for Market Protocol
TypeScript
1
star
26

pair-algorithm

Algorithm for Pairing Developers with different levels of experience and background
Swift
1
star
27

proto_api_cleaner

Tool to remove http api annotations from a protocol buffer file
JavaScript
1
star
28

IoTHub

IoT Hub for learning
JavaScript
1
star
29

SingleFile

A File system that archives the whole system directories and files. Also checks for redundant files and cleans them up efficiently
Python
1
star
30

gdg-oau-firebase-meetup

Demo Web App for the GDG OAU Firebase Meetup in September 2016
CSS
1
star