Using JS LDK
Librty Dev Kit wraps up all the apis and utility codes needed to query blockchain data
Install the Librty Dev Kit for Javascript through npm.
npm i librty-dev-kit
const { LibrtyDevKit, NETWORK } = require("librty-dev-kit");
const librtyInstance = new LibrtyDevKit("LDKhack", NETWORK.POLYGON);
Note: "LDKhack" is the api key
Please use following enum types in api parameters to fetch data for the respective networks:
Name | Value |
---|---|
Polygon Mainnet | LDKNetworkType.polygon |
Ethereum Mainnet ( coming Soon ) | LDKNetworkType.ethereum |
Simulation ( Simulate response ) | LDKNetworkType.simulation |
Indexer is solely responsible for read only data and has 3 major divisions: token, nft & account. For an example if we are looking for token balance of a wallet for a particular token
const tokenBalance = librtyInstance.indexer.token.getTokenBalance("0xc2132d05d31c914a87c6611c10748aeb04b58e8f", "0x6fe489d80a48caf7472cd45f4258b9ffb5208e3c");
Under token the available functions are:
Function | Details |
---|---|
getTokenBalance(token, wallet) | Get the tokens available in a wallet |
getTokenInfo(token) | Get token name, ticker and other info. |
getNativeTokenBalance(wallet) | Get native token balance of a wallet. |
getTokenAllowance(token, wallet, spender) | Get token allowance approved by a wallet for a spender. |
token is the contract address of a particular token, wallet is the wallet address of a user and spender is the wallet address or contract address of the spender.
Under nft the available functions are:
Fuction | Details |
---|---|
getNFTDetails(token, tokenId) | Get detail of a particular NFT |
getCollectionInfo(token) | Get detail of a collection |
token is the contract address of a NFT contract and tokenId is the id of the particular nft token.
Under account the available functions are:
Function | Details |
---|---|
getTransactionDetails(hash) | Get transaction details of a given hash |
hash is the unique transaction hash of a particular transaction.
We understand working with blockchain is new and interacting with it is time consuming as well, we introduce an option to simulate the response of apis, this will help developers seamlessly integrate the SDK.
const { LibrtyDevKit, NETWORK, LDKResponseMapper } = require("librty-dev-kit");
const responseMapper = new LDKResponseMapper();
responseMapper.setTokenBalance({
"status": 1,
"message": "SUCCESS",
"data": "47099"
});
const librtyInstance = new LibrtyDevKit("api_key", NETWORK.SIMULATION, responseMapper);
const tokenBalance = librtyInstance.indexer.token.getTokenBalance("0xc2132d05d31c914a87c6611c10748aeb04b58e8f", "0x6fe489d80a48caf7472cd45f4258b9ffb5208e3c");
Last modified 24d ago