Dapp Client Library¶
The dapp-client library makes using DAPP Network services much easier. It also allows you to easily tap into the dappservices
(core DAPP Network Smart contract) and dappairhodl1
(Air-HODL smart contract) RAM tables with precision utilizing secondary and tertiary indices without the hassle.
To setup the library, first install it:
npm i -g @liquidapps/dapp-client
From there include the library’s client creator script:
const { createClient } = require('@liquidapps/dapp-client');
Then pass your desired arguments to the creator function
/*
* network: specify your network of choice: mainnet, kylin, jungle
* httpEndpoint: you may also specify an endpoint to use instead of our defaults
* fetch: pass a fetch reference as needed
// if using dfuse
* dfuse_key: Dfuse API key
* dfuse_guarantee: Dfuse Push Guarantee(in-block, handoff:1, handoffs:2, handoffs:3, irreversible)
* dfuse_network: Dfuse Network ( mainnet, testnet (eosio testnet), kylin, worbli, wax)
*/
export const getClient = async() => {
return await createClient({ network: "kylin", httpEndpoint: endpoint, fetch: window.fetch.bind(window) });
};
Finally, setup the service you would like to interact along with your smart contract name:
(async () => {
const service = await (await createClient()).service('ipfs','cardgame1112');
const response = await service.get_vram_row( "cardgame1112", "cardgame1112", "users", "nattests" );
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 } }
})().catch((e) => { console.log(e); });
Here is a full list of service options. The library comes with a push_guarantee function, similar to dfuse’s push guarantee, it accepts in-block
, handoffs:1-3
, or irreversible
. There are DAPP Network service extensions and dappservices
/ dappairhodl1
RAM row calls.
DAPP Network service extensions¶
Push Guarantee¶
Retry time between push guarantee verification can be set with the DAPP_CLIENT_PUSH_TRANSACTION_SLEEP
environment variable, defaults to 10ms.
const { PushGuarantee } = require("eosio-push-guarantee");
const { Api, JsonRpc, RpcError } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
const fetch = require('node-fetch'); // node only; not needed in browsers
const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder
const defaultPrivateKey = "5JMUyaQ4qw6Zt816B1kWJjgRA5cdEE6PhCb2BW45rU8GBEDa1RC"; // bob
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const rpc = new JsonRpc('https://kylin-dsp-2.liquidapps.io', { fetch });
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
(async () => {
const config = {
// pushGuarantee: 'none', // push guarantee level for trx
// readRetries: 0, // amount of times to try and verify trx before retrying trx
// pushRetries: 3, // amount of times to retry trx before failing
// backoff: 500, // time in ms between readRetries
// backoffExponent: 1.1 // multiplier backoff time for backoff (if 500ms and 1.1 multiplier then 550ms backoff next time, etc)
pushGuarantee: 'in-block',
readRetries: 3,
// pushGuarantee: 'handoffs:1',
// readRetries: 10,
// pushGuarantee: 'handoffs:2',
// readRetries: 20,
// pushGuarantee: 'handoffs:3',
// readRetries: 30,
pushGuarantee: 'irreversible',
readRetries: 100,
}
const push_guarantee_rpc = new PushGuarantee(rpc, config);
const account = 'dappservices';
const actor = 'vacctstst123';
const action = 'transfer';
const serializedTrx = await api.transact({
actions: [{
account,
name: action,
authorization: [{
actor,
permission: 'active',
}],
data: {
from: 'vacctstst123',
to: 'natdeveloper',
quantity: '1.0000 DAPP',
memo: ''
},
}]
}, {
blocksBehind: 3, // in-block
expireSeconds: 30, // in-block
// blocksBehind: 3, // handoffs
// expireSeconds: 90, // handoffs
// expireSeconds: 300, // irreversible
// useLastIrreversible: true, // irreversible,
broadcast: false
});
const response = await (await getClient()).dappNetwork.push_action(rpc, serializedTrx, config);
console.dir(result);
})().catch((e) => { console.log(e); });
vRAM - IPFS¶
get_vram_row - get vRAM row from DSP’s endpoint¶
/*
getClient()
* service name: ipfs
* contract name
service.get_vram_row - read vRAM table row from DSP's endpoint
* code - smart contract account
* scope - scope of table
* table - name of table
* primary key
*/
const service = await (await getClient()).service('ipfs','cardgame1112');
const response = await service.get_vram_row( "cardgame1112", "cardgame1112", "users", "nattests" );
LiquidAccounts¶
push_liquid_account_transaction - register new account¶
/*
getClient()
* service name: vaccounts
* contract name
service.push_liquid_account_transaction
* account name of contract with LiquidAcount code deployed
* private key of LiquidAccount
* action name: regaccount to register new account
* payload
* vaccount - name of LiquidAccount
*/
const service = await (await getClient()).service('vaccounts', "vacctstst123");
const response = await service.push_liquid_account_transaction(
"vacctstst123",
"5JMUyaQ4qw6Zt816B1kWJjgRA5cdEE6PhCb2BW45rU8GBEDa1RC",
"regaccount",
{
vaccount: 'testing126'
}
);
push_liquid_account_transaction - push transaction after creating account¶
/*
getClient()
* service name: vaccounts
* contract name
service.push_liquid_account_transaction
* account name of contract with LiquidAcount code deployed
* private key of LiquidAccount
* action name: hello
* payload
* any - payload must match struct outline in the smart contract
*/
const service = await (await getClient()).service('vaccounts', "vacctstst123");
const response = await service.push_liquid_account_transaction(
"vacctstst123",
"5JMUyaQ4qw6Zt816B1kWJjgRA5cdEE6PhCb2BW45rU8GBEDa1RC",
"hello",
{
vaccount: 'testing126'
}
);
dappservices¶
get_package_info - returns package info¶
/*
dappNetwork.get_package_info
* account name
* service name - service names are listed under the services section of the docs as the Contract name
*/
const response = await (await getClient()).dappNetwork.get_package_info( "cardgame1112", "accountless1" );
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
// }
get_table_accountext - returns entire accountext table¶
/*
dappNetwork.get_table_accountext
*/
const response = await (await getClient()).dappNetwork.get_table_accountext();
for (const row of response.rows) {
console.log(row);
// {
// id: 144,
// account: 'mailcontract',
// service: 'ipfsservice1',
// provider: 'heliosselene',
// quota: '9.9907 QUOTA',
// balance: '10.0000 DAPP',
// last_usage: '1564112241500',
// last_reward: '1564112241500',
// package: 'ipfs1',
// pending_package: 'ipfs1',
// package_started: '1564112241500',
// package_end: '1564112301500'
// }
}
get_table_accountext_by_account_service - returns entire accountext by account and service specified¶
/*
dappNetwork.get_table_accountext_by_account_service
* account name
* service name - service names are listed under the services section of the docs as the Contract name
*/
const response = await (await getClient()).dappNetwork.get_table_accountext_by_account_service('cardgame1112', 'ipfsservice1');
for (const row of response.rows) {
console.log(row);
// {
// id: 144,
// account: 'mailcontract',
// service: 'ipfsservice1',
// provider: 'heliosselene',
// quota: '9.9907 QUOTA',
// balance: '10.0000 DAPP',
// last_usage: '1564112241500',
// last_reward: '1564112241500',
// package: 'ipfs1',
// pending_package: 'ipfs1',
// package_started: '1564112241500',
// package_end: '1564112301500'
// }
}
get_table_accountext_by_account_service_provider - returns entire accountext by account, service, and provider specified¶
/*
dappNetwork.get_table_accountext_by_account_service_provider
* account name
* service name - service names are listed under the services section of the docs as the Contract name
* provider name - DSP name
*/
const response = await (await getClient()).dappNetwork.get_table_accountext_by_account_service_provider('cardgame1112', 'ipfsservice1','heliosselene');
for (const row of response.rows) {
console.log(row);
// {
// id: 144,
// account: 'mailcontract',
// service: 'ipfsservice1',
// provider: 'heliosselene',
// quota: '9.9907 QUOTA',
// balance: '10.0000 DAPP',
// last_usage: '1564112241500',
// last_reward: '1564112241500',
// package: 'ipfs1',
// pending_package: 'ipfs1',
// package_started: '1564112241500',
// package_end: '1564112301500'
// }
}
get_table_package - returns entire package table¶
/*
dappNetwork.get_table_package
* [limit] - optional limit for how many packages to return
*/
const response = await (await getClient()).dappNetwork.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 - returns packages by package, service, and DSP name¶
/*
dappNetwork.get_table_package_by_package_service_provider
* package name
* service name - service names are listed under the services section of the docs as the Contract name
* DSP name
* [limit] - optional limit for how many packages to return
*/
const response = await (await getClient()).dappNetwork.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_packagext - returns a packages selected inflation rate and quota cost for actions¶
/*
dappNetwork.get_table_packagext
* [limit] - optional limit for how many packages to return
*/
const response = await (await getClient()).dappNetwork.get_table_packagext({ limit: 500 });
for (const row of response.rows) {
console.log(row);
}
get_table_packagext_by_package_service_provider - returns DSP packagext entries that match the package and dsp service provided¶
/*
dappNetwork.get_table_packagext_by_package_service_provider
* package name
* service name - service names are listed under the services section of the docs as the Contract name
* DSP name
* [limit] - optional limit for how many packages to return
*/
const response = await (await getClient()).dappNetwork.get_table_packagext_by_package_service_provider('package1', 'ipfsservice1', 'heliosselene', { limit: 500 });
for (const row of response.rows) {
console.log(row);
}
get_table_refunds - returns refund table details for account name specified¶
/*
dappNetwork.get_table_refunds
* account name
*/
const response = await (await getClient()).dappNetwork.get_table_refunds('heliosselene');
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_table_staking - returns staking table details for account name specified¶
/*
dappNetwork.get_table_staking
* account name
*/
const response = await (await getClient()).dappNetwork.get_table_staking('cardgame1112');
for (const row of response.rows) {
console.log(row);
// {
// id: 0,
// account: 'cardgame1112',
// balance: '10.0000 DAPP',
// provider: 'uuddlrlrbass',
// service: 'accountless1'
// }
}
dappairhodl1¶
get_dapphdl_accounts - get an account’s DAPPHDL stats¶
/*
airhodl.get_dapphdl_accounts
* account name
*/
const response = await (await getClient()).airhodl.get_dapphdl_accounts('natdeveloper');
for (const row of response.rows) {
console.log(row);
// {
// balance: '0.0033 DAPPHDL',
// allocation: '0.0199 DAPPHDL',
// staked: '0.0000 DAPPHDL',
// claimed: 1
// }
}