Javascript api to interface with LoyalX protocol.
will be published soon to npm for now you can use our git repo
$ npm install git+https://github.com/LoyalX/LoyalX-JSAPI.git
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
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(...);
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;
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);
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();
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();
var loyalx = new LoyalX(...);
loyalx.TokenFactory;
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);
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 accountTokenFactory.getTokensAddressByOwner()
to get only the addresses.
var tokensData = await loyalx.TokenFactory.getTokensAddress();
console.log(tokensData);
"TokensData" : [
{
"address": "0xd69d78e1cf0729cad59080820c9931315aba7778",
"name": "test",
"symbol": "tst",
"decimal": 2
},
...
];
get the truffle contract instance
Alternatively u can use:-
TokenFactory.getContract()
to get the contract.
var contractInstance = await loyalx.TokenFactory.getContractInstance();