Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Latest commit

 

History

History
178 lines (121 loc) · 4.31 KB

README.md

File metadata and controls

178 lines (121 loc) · 4.31 KB

LoyalX Javascript API

Javascript api to interface with LoyalX protocol.

Install

will be published soon to npm for now you can use our git repo

$ npm install git+https://github.com/LoyalX/LoyalX-JSAPI.git

Node Usage

import TruffleContract = require("truffle-contract");

var loyalx = new LoyalX(
    TruffleContract,
    LoyalX.SERVERS.PRODUCTION  // you can change to an other server here exm: LoyalX.SERVERS.LOCALHOST
);

You now have access to the following

Browser Usage ( builds coming soon )

minified version and non minified version will be avalble at Releases
In your head element, include Web3, truffle-contract then loyalx-jsapi:

<script type="text/javascript" src="web3.min.js"></script>
<script type="text/javascript" src="truffle-contract.min.js"></script>
<script type="text/javascript" src="loyalx-jsapi.min.js"></script>

Alternatively, you can use the non-minified versions for easier debugging.

With this usage, it will be available via the Loyalx object:

var loyalx = new LoyalX(...);

APIs

Token

var loyalx = new LoyalX(...);
var tokenAddress = "0xd69d78e1cf0729cad59080820c9931315aba7778",
var myToken = new loyalx.Token(tokenAddress);

to use our main token you can use

var loyalx = new LoyalX(...);
loyalx.LoyalXToken;

Token.transfer(amount, toAddress)

transfer tokens from the selected account to the recipient account

Param Type Description
amount number the amount to be transferred
toAddress address the recipient account address
var tokenAddress = "0xd69d78e1cf0729cad59080820c9931315aba7778",
    toAddress = "0xb3cc2d1bbe6b87edfcd3b4c1c394f35caf0593be",
    amount = 123;
var myToken = new loyalx.Token(tokenAddress);
myToken.transfer(amount, toAddress);

Token.getBalance()

get the balance of the selected user
return bignumber, for more reference check bignumber.js

var tokenAddress = "0xd69d78e1cf0729cad59080820c9931315aba7778";
var myToken = new loyalx.Token(tokenAddress);
var balance = await myToken.getBalance();

Token.getContractInstance()

get the truffle contract instance

Alternatively u can use:-

  • Token.getContract() to get the contract.
var tokenAddress = "0xd69d78e1cf0729cad59080820c9931315aba7778";
var myToken = new loyalx.Token(tokenAddress);
var contractInstance = await myToken.getContractInstance();

TokenFactory

var loyalx = new LoyalX(...);
loyalx.TokenFactory;

TokenFactory.initialiseRetail(symbol, name, amount, decimal)

deploy a new token contract instance.

Param Type Description
symbol string a short name usually 3 chars
name string reward point name
amount number total points in circulation
decimal number how many decimal point
var symbol = "tst",
    name = "test",
    amount = "1000000",
    decimal = 2;
var result = await loyalx.TokenFactory.initialiseRetail(symbol, name, amount, decimal);

TokenFactory.getTokens()

get all token's data.
return a promise with an array containing the tokens data.

Alternatively u can use:-

  • TokenFactory.getTokensAddress() to get only the addresses.
  • TokenFactory.getTokensByOwner() to get them by the selected user account
  • TokenFactory.getTokensAddressByOwner() to get only the addresses.
var tokensData = await loyalx.TokenFactory.getTokensAddress();
console.log(tokensData);
"TokensData" : [
    {
        "address": "0xd69d78e1cf0729cad59080820c9931315aba7778",
        "name": "test",
        "symbol": "tst",
        "decimal": 2
    },
    ...
];

TokenFactory.getContractInstance()

get the truffle contract instance

Alternatively u can use:-

  • TokenFactory.getContract() to get the contract.
var contractInstance = await loyalx.TokenFactory.getContractInstance();