dapp-network-js-nat-test v1.0.1
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-jsor using NPM:
npm install --save dapp-network-jsQuick Start
CommonJS
const { DappClient } = require("dapp-client")
const fetch = require("isomorphic-fetch")
const endpoint = "https://kylin-dsp-2.liquidapps.io"
const network = "kylin" // mainnet, jungle
const client = new DappClient(network, { endpoint, fetch })TypeScript
import { DappClient } from "dapp-client"
import fetch from "isomorphic-fetch"
const endpoint = "https://kylin-dsp-2.liquidapps.io"
const network = "kylin" // mainnet, jungle
const client = new DappClient(network, { endpoint, fetch })Add additional networks to /src/network-config.json
{
"networks": {
"mainnet": "https://nodes.get-scatter.com:443",
"kylin": "https://kylin-dsp-2.liquidapps.io",
"jungle": "https://jungle2.cryptolions.io:443"
}
}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 = new DappClient(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
contractstring contract accountscopestring table scopetablestring contract tableprimary_keystring table primary_keyoptionsobject optional params (optional, default{})
Examples
const response = await get_vram_row(
"cardgame1112",
"cardgame1112",
"users",
"nattests",
"kylin",
);
console.log(response);
// { 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
contractstring contract accountprivate_keystring contract private keyactionstring contract actionpayloadany transaction payloadoptions(optional, default{})time_to_livenumber transaction time to live before expiration (optional, default3600)
Examples
let response = await push_liquid_account_transaction(
"vacctstst123",
"5JMUyaQ4qw6Zt816B1kWJjgRA5cdEE6PhCb2BW45rU8GBEDa1RC",
"hello",
{
vaccount: 'testing124',
b: 1,
c: 2
},
"kylin",
);
console.log( response );
// { 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
contractstring contract accountmethodstring contract methodpayloadreadfn.Payload transaction payload
Examples
let response = await push_readfn_transaction(
"1pointeight1",
"readtest",
{
testnum: 123
},
"kylin",
);
console.log( response );
// {
// result: 'hello-123'
// }get_package_info
Get DSP Package Info - returns staked DSP package information for account specified
Parameters
contractstring contract accountoptions(optional, default{})
Examples
const response = await client.get_package_info( 'cardgame1112' );
console.log( response );
// {
// 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
uristring oracle query information
Examples
const response = await client.return_oracle_uri_hex( "https+json://name/api.github.com/users/tmuskal" );
console.log( response );
// <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
uristring oracle query informationcodestring contract account nameaction_namestring contract action name to call oracle requestprivate_keystring contract private keyoptionsobject optional params (optional, default{})options.endpointnumber? DSP endpoint for Oracel servicesoptions.blocks_behindnumber How many blocks behind the head block to be used for TAPOS and expire inexpire_second(optional, default3)options.expire_secondsnumber Expiration time for transaction (optional, default30)options.authorization_actorstring Account name to authorize transaction (optional, defaultcode)options.authorization_permissionstring Permission to authorize transaction (optional, defaultactive)options.broadcastboolean Boolean to broadcast transaction to network or not (optional, defaulttrue)options.signboolean Boolean to sign transaction or not (optional, defaulttrue)
Examples
const response = await client.push_oracle_request_transaction( "https+json://USD/min-api.cryptocompare.com/data/price?fsym=EOS&tsyms=USD", "newtest12345", "testrnd", process.env.ORACLE_PRIVATE_KEY,
{
endpoint: "https://kylin-dsp-2.liquidapps.io"
}
);
console.log( response );
// { 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
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, default1500)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://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_nameservicestring dsp serviceproviderstring dsp accountoptionsobject optional params (optional, default{})packagestring dsp package name
Examples
const response = await client.get_table_package_by_package_service_provider('package1', 'ipfsservice1', 'heliosselene' { limit: 500 });
for (const row of response.rows) {
console.log(row);
// {
// 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
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('heliosselene', { limit: 500 });
for (const row of response.rows) {
console.log(row);
// {
// 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
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('heliosselene', {limit: 500});
for (const row of response.rows) {
console.log(row);
// {
// 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
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('heliosselene', {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
// }
}get_table_accountext
Get TABLE accountext - returns all DSP package usage and stake information for all accounts
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, default1500)options.show_payerboolean Show Payer (optional, defaultfalse)
Examples
const response = await client.get_table_accountext();
for (const row of response.rows) {
console.log(row);
// {
// 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
accountstring staker accountservicestring dsp serviceoptionsobject optional params (optional, default{})
Examples
const response = await client.get_table_accountext_by_account_service('cardgame1112', 'ipfsservice1');
for (const row of response.rows) {
console.log(row);
// {
// 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
accountstring staker accountservicestring dsp serviceproviderstring dsp provideroptionsobject optional params (optional, default{})
Examples
const response = await client.get_table_accountext_by_account_service('cardgame1112', 'ipfsservice1', 'heliosselene');
for (const row of response.rows) {
console.log(row);
// {
// 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
import { names } from "dapp-client"
names.DAPP // => "......2ke1.o4"DAPPHDL
DAPPHDL
Examples
import { names } from "dapp-client"
names.DAPPHDL // => ".1a4cm2ke1.o4"EosjsClient
EOSJS Client
Parameters
networkstring networkoptionsobject optional params (optional, default{})options.endpointendpoint? dsp endpointoptions.fetchFetch fetch (optional, defaultglobal.fetch)
Examples
const network = "kylin"
const endpoint = "https://kylin-dsp-2.liquidapps.io"
const client = new EosjsClient(network, { endpoint, fetch })post_eosjs_transaction
POST /v1/chain/push_transaction
Pushes EOSJS transaction.
Parameters
codestring The name of the smart contract that controls the provided tableaction_namestring The name of the action to call on the smart contractprivate_keystring The private key used to sign the transactiondataobject Data to pass to transactionoptionsobject optional params (optional, default{})options.endpointnumber? Endpoint to post transaction tooptions.blocks_behindnumber How many blocks behind the head block to be used for TAPOS and expire inexpire_second(optional, default3)options.expire_secondsnumber Expiration time for transaction (optional, default30)options.authorization_actorstring Account name to authorize transaction (optional, defaultcode)options.authorization_permissionstring Permission to authorize transaction (optional, defaultactive)options.broadcastboolean Boolean to broadcast transaction to network or not (optional, defaulttrue)options.signboolean Boolean to sign transaction or not (optional, defaulttrue)
Examples
const response = await client.post_eosjs_transaction( "newtest12345", "testrnd", process.env.PRIVATE_KEY, { uri: <Buffer 68 74 74 ... > } );
console.log(response);Returns Promise<Any> transaction result
EosioClient
EOSIO Client
Parameters
networkstring networkoptionsobject optional params (optional, default{})options.endpointendpoint? dsp endpointoptions.fetchFetch fetch (optional, defaultglobal.fetch)
Examples
const network = "kylin"
const endpoint = "https://kylin-dsp-2.liquidapps.io"
const client = new EosioClient(network, { 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_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>