2.0.6 • Published 5 years ago

dragon-lotto-base-sdk v2.0.6

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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",
        }
    ]
}
2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago