dragon-lotto-base-sdk

This SDK is intended to build for the convinience of developers whose want to interact with our Sabay Stellar's network.

this package has been deprecated
Last updated 2 years ago by him-ich .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dragon-lotto-base-sdk 
SYNC missed versions from official npm registry.

Dragon Lotto Base SDK

This SDK is intended to build for the convinience of developers whose want to interact with our Sabay Stellar's network.

Features

  • Initialize an account based on the provided seed (Create or Load the exists account)
  • Top-up (Request top-up from provider)
  • Check Balance (Custom & Native assets)
  • Clear the custom asset

Installation

Using npm:

npm install dragon-lotto-base-sdk

Examples

Create a new account or load an existing one from the network.

import { Account, Server } from 'dragon-lotto-base-sdk';

const seed = 'some-unique-seed';
const development = true; // this is in a development environment

// const server = Server.loadProductionServer(); // production
const server = Server.loadTestServer(); // development

const account = new Account(seed, server, development);

// the address that would consider as a parent of user's account
const source = 'GCSYLEFISTDRFXBMWYKEFWPKM73PGBDUCGJTIS3TLTC3LQ67TJSFEZ3P';
const passphrase = 'sabay';

account
    .init()
    .sources(source)
    .passPhrase(passphrase)
    .submit()
    .then(result => {
        // handle result
    })
    .catch(error => {
        // handle error
    });

Response:

{
    "status": "xxx",
    "message": "xxx",
    "body": [
        {
            "balance": "xxx",
            "buying_liabilities": "xxx",
            "selling_liabilities": "xxx",
            "limit": "xxx",
            "asset_type": "xxx",
            "asset_code": "xxx",
            "asset_issuer": "xxx",
        },
        {
            "balance": "xxx",
            "buying_liabilities": "xxx",
            "selling_liabilities": "xxx",
            "limit": "xxx",
            "asset_type": "native",
            "asset_code": "xxx",
            "asset_issuer": "xxx",
        }
    ]
}

Request a top-up for an account by sending a small amout of lumens (0.0000001) to the fund provider.

import { Account, Server } from 'dragon-lotto-base-sdk';

const seed = 'some-unique-seed';
const development = true; // this is in a development environment

// const server = Server.loadProductionServer(); // production
const server = Server.loadTestServer(); // development

const account = new Account(seed, server, development);

// the address of fund provider
const source = 'GCSYLEFISTDRFXBMWYKEFWPKM73PGBDUCGJTIS3TLTC3LQ67TJSFEZ3P';
const reference_id = 'some_unique_reference'; // limit 28-byte

account
    .topUp()
    .sources(source)
    .reference(reference_id)
    .submit()
    .then(result => {
        // handle result
    })
    .catch(error => {
        // handle error
    });

On success, this doesn't mean the account get the fund. The client just make a request to top-up to the server of provider. Client itself still need to wait until the server receive the request and send back the fund.

Response:

{
    "status": "xxx",
    "message": "xxx",
    "body": [
        {
            "hash": "xxx",
            "ledger": "xxx",
            "envelope_xdr": "xxx",
            "result_xdr": "xxx",
            "result_meta_xdr": "native",
            "offerResults": "xxx"
        }
    ]
}

To check an account's balance:

import { Account, Server } from 'dragon-lotto-base-sdk';

const seed = 'some-unique-seed';
const development = true; // this is in a development environment

// const server = Server.loadProductionServer(); // production
const server = Server.loadTestServer(); // development

const account = new Account(seed, server, development);

const passphrase = 'sabay';
const asset_code = 'LTC';

// example 1
//
// get blace of native and default custom asset
account
    .getBalances(passphrase)
    .then(result => {
        // handle result
    })
    .catch(error => {
        // handle error
    });
    
// example 2
//
// get blace of native and other custom asset
account
    .getBalances(passphrase, asset_code)
    .then(result => {
        // handle result
    })
    .catch(error => {
        // handle error
    });

Response:

{
    "status": "xxx",
    "message": "xxx",
    "body": [
        {
            "balance": "xxx",
            "buying_liabilities": "xxx",
            "selling_liabilities": "xxx",
            "limit": "xxx",
            "asset_type": "xxx",
            "asset_code": "xxx",
            "asset_issuer": "xxx",
        },
        {
            "balance": "xxx",
            "buying_liabilities": "xxx",
            "selling_liabilities": "xxx",
            "limit": "xxx",
            "asset_type": "native",
            "asset_code": "xxx",
            "asset_issuer": "xxx",
        }
    ]
}

Clearing an asset:

import { Account, Server } from 'dragon-lotto-base-sdk';

const seed = 'some-unique-seed';
const development = true; // this is in a development environment

// const server = Server.loadProductionServer(); // production
const server = Server.loadTestServer(); // development

const account = new Account(seed, server, development);

// the adress where all the fund will be sent to
const source = 'GCSYLEFISTDRFXBMWYKEFWPKM73PGBDUCGJTIS3TLTC3LQ67TJSFEZ3P';
const user_id = 'some_user_id';
const passphrase = 'sabay';

// example 1
//
// to clear all the remaining assets back to its own provider
// with the default address and asset_code that has set in the SDK
account
    .clear()
    .sources(source)
    .reference(user_id)
    .passPhrase(passphrase)
    .submit()
    .then(result => {
        // return the details of remaining balances of native and custom asset
    })
    .catch(error => {
        // handle error
    });
    
// example 2
//
// to clear only some amount of asset
// with custom address and asset_code
const amount = 5;
const asset_code = 'LTC';
const asset_issuer = 'GCIE6MTOWK37MQGJVLS3QSO67KTU2VUPWWH4D5336UL6YERDPT23U2IJ';

account
    .clear(amount, asset_code, asset_issuer)
    .sources(source)
    .reference(user_id)
    .passPhrase(passphrase)
    .submit()
    .then(result => {
        // return the details of remaining balances of native and custom asset
    })
    .catch(error => {
        // handle error
    });    

Response:

{
    "status": "xxx",
    "message": "xxx",
    "body": [
        {
            "balance": "xxx",
            "buying_liabilities": "xxx",
            "selling_liabilities": "xxx",
            "limit": "xxx",
            "asset_type": "xxx",
            "asset_code": "xxx",
            "asset_issuer": "xxx",
        },
        {
            "balance": "xxx",
            "buying_liabilities": "xxx",
            "selling_liabilities": "xxx",
            "limit": "xxx",
            "asset_type": "native",
            "asset_code": "xxx",
            "asset_issuer": "xxx",
        }
    ]
}

Current Tags

  • 2.0.6                                ...           latest (a year ago)

16 Versions

  • 2.0.6 [deprecated]           ...           a year ago
  • 2.0.5 [deprecated]           ...           a year ago
  • 2.0.4 [deprecated]           ...           a year ago
  • 2.0.3 [deprecated]           ...           2 years ago
  • 2.0.2 [deprecated]           ...           2 years ago
  • 2.0.1 [deprecated]           ...           2 years ago
  • 2.0.0 [deprecated]           ...           2 years ago
  • 1.3.0 [deprecated]           ...           2 years ago
  • 1.2.0 [deprecated]           ...           2 years ago
  • 1.1.0 [deprecated]           ...           2 years ago
  • 1.0.5 [deprecated]           ...           2 years ago
  • 1.0.4 [deprecated]           ...           2 years ago
  • 1.0.3 [deprecated]           ...           2 years ago
  • 1.0.2 [deprecated]           ...           2 years ago
  • 1.0.1 [deprecated]           ...           2 years ago
  • 1.0.0 [deprecated]           ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |