@liquidapps/dapp-client

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.

Last updated