sinqlaritytest
v0.0.17
Published
This is Test package of Triweb Genesis Private Limited
Readme
Sinqlarity Integration Guide
Backend Integration
Add sinqlarity to your project dependencies
With Yarn
yarn add sinqlarityor with NPM
npm install sinqlarityimport SinqlarityServer
With JavaScript
const { SinqlarityServer } = require('sinqlarity');or with TypeScript
import { SinqlarityServer } from 'sinqlarity';Use the projectId, sinqlarityKey and sinqlaritySecret you get from sinqlarity.com to create SinqlarityServer object
const sinqlarityServer = new SinqlarityServer(projectId, sinqlarityKey, sinqlaritySecret);Create a route for your client app and serve the below auth token for integration with Sinqlarity
const sinqlarityAuthToken = await sinqlarity.getAuthenticationToken();Example
const { SinqlarityServer } = require('sinqlarity');
const projectId = process.env.SINQLARITY_PROJECT_ID;
const sinqlarityKey = process.env.SINQLARITY_KEY;
const sinqlaritySecret = process.env.SINQLARITY_SECRET;
const sinqlarityServer = new SinqlarityServer(projectId, sinqlarityKey, sinqlaritySecret);
app.post('/gettokenfromownclient', async (req, res) => {
const sinqlarityAuthToken = await sinqlarityServer.getAuthenticationToken();
res.send({ status: 'success', sinqlarityAuthToken });
});How to change the expiry time of sinqlarityAuthToken
- By default, it expires in 60 minutes.
- You can set expiry in minutes.
- Call this method before "getAuthenticationToken"
- Below syntax will set the expiry to 10 minutes.
- Its not a mandatory method.
sinqlarityServer.setTokenExpiry(10);How to get token for testnet network type
- By default, it generates token for mainnet.
- You can call below method (i.e. enableTestnet()) to generate auth token for testnet.
- Call this method before "getAuthenticationToken"
- Its mandatory to generate auth token for testnet.
sinqlarityServer.enableTestnet();- If you want to switch between network in code and generate token for mainnet and testnet both
sinqlarityServer.enableTestnet();
<!-- Generate testnet token -->
sinqlarityServer.enableMainnet();
<!-- Generate mainnet token -->Client Integration
Add sinqlarity to your project dependencies
With Yarn
yarn add sinqlarityor with NPM
npm install sinqlarityimport SinqlarityClient and other required constants and enums Doc
With JavaScript
const { SinqlarityClient, CONTRACT, ENVIRONMENT, FUNCTION, NETWORK, EVENTS } = require('sinqlarity');or with TypeScript
import { SinqlarityClient, CONTRACT, ENVIRONMENT, FUNCTION, NETWORK, EVENTS } from 'sinqlarity';Create object of Sinqlarity client by passing the blockchain environment and sinqlarity Authentication token(For authentication token see SinqlarityServer)
const sinqlarityClient = new SinqlarityClient(ENVIRONMENT.EVM, 'Sinqlarity Token from own Backend');To call a method to execute any function of any contract Docs
const response = await sinqlarityClient.execute(
FUNCTION.AIRDROP_BULKAIRDROPERC20,
data,
CONTRACT.AIRDROP,
NETWORK.POLYGON,
);To call a method to read data from contract Docs
Example
const data = await sinqlarityClient.read(
FUNCTION.PIGGY_BANK_GETBALANCE,
{
address: '0xe756ed2510d30911d5B9Ab4BeC5f89A4536D2111',
},
CONTRACT.PIGGY_BANK,
NETWORK.POLYGON,
);Subscribe for events and stay tuned
You can subscribe for
Success: At then end of successful process finish, it will give you response with status.
sinqlarityClient.subscribe(EVENTS.SINQLARITY_SUCCESS, successHandler);Error: In case of Error in processing, it will give you response with status.
sinqlarityClient.subscribe(EVENTS.SINQLARITY_ERROR, errorHandler);Process: It will help you in tracking the whole process and you can share the alerts with your user
sinqlarityClient.subscribe(EVENTS.SINQLARITY_PROCESS_ALERT, processHandler);- The event will send data in below format
{
message: 'Step related message...',
currentStep: '1',
totalSteps: '10',
isImportantStep: false, // If you dont want to show all the messages then it is recommended to show messages with isImportantStep:true
isFinalStep: false,// If it is last step then this flag will be true
}To set a default environment for Sinqlarity Client
sinqlarityClient.setEnvironment(ENUMS.ENVIRONMENT.EVM);To set a custom wallet for Sinqlarity Client
sinqlarityClient.setCustomWallet(ENUMS.WALLET.METAMASK);To set a custom base url for Sinqlarity Client
sinqlarityClient.setBaseURL(baseURL);To change Sinqlarity Authentication token anytime during the process, you can get it from your backend and do like below
sinqlarityClient.setAuthenticationToken(jwt);To switch between network types (i.e. Testnet and Mainnet)
To switch to Testnet
sinqlarityClient.enableTestnet();To switch to Mainnet
sinqlarityClient.enableMainnet();