Use DAPI Client Methods
Accessing DAPI client methods via the SDK
Overview
In addition to the SDK methods for interacting with identities, names, contracts, and documents, the SDK also provides direct access to DAPI client methods.
Prerequisites
- node.js (v12+)
- Basic familiarity with JavaScript asychronous functions using async/await
- The Dash JavaScript SDK is initialized (covered in Connect to a Network)
Code
The following example demonstrates several of the Core DAPI client methods. DAPI client also has several Platform methods accessible via getDAPIClient().platform.*
. The methods can be found here in the js-dapi-client repository.
const Dash = require('dash');
const client = new Dash.Client();
async function dapiClientMethods() {
console.log(await client.getDAPIClient().core.getBlockHash(1));
console.log(await client.getDAPIClient().core.getBestBlockHash());
console.log(await client.getDAPIClient().core.getBlockByHeight(1));
return client.getDAPIClient().core.getStatus();
}
dapiClientMethods()
.then((d) => console.log('Core status:\n', d))
.catch((e) => console.error('Something went wrong:\n', e))
.finally(() => client.disconnect());
Examples using DAPI client to access many of the DAPI endpoints can be found in the DAPI Endpoint Reference section.
Updated almost 3 years ago