npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wm-kulap-libra

v2.0.8

Published

Typescript Library for Libra

Downloads

7

Readme

Kulap Libra

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

Kulap Libra is Libra-core compatible, and this project's forked from there.

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

Usable both in node and on browser clients.

Table of Content

Installation

To install with npm run:

npm install kulap-libra

Usage

You would most likely interact with these two modules

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

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 'kulap-libra';

// 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 'kulap-libra';

async function main() {
  // On Browser
  // const client = new LibraClient({
  //   transferProtocol: 'https',
  //   host: 'ac-libra-testnet.kulap.io',
  //   port: '443',
  //   dataProtocol: 'grpc-web-text'
  // })
  // On Node
  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() {
  // On Browser
  // const client = new LibraClient({
  //   transferProtocol: 'https',
  //   host: 'ac-libra-testnet.kulap.io',
  //   port: '443',
  //   dataProtocol: 'grpc-web-text'
  // })
  // On Node
  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() {
  // On Browser
  // const client = new LibraClient({
  //   transferProtocol: 'https',
  //   host: 'ac-libra-testnet.kulap.io',
  //   port: '443',
  //   dataProtocol: 'grpc-web-text'
  // })
  // On Node
  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);

}

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() {
  // On Browser
  // const client = new LibraClient({
  //   transferProtocol: 'https',
  //   host: 'ac-libra-testnet.kulap.io',
  //   port: '443',
  //   dataProtocol: 'grpc-web-text'
  // })
  // On Node
  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);
}

Rotate Key

async function main() {
  // On Browser
  // const client = new LibraClient({
  //   transferProtocol: 'https',
  //   host: 'ac-libra-testnet.kulap.io',
  //   port: '443',
  //   dataProtocol: 'grpc-web-text'
  // })
  // On Node
  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 account2 = wallet.newAccont();
  const account2Address = account2.getAddress().toHex();
  const response = await client.rotateKey(account1, account2Address);

  // transfer coin with newly updated key
  const response2 = await client.transferCoins(account1, account2Address, 1e6, account2.keyPair)
}

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