dapp-network-js-nat-test
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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 } = 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

Dapp Network Client

Library for accessing DAPP Network services

Parameters

  • network string network
  • options object optional params (optional, default {})
    • options.endpoint string? dsp endpoint
    • options.dappservices string DAPP Services contract (optional, default "dappservices")
    • options.fetch Fetch fetch (optional, default global.fetch)

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
  • contract string contract account
  • scope string table scope
  • table string contract table
  • primary_key string table primary_key
  • options object optional params (optional, default {})
    • options.index_position number (optional, default 1)
    • options.json boolean?
    • options.key_type string?
    • options.lower_bound string?
    • options.upper_bound string?
    • options.table_key string?
    • options.encode_type string?
    • options.show_payer boolean?
    • options.limit number (optional, default 10)
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
  • contract string contract account
  • private_key string contract private key
  • action string contract action
  • payload any transaction payload
  • options (optional, default {})
  • time_to_live number transaction time to live before expiration (optional, default 3600)
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
  • contract string contract account
  • method string contract method
  • payload readfn.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
  • contract string contract account
  • options (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
  • uri string 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
  • uri string oracle query information
  • code string contract account name
  • action_name string contract action name to call oracle request
  • private_key string contract private key
  • options object optional params (optional, default {})
    • options.endpoint number? DSP endpoint for Oracel services
    • options.blocks_behind number How many blocks behind the head block to be used for TAPOS and expire in expire_second (optional, default 3)
    • options.expire_seconds number Expiration time for transaction (optional, default 30)
    • options.authorization_actor string Account name to authorize transaction (optional, default code)
    • options.authorization_permission string Permission to authorize transaction (optional, default active)
    • options.broadcast boolean Boolean to broadcast transaction to network or not (optional, default true)
    • options.sign boolean Boolean to sign transaction or not (optional, default true)
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
  • 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 set
    • options.upper_bound string? Filters results to return the first element that is greater than provided value in set
    • options.limit number Limit the result amount (optional, default 1500)
    • options.show_payer boolean Show Payer (optional, default false)
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_name
  • service string dsp service
  • provider string dsp account
  • options object optional params (optional, default {})
    • options.limit number Limit the result amount (optional, default 1500)
    • options.show_payer boolean Show Payer (optional, default false)
  • package string 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
  • scope string dsp account
  • 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 set
    • options.upper_bound string? Filters results to return the first element that is greater than provided value in set
    • options.limit number Limit the result amount (optional, default 10)
    • options.show_payer boolean Show Payer (optional, default false)
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
  • scope string dsp account
  • 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 set
    • options.upper_bound string? Filters results to return the first element that is greater than provided value in set
    • options.limit number Limit the result amount (optional, default 10)
    • options.show_payer boolean Show Payer (optional, default false)
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
  • scope string user account
  • 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 set
    • options.upper_bound string? Filters results to return the first element that is greater than provided value in set
    • options.limit number Limit the result amount (optional, default 10)
    • options.show_payer boolean Show Payer (optional, default false)
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
  • 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 set
    • options.upper_bound string? Filters results to return the first element that is greater than provided value in set
    • options.limit number Limit the result amount (optional, default 1500)
    • options.show_payer boolean Show Payer (optional, default false)
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
  • account string staker account
  • service string dsp service
  • options object optional params (optional, default {})
    • options.limit number Limit the result amount (optional, default 1500)
    • options.show_payer boolean Show Payer (optional, default false)
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
  • account string staker account
  • service string dsp service
  • provider string dsp provider
  • options object optional params (optional, default {})
    • options.limit number Limit the result amount (optional, default 1500)
    • options.show_payer boolean Show Payer (optional, default false)
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

  • network string network
  • options object optional params (optional, default {})
    • options.endpoint endpoint? dsp endpoint
    • options.fetch Fetch fetch (optional, default global.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
  • code string The name of the smart contract that controls the provided table
  • action_name string The name of the action to call on the smart contract
  • private_key string The private key used to sign the transaction
  • data object Data to pass to transaction
  • options object optional params (optional, default {})
    • options.endpoint number? Endpoint to post transaction to
    • options.blocks_behind number How many blocks behind the head block to be used for TAPOS and expire in expire_second (optional, default 3)
    • options.expire_seconds number Expiration time for transaction (optional, default 30)
    • options.authorization_actor string Account name to authorize transaction (optional, default code)
    • options.authorization_permission string Permission to authorize transaction (optional, default active)
    • options.broadcast boolean Boolean to broadcast transaction to network or not (optional, default true)
    • options.sign boolean Boolean to sign transaction or not (optional, default true)
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

  • network string network
  • options object optional params (optional, default {})
    • options.endpoint endpoint? dsp endpoint
    • options.fetch Fetch fetch (optional, default global.fetch)

Examples

const network = "kylin"
const endpoint = "https://kylin-dsp-2.liquidapps.io"
const client = new EosioClient(network, { endpoint, fetch })

get_table_rows

GET /v1/chain/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 table
  • scope string The account to which this data belongs
  • table string The name of the table to query
  • 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 set
    • options.upper_bound string? Filters results to return the first element that is greater than provided value in set
    • options.limit number Limit the result amount (optional, default 10)
    • options.show_payer boolean Show Payer (optional, default false)
    • options.json boolean JSON response (optional, default true)
    • options.index_position number Position of the index used (optional, default 1)
    • options.key_type string? Type of key specified by index_position (for example - uint64_t or name)
    • options.table_key string? Table Key
    • options.encode_type string? 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

GET /v1/chain/get_table_rows

Returns all objects containing rows from the specified table.

Parameters
  • code string The name of the smart contract that controls the provided table
  • scope string The account to which this data belongs
  • table string The name of the table to query
  • lower_bound_key string Key value to identify lower_bound object
  • 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 set
    • options.upper_bound string? Filters results to return the first element that is greater than provided value in set
    • options.limit number Limit the result amount per get_table_rows API request (optional, default 1500)
    • options.show_payer boolean Show Payer (optional, default false)
    • options.json boolean JSON response (optional, default true)
    • options.index_position number Position of the index used (optional, default 1)
    • options.key_type string? Type of key specified by index_position (for example - uint64_t or name)
    • options.table_key string? Table Key
    • options.encode_type string? Encode type
    • options.delay_ms number? 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

GET /v1/chain/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

Examples

await delay(100);

Returns Promise<void>

Readme

Keywords

none

Package Sidebar

Install

npm i dapp-network-js-nat-test

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

145 kB

Total Files

47

Last publish

Collaborators

  • natpdeveloper