DAPP Network JavaScript/TypeScript Client Library
Library for accessing DAPP Network services
Forked from EOS Nations's dapp-client-js: https://github.com/EOS-Nation/dapp-client-js LICENSE: https://github.com/EOS-Nation/dapp-client-js/blob/master/LICENSE
Installation
Using Yarn:
yarn add dapp-network-js
or using NPM:
npm install --save dapp-network-js
Quick Start
CommonJS
const DappClient = const fetch = const endpoint = "https://kylin-dsp-2.liquidapps.io"const network = "kylin" // mainnet, jungleconst client = network endpoint fetch
TypeScript
/src/network-config.json
Add additional networks to
API
Table of Contents
- DappClient
- Parameters
- Examples
- get_vram_row
- push_liquid_account_transaction
- push_readfn_transaction
- get_package_info
- return_oracle_uri_hex
- push_oracle_request_transaction
- get_table_package
- get_table_package_by_package_service_provider
- get_table_staking
- get_table_refunds
- get_dapphdl_accounts
- get_table_accountext
- get_table_accountext_by_account_service
- get_table_accountext_by_account_service_provider
- DAPP
- DAPPHDL
- EosjsClient
- EosioClient
- delay
DappClient
Dapp Network Client
Library for accessing DAPP Network services
Parameters
Examples
const endpoint = "https://kylin-dsp-2.liquidapps.io"const network = "kylin"const client = network endpoint fetch
get_vram_row
GET /v1/dsp/ipfsservice1/get_table_row
Get vRAM Row - returns get table row call for dapp::multi_index containers
Parameters
contract
string contract accountscope
string table scopetable
string contract tableprimary_key
string table primary_keyoptions
object optional params (optional, default{}
)
Examples
const response = await ; console; // { username: 'nattests', // win_count: 0, // lost_count: 0, // game_data: // { life_player: 5, // life_ai: 5, // deck_player: // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ], // deck_ai: // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ], // hand_player: [ 0, 0, 0, 0 ], // hand_ai: [ 0, 0, 0, 0 ], // selected_card_player: 0, // selected_card_ai: 0, // life_lost_player: 0, // life_lost_ai: 0, // status: 0 } }
push_liquid_account_transaction
POST /v1/dsp/accountless1/push_action
Push Liquid Account Transaction - creates and pushes LiquidAccount transaction
Parameters
contract
string contract accountprivate_key
string contract private keyaction
string contract actionpayload
any transaction payloadoptions
(optional, default{}
)time_to_live
number transaction time to live before expiration (optional, default3600
)
Examples
let response = await ; console;// { result:// { broadcast: true,// transaction:// { compression: 'none',// transaction: [Object],// signatures: [Array] },// transaction_id:// 'ef90712d7bfe7da325a5eb5545b13f1bb05ba1360753463645be96dce18858c2',// processed:// { id:// 'ef90712d7bfe7da325a5eb5545b13f1bb05ba1360753463645be96dce18858c2',// block_num: 60942620,// block_time: '2019-08-07T14:12:47.500',// producer_block_id: null,// receipt: [Object],// elapsed: 4414,// net_usage: 400,// scheduled: false,// action_traces: [Array],// account_ram_delta: null,// except: null,// error_code: null } } }
push_readfn_transaction
POST /v1/dsp/readfndspsvc/read
Push Readfn Transaction - creates and pushes ReadFN transaction
Parameters
contract
string contract accountmethod
string contract methodpayload
readfn.Payload transaction payload
Examples
let response = await ; console;// {// result: 'hello-123'// }
get_package_info
Get DSP Package Info - returns staked DSP package information for account specified
Parameters
contract
string contract accountoptions
(optional, default{}
)
Examples
const response = await client; console;// {// api: 'https://kylin-dsp-2.liquidapps.io',// package_json_uri: 'https://kylin-dsp-2.liquidapps.io/liquidaccts2.dsp-package.json',// package_id: 'liquidaccts2',// service: 'accountless1',// provider: 'heliosselene',// quota: '10.0000 QUOTA',// package_period: 60,// min_stake_quantity: '10.0000 DAPP',// min_unstake_period: 3600,// enabled: 0// }
return_oracle_uri_hex
Return Oracle URI hex - returns hex to be used as URI param to request DSP oracle response
Parameters
uri
string oracle query information
Examples
const response = await client; console; // <Buffer 68 74 74 70 73 2b 6a 73 6f 6e 3a 2f 2f 6e 61 6d 65 2f 61 70 69 2e 67 69 74 68 75 62 2e 63 6f 6d 2f 75 73 65 72 73 2f 74 6d 75 73 6b 61 6c>
push_oracle_request_transaction
Push Oracle Request Transactkon - pushes an oracle request transaction
Parameters
uri
string oracle query informationcode
string contract account nameaction_name
string contract action name to call oracle requestprivate_key
string contract private keyoptions
object optional params (optional, default{}
)options.endpoint
number? DSP endpoint for Oracel servicesoptions.blocks_behind
number How many blocks behind the head block to be used for TAPOS and expire inexpire_second
(optional, default3
)options.expire_seconds
number Expiration time for transaction (optional, default30
)options.authorization_actor
string Account name to authorize transaction (optional, defaultcode
)options.authorization_permission
string Permission to authorize transaction (optional, defaultactive
)options.broadcast
boolean Boolean to broadcast transaction to network or not (optional, defaulttrue
)options.sign
boolean Boolean to sign transaction or not (optional, defaulttrue
)
Examples
const response = await client; console;// { transaction_id:// '5578c5b726597d03f578f971dc67973f768742ee55623c4e48352b5a52f46cfd',// processed:// { id:// '5578c5b726597d03f578f971dc67973f768742ee55623c4e48352b5a52f46cfd',// block_num: 68590646,// block_time: '2019-09-23T16:26:03.500',// producer_block_id: null,// receipt:// { status: 'executed', cpu_usage_us: 424, net_usage_words: 21 },// elapsed: 424,// net_usage: 168,// scheduled: false,// action_traces: [ [Object] ],// account_ram_delta: null,// except: null,// error_code: null } }
Returns Promise<Any> transaction result
get_table_package
Get TABLE package - returns all DSP packages from the dappservices package table
Parameters
options
object optional params (optional, default{}
)options.lower_bound
string? Filters results to return the first element that is not less than provided value in setoptions.upper_bound
string? Filters results to return the first element that is greater than provided value in setoptions.limit
number Limit the result amount (optional, default1500
)options.show_payer
boolean Show Payer (optional, defaultfalse
)
Examples
const response = await client; for const row of responserows console; // { // id: 9, // api_endpoint: 'https://kylin-dsp-2.liquidapps.io', // package_json_uri: 'https://kylin-dsp-2.liquidapps.io/package1.dsp-package.json', // package_id: 'package1', // service: 'ipfsservice1', // provider: 'heliosselene', // quota: '1.0000 QUOTA', // package_period: 86400, // min_stake_quantity: '10.0000 DAPP', // min_unstake_period: 3600, // enabled: 1 // }
get_table_package_by_package_service_provider
Get TABLE package by package name and dsp service - returns DSP packages from the dappservices package table that match the package and dsp service provided
Parameters
package_name
service
string dsp serviceprovider
string dsp accountoptions
object optional params (optional, default{}
)package
string dsp package name
Examples
const response = await client; for const row of responserows console; // { // id: 9, // api_endpoint: 'https://kylin-dsp-2.liquidapps.io', // package_json_uri: 'https://kylin-dsp-2.liquidapps.io/package1.dsp-package.json', // package_id: 'package1', // service: 'ipfsservice1', // provider: 'heliosselene', // quota: '1.0000 QUOTA', // package_period: 86400, // min_stake_quantity: '10.0000 DAPP', // min_unstake_period: 3600, // enabled: 1 // }
get_table_staking
Get TABLE staking - returns staking information for specified account
Parameters
scope
string dsp accountoptions
object optional params (optional, default{}
)options.lower_bound
string? Filters results to return the first element that is not less than provided value in setoptions.upper_bound
string? Filters results to return the first element that is greater than provided value in setoptions.limit
number Limit the result amount (optional, default10
)options.show_payer
boolean Show Payer (optional, defaultfalse
)
Examples
const response = await client; for const row of responserows console; // { // id: 0, // account: 'heliosselene', // balance: '0.0000 DAPP', // provider: 'heliosselene', // service: 'ipfsservice1' // }
get_table_refunds
Get TABLE refunds - returns refund information for specified account
Parameters
scope
string dsp accountoptions
object optional params (optional, default{}
)options.lower_bound
string? Filters results to return the first element that is not less than provided value in setoptions.upper_bound
string? Filters results to return the first element that is greater than provided value in setoptions.limit
number Limit the result amount (optional, default10
)options.show_payer
boolean Show Payer (optional, defaultfalse
)
Examples
const response = await client; for const row of responserows console; // { // id: 0, // account: 'heliosselene', // amount: '10.0000 DAPP', // unstake_time: 12345678 // provider: 'heliosselene', // service: 'ipfsservice1' // }
get_dapphdl_accounts
Get TABLE accounts from dappairhodl1 contract - returns account information for DAPPHDL tokens
Parameters
scope
string user accountoptions
object optional params (optional, default{}
)options.lower_bound
string? Filters results to return the first element that is not less than provided value in setoptions.upper_bound
string? Filters results to return the first element that is greater than provided value in setoptions.limit
number Limit the result amount (optional, default10
)options.show_payer
boolean Show Payer (optional, defaultfalse
)
Examples
const response = await client; for const row of responserows console; // { // balance: '0.0000 DAPPHDL', // allocation: '0.0000 DAPPHDL', // staked: '0.0000 DAPPHDL', // claimed: false // }
get_table_accountext
Get TABLE accountext - returns all DSP package usage and stake information for all accounts
Parameters
options
object optional params (optional, default{}
)options.lower_bound
string? Filters results to return the first element that is not less than provided value in setoptions.upper_bound
string? Filters results to return the first element that is greater than provided value in setoptions.limit
number Limit the result amount (optional, default1500
)options.show_payer
boolean Show Payer (optional, defaultfalse
)
Examples
const response = await client; for const row of responserows console; // { // id: 29, // account: 'heliosselene', // service: 'ipfsservice1', // provider: 'heliosselene', // 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_table_accountext_by_account_service
Get TABLE accountext by account name and dsp service - returns all DSP package usage and stake information for accounts matching the account and dsp service provided
Parameters
account
string staker accountservice
string dsp serviceoptions
object optional params (optional, default{}
)
Examples
const response = await client; for const row of responserows console; // { // id: 29, // account: 'heliosselene', // service: 'ipfsservice1', // provider: 'heliosselene', // 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_table_accountext_by_account_service_provider
Get TABLE accountext by account name, DSP service, and DSP provider name - returns all DSP package usage and stake information for accounts matching the account and dsp service provided
Parameters
account
string staker accountservice
string dsp serviceprovider
string dsp provideroptions
object optional params (optional, default{}
)
Examples
const response = await client; for const row of responserows console; // { // id: 29, // account: 'heliosselene', // service: 'ipfsservice1', // provider: 'heliosselene', // 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' // }
DAPP
DAPP
Examples
namesDAPP // => "......2ke1.o4"
DAPPHDL
DAPPHDL
Examples
namesDAPPHDL // => ".1a4cm2ke1.o4"
EosjsClient
EOSJS Client
Parameters
network
string networkoptions
object optional params (optional, default{}
)options.endpoint
endpoint? dsp endpointoptions.fetch
Fetch fetch (optional, defaultglobal.fetch
)
Examples
const network = "kylin"const endpoint = "https://kylin-dsp-2.liquidapps.io"const client = network endpoint fetch
post_eosjs_transaction
POST /v1/chain/push_transaction
Pushes EOSJS transaction.
Parameters
code
string The name of the smart contract that controls the provided tableaction_name
string The name of the action to call on the smart contractprivate_key
string The private key used to sign the transactiondata
object Data to pass to transactionoptions
object optional params (optional, default{}
)options.endpoint
number? Endpoint to post transaction tooptions.blocks_behind
number How many blocks behind the head block to be used for TAPOS and expire inexpire_second
(optional, default3
)options.expire_seconds
number Expiration time for transaction (optional, default30
)options.authorization_actor
string Account name to authorize transaction (optional, defaultcode
)options.authorization_permission
string Permission to authorize transaction (optional, defaultactive
)options.broadcast
boolean Boolean to broadcast transaction to network or not (optional, defaulttrue
)options.sign
boolean Boolean to sign transaction or not (optional, defaulttrue
)
Examples
const response = await client;console;
Returns Promise<Any> transaction result
EosioClient
EOSIO Client
Parameters
network
string networkoptions
object optional params (optional, default{}
)options.endpoint
endpoint? dsp endpointoptions.fetch
Fetch fetch (optional, defaultglobal.fetch
)
Examples
const network = "kylin"const endpoint = "https://kylin-dsp-2.liquidapps.io"const client = network endpoint fetch
get_table_rows
Returns an object containing rows from the specified table.
Parameters
code
string The name of the smart contract that controls the provided tablescope
string The account to which this data belongstable
string The name of the table to queryoptions
object optional params (optional, default{}
)options.lower_bound
string? Filters results to return the first element that is not less than provided value in setoptions.upper_bound
string? Filters results to return the first element that is greater than provided value in setoptions.limit
number Limit the result amount (optional, default10
)options.show_payer
boolean Show Payer (optional, defaultfalse
)options.json
boolean JSON response (optional, defaulttrue
)options.index_position
number Position of the index used (optional, default1
)options.key_type
string? Type of key specified by index_position (for example - uint64_t or name)options.table_key
string? Table Keyoptions.encode_type
string? Encode type
Examples
const response = await rpc;console;
Returns Promise<GetTableRows> table rows
get_all_table_rows
Returns all objects containing rows from the specified table.
Parameters
code
string The name of the smart contract that controls the provided tablescope
string The account to which this data belongstable
string The name of the table to querylower_bound_key
string Key value to identifylower_bound
objectoptions
object optional params (optional, default{}
)options.lower_bound
string? Filters results to return the first element that is not less than provided value in setoptions.upper_bound
string? Filters results to return the first element that is greater than provided value in setoptions.limit
number Limit the result amount perget_table_rows
API request (optional, default1500
)options.show_payer
boolean Show Payer (optional, defaultfalse
)options.json
boolean JSON response (optional, defaulttrue
)options.index_position
number Position of the index used (optional, default1
)options.key_type
string? Type of key specified by index_position (for example - uint64_t or name)options.table_key
string? Table Keyoptions.encode_type
string? Encode typeoptions.delay_ms
number? Delay in ms between API calls (helps prevents rate limited APIs)
Examples
const response = await rpc;console;
Returns Promise<GetTableRows> table rows
get_info
Returns an object containing various details about the blockchain.
Examples
const response = await rpc;console;
Returns Promise<GetInfo> table rows
delay
Promise based timeout delay
Parameters
ms
number Milisecond delay
Examples
await ;
Returns Promise<void>