dapp-client v0.8.2
DAPP JavaScript/TypeScript Client Library
General purpose library for the DAPP network
Installation
Using Yarn:
yarn add dapp-clientor using NPM:
npm install --save dapp-clientQuick Start
CommonJS
const { DappClient } = require("dapp-client")
const fetch = require("isomorphic-fetch")
const endpoint = "https://dsp.eosn.io"
const client = new DappClient(endpoint, { fetch })TypeScript
import { DappClient } from "dapp-client"
import fetch from "isomorphic-fetch"
const endpoint = "https://dsp.eosn.io"
const client = new DappClient(endpoint, { fetch })Supported Endpoints
# Chain
/v1/chain/get_currency_stats
/v1/chain/get_info
/v1/chain/get_table_by_scope
/v1/chain/get_table_rows
# DSP
/v1/dsp/ipfsservice1/get_table_rowAPI
Table of Contents
DappClient
DAPP Client
General purpose library for the DAPP network.
Parameters
endpointstring dsp endpointoptionsobject optional params (optional, default{})options.dappservicesstring DAPP Services contract (optional, default"dappservices")options.ipfsservice1string IPFS Services contract (optional, default"ipfsservice1")options.oracleservicstring Oracle Services contract (optional, default"oracleservic")options.cronservicesstring Cron Services contract (optional, default"cronservices")options.fetchFetch fetch (optional, defaultglobal.fetch)
Examples
const endpoint = "https://dsp.eosn.io"
const client = new DappClient(endpoint, { fetch })get_table_package
Get TABLE package
Parameters
optionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount (optional, default10)options.show_payerboolean Show Payer (optional, defaultfalse)
Examples
const response = await client.get_table_package({limit: 500});
for (const row of response.rows) {
console.log(row);
// {
// id: 9,
// api_endpoint: 'https://dsp.eosn.io',
// package_json_uri: 'https://eosnation.io/package1.dsp-package.json',
// package_id: 'package1',
// service: 'ipfsservice1',
// provider: 'eosnationdsp',
// quota: '500.0000 QUOTA',
// package_period: 86400,
// min_stake_quantity: '10000.0000 DAPP',
// min_unstake_period: 3600,
// enabled: 1
// }
}get_table_staking
Get TABLE staking
Parameters
scopestring dsp accountoptionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount (optional, default10)options.show_payerboolean Show Payer (optional, defaultfalse)
Examples
const response = await client.get_table_staking('eosnationdsp', {limit: 500});
for (const row of response.rows) {
console.log(row);
// {
// id: 0,
// account: 'eosnationdsp',
// balance: '0.0000 DAPP',
// provider: 'eosnationdsp',
// service: 'ipfsservice1'
// }
}get_table_refunds
Get TABLE refunds
Parameters
scopestring dsp accountoptionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount (optional, default10)options.show_payerboolean Show Payer (optional, defaultfalse)
Examples
const response = await client.get_table_refunds('eosnationdsp', {limit: 500});
for (const row of response.rows) {
console.log(row);
// {
// id: 0,
// account: 'eosnationdsp',
// amount: '10.0000 DAPP',
// unstake_time: 12345678
// provider: 'eosnationdsp',
// service: 'ipfsservice1'
// }
}get_table_accountext
Get TABLE accountext
Parameters
optionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount (optional, default10)options.show_payerboolean Show Payer (optional, defaultfalse)
Examples
const response = await client.get_table_accountext({limit: 500});
for (const row of response.rows) {
console.log(row);
// {
// id: 29,
// account: 'eosnationdsp',
// service: 'ipfsservice1',
// provider: 'eosnationdsp',
// quota: '0.0001 QUOTA',
// balance: '255101.1461 DAPP',
// last_usage: '1555466031000',
// last_reward: '1555466031000',
// package: 'package2',
// pending_package: 'package2',
// package_started: '1555466031000',
// package_end: '1555469631000'
// }
}get_dapphdl_accounts
Get TABLE accounts from dappairhodl1 contract
Parameters
scopestring user accountoptionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount (optional, default10)options.show_payerboolean Show Payer (optional, defaultfalse)
Examples
const response = await client.get_dapphdl_accounts('eosnationdsp', {limit: 500});
for (const row of response.rows) {
console.log(row);
// {
// balance: '0.0000 DAPPHDL',
// allocation: '0.0000 DAPPHDL',
// staked: '0.0000 DAPPHDL',
// claimed: false
// }
}dsp_ipfs_get_table_row
GET /v1/dsp/ipfsservice1/get_table_row
Returns an object containing row from the specified table.
Parameters
contractstring The name of the smart contract that controls the provided tablescopestring The account to which this data belongstablestring The name of the table to querykeystring The key value to queryoptionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount (optional, default10)options.show_payerboolean Show Payer (optional, defaultfalse)options.jsonboolean JSON response (optional, defaulttrue)options.index_positionnumber Position of the index used (optional, default1)options.key_typestring? Type of key specified by index_position (for example - uint64_t or name)options.table_keystring? Table Keyoptions.encode_typestring? Encode type
Examples
const response = await rpc.dsp_ipfs_get_table_row("<contract>", "<scope>", "<table>", "<key>");
console.log(response);Returns Promise<GetTableRows> table rows
DAPP
DAPP
Examples
import { names } from "dapp-client"
names.DAPP // => "......2ke1.o4"DAPPHDL
DAPPHDL
Examples
import { names } from "dapp-client"
names.DAPPHDL // => ".1a4cm2ke1.o4"EosioClient
EOSIO Client
Parameters
endpointstring dsp endpointoptionsobject optional params (optional, default{})options.fetchFetch fetch (optional, defaultglobal.fetch)
Examples
const endpoint = "https://api.eosn.io"
const client = new EosioClient(endpoint, { fetch })get_table_rows
Returns an object containing rows from the specified table.
Parameters
codestring The name of the smart contract that controls the provided tablescopestring The account to which this data belongstablestring The name of the table to queryoptionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount (optional, default10)options.show_payerboolean Show Payer (optional, defaultfalse)options.jsonboolean JSON response (optional, defaulttrue)options.index_positionnumber Position of the index used (optional, default1)options.key_typestring? Type of key specified by index_position (for example - uint64_t or name)options.table_keystring? Table Keyoptions.encode_typestring? Encode type
Examples
const response = await rpc.get_table_rows("<code>", "<scope>", "<table>");
console.log(response);Returns Promise<GetTableRows> table rows
get_all_table_rows
Returns all objects containing rows from the specified table.
Parameters
codestring The name of the smart contract that controls the provided tablescopestring The account to which this data belongstablestring The name of the table to querylower_bound_keystring Key value to identifylower_boundobjectoptionsobject optional params (optional, default{})options.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber Limit the result amount perget_table_rowsAPI request (optional, default1500)options.show_payerboolean Show Payer (optional, defaultfalse)options.jsonboolean JSON response (optional, defaulttrue)options.index_positionnumber Position of the index used (optional, default1)options.key_typestring? Type of key specified by index_position (for example - uint64_t or name)options.table_keystring? Table Keyoptions.encode_typestring? Encode typeoptions.delay_msnumber? Delay in ms between API calls (helps prevents rate limited APIs)
Examples
const response = await rpc.get_all_table_rows("<code>", "<scope>", "<table>", "<lower_bound_key>");
console.log(response);Returns Promise<GetTableRows> table rows
get_table_by_scope
GET /v1/chain/get_table_by_scope
Returns an object containing rows from the specified table.
Parameters
codestring name of the contract to return table data foroptionsobject optional params (optional, default{})options.tablestring? Filter results by tableoptions.lower_boundstring? Filters results to return the first element that is not less than provided value in setoptions.upper_boundstring? Filters results to return the first element that is greater than provided value in setoptions.limitnumber? Limit number of results returned.options.reverseboolean Reverse the order of returned results (optional, defaultfalse)
Examples
const response = await rpc.get_table_by_scope();
console.log(response);Returns Promise<GetTableByScope> table rows
get_currency_balance
GET /v1/chain/get_currency_balance
Retrieve the stats of for a given currency
Parameters
codestring The contract that operates the currencyaccountstring The account to query balances forsymbolstring The symbol for the currency if the contract operates multiple currencies
Examples
const response = await rpc.get_currency_balance("eosio.token", "eosio.null", "EOS");
console.log(response);Returns Promise<GetCurrencyBalance> table rows
get_currency_stats
GET /v1/chain/get_currency_stats
Retrieve the stats of for a given currency
Parameters
codestring The contract that operates the currencysymbolstring The symbol for the currency if the contract operates multiple currencies
Examples
const response = await rpc.get_currency_stats("eosio.token", "EOS");
console.log(response);Returns Promise<GetCurrencyStats> table rows
get_info
Returns an object containing various details about the blockchain.
Examples
const response = await rpc.get_info();
console.log(response);Returns Promise<GetInfo> table rows
delay
Promise based timeout delay
Parameters
msnumber Milisecond delay
Examples
await delay(100);Returns Promise<void>