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

@koibanx/ledger-sdk

v0.0.10

Published

Ledger SDK

Downloads

683

Readme

Koibanx Ledger SDK

Ledger SDK based in module Ledger

The ledger module provides a way to handle custom tokens transactions among accounts. Each token supply can be increased by minting, or decreased by burning. Every transaction is made asynchronously and it´s state notified by POST callbacks. Every token, account and transaction is backed by a blockchain providing all its benefits and hiding the complexity associated to the technology.

What can be done?

  • Create tokens (example US Dolar)
  • Create accounts to hold any number of different tokens (example, an account can hold, US Dolars, Mexican Pesos, …etc)
  • Mint and burn tokens into accounts: Every time you mint you are incrementing the total supply (circulating amount of tokens), and every time you burn, you decrease that supply
  • Transfer tokens between any account: Here the supply is not changed
  • Swap tokens: Given two tokens and 2 accounts (can be between the same account) exchange the tokens one for another (equivalent to burn X amount from one token and mint Y to the other in an atomic transaction)
  • Check token´s supply

What do i need to care about?

As the ledger uses the blockchain to settle its transactions, and for using the blockchain you need to pay, you must ensure that:

  1. The gas station you configured has enough funds for you to transact
  2. If a budget manager is involved in the fueling process (check the gas station configuration for that), provide while creating a token a budget allowance with enough funds. Keep in mind that you will be charged for every set of 50 transactions you generate (this is configurable, as greater the amount of transactions you book, the cheaper the fueling process gets)

Endpoint documentation

Check the OpenApi 3.0 documentation Here

SDK Documentation

Feast yourself

Installation

npm install @koibanx/ledger-sdk

NOTE: you must have the npm token in your .npmrc file


Initialization

Node

Using ES6 import

import LedgerSdk from '@koibanx/ledger-sdk';

const ledger = LedgerSdk({
  baseURL: 'http://your-url',
});

With require

exports.__esModule = true;
const LedgerSdk = require('@koibanx/ledger-sdk')["default"];

const ledger = LedgerSdk({
  baseURL: 'http://your-url',
});

Types

  • Typescript (@koibanx/ledger-sdk/dist/index.d.ts)

Examples

Using ES6 import

import ledgerSdk from "@koibanx/ledger-sdk";

const ledger = LedgerSdk({
    baseURL: 'http://your-url',
})

const catchError = (err, modulo) => {
  console.log('Modulo: ', modulo);
  console.log('details: ', err.details);
  console.log('shortMessage: ', err.message);
  console.log('errorCode: ', err.code);
}


/** Default */

ledgerSdk.getLedgerStatus().then((res) => {
  console.log('getLedgerStatus: ', res.toDate);
}).catch((err) => catchError(err, 'getLedgerStatus'));

ledgerSdk.getEstimatedRemainingLedgerUsage().then((res) => {
  console.log('getEstimatedRemainingLedgerUsage: ', res);
}).catch((err) => catchError(err, 'getEstimatedRemainingLedgerUsage'));

ledgerSdk.getFuelingLedgerAccount().then((res) => {
  console.log('getFuelingLedgerAccount: ', res);
}).catch((err) => catchError(err, 'getFuelingLedgerAccount'));

ledgerSdk.wallets.createWallet({})
  .then((res) => console.log('createWallet: ', res))
  .catch((err) => catchError(err, 'createWallet'));

ledgerSdk.getLedgerTransaction({ id: '62ec9b642b0be63e4b5cbbba' })
  .then((res) => console.log('getLedgerTransaction: ', res.status))
  .catch((err) => catchError(err, 'getLedgerTransaction'));



/** Wallet */

ledgerSdk.wallets.getWallet(({ id: '62ec970b2b0be63e4b5cbb97' }))
  .then((res) => console.log('getWallet: ', res.status))
  .catch((err) => catchError(err, 'getWallet'));

ledgerSdk.wallets.createWallet({ callback: 'http://testing.com' })
  .then((res) => console.log('createWallet: ', res.status))
  .catch((err) => catchError(err, 'createWallet'));
    


/** Tokens */

ledgerSdk.tokens.createToken({
  budgetAllowance: '62f42d17176cc9be63d5d1b1',
  callback: 'http://testing.com',
}).then((res) => console.log('createToken: ', JSON.stringify(res)))
  .catch((err) => catchError(err, 'createToken'));

ledgerSdk.tokens.getToken({
  id: '6302b2da6ee0cd90f068b93e',
}).then((res) => console.log('getToken: ', JSON.stringify(res)))
  .catch((err) => catchError(err, 'getToken'));

ledgerSdk.wallets.createWallet({}).then((wall) => {
  ledgerSdk.tokens.createToken({}).then((tok) => {
    ledgerSdk.tokens.mintToken({
      receiverWalletId: wall._id,
      amount: 10,
      token: tok._id,
    })
      .then((res) => console.log('mintToken: ', JSON.stringify(res)))
      .catch((err) => catchError(err, 'mintToken'));
  });
});

ledgerSdk.wallets.createWallet({}).then((wall) => {
  ledgerSdk.tokens.createToken({}).then((tok) => {
    ledgerSdk.tokens.burnToken({
      receiverWalletId: wall._id,
      amount: 10,
      token: tok._id,
    })
      .then((res) => console.log('burnToken: ', JSON.stringify(res)))
      .catch((err) => catchError(err, 'burnToken'));
  });
});

ledgerSdk.wallets.createWallet({}).then((wall) => {
  ledgerSdk.tokens.createToken({
    budgetAllowance: 'dummy',
  }).then((tok) => {
    ledgerSdk.tokens.mintToken({
      receiverWalletId: wall._id,
      amount: 10,
      token: tok._id,
    })
      .then((mint) => {
        sleep(60000).then(() => {
          allTransfersPerformed([mint]).then(() => {
            ledgerSdk.tokens.getTokenBalance({
              walletId: wall._id,
              tokenId: tok._id,
            }).then((res) => console.log('getTokenBalance: ', JSON.stringify(res.balance)))
              .catch((err) => catchError(err, 'getTokenBalance'));
          }).catch((err) => catchError(err, 'allTransfersPerformed'));
        });
      })
      .catch((err) => catchError(err, 'mintToken'));
  });
});

ledgerSdk.wallets.createWallet({}).then((wall) => {
  ledgerSdk.wallets.createWallet({}).then((wall2) => {
    ledgerSdk.tokens.createToken({
      budgetAllowance: 'dummy2',
    }).then((tok) => {
      ledgerSdk.tokens.mintToken({
        receiverWalletId: wall._id,
        amount: 10,
        token: tok._id,
      }).then((mint) => {
        sleep(120000).then(() => {
          allTransfersPerformed([mint]).then(() => {
            ledgerSdk.tokens.getTokenBalance({
              walletId: wall._id,
              tokenId: tok._id,
            }).then(() => {
              ledgerSdk.tokens.transferTokens({
                amount: 10,
                senderWalletId: wall._id,
                receiverWalletId: wall2._id,
                token: tok._id,
              }).then((res) => console.log('transferTokens', JSON.stringify(res)))
                .catch((err) => catchError(err, 'transferTokens'));
            }).catch((err) => catchError(err, 'getTokenBalance'));
          }).catch((err) => catchError(err, 'allTransfersPerformed'));
        });
      })
        .catch((err) => catchError(err, 'mintToken'));
    });
  });
});