Building tools for xcash using Node.js using TS
The tool covers:
Global API (includes DPOPS, Namespace and Xpayment Twitter)
Blockchain (xcash daemon and xcash wallet)
Most methods are included
Note you must use
node.js 18+
Typescript 4.0+
Run this inside your project directory
npm i git+https://github.com/X-CASH-official/XCASH-api-tools-ts.git
Add the import
import * as xcash from 'xcash';
Default Configuration (will use remote daemon and remote wallet)
const XCASH_DAEMON_ADDRESS:string = "";
const XCASH_WALLET_ADDRESS:string = "";
For example if you want to use a local xcash daemon and xcash wallet
Default Configuration (will use remote daemon and remote wallet)
const XCASH_DAEMON_ADDRESS:string = "127.0.0.1:18281";
const XCASH_WALLET_ADDRESS:string = "127.0.0.1:18285";
Initialize the settings
xcash.Initialize(XCASH_DAEMON_ADDRESS,XCASH_WALLET_ADDRESS);
Run the test
npm run test
The full request structure of each method can be found in here but they generally follow the request structure of the API
The full response structure of each request can be found in here
The example below calls one method from the global API, and one method from the Blockchain
import * as xcash from 'xcash';
const XCASH_DAEMON_ADDRESS:string = "127.0.0.1:18281";
const XCASH_WALLET_ADDRESS:string = "127.0.0.1:18285";
async function main() {
try {
await xcash.Initialize(XCASH_DAEMON_ADDRESS,XCASH_WALLET_ADDRESS);
const data:xcash.xcashInterfaces.BlockchainGetBlockCount = await xcash.Blockchain_get_block_count();
console.log(data.result.count); // prints 993163
console.log(JSON.stringify(data));
/* Prints out the following:
{
"id": "0",
"jsonrpc": "2.0",
"result": {
"count": 993163,
"status": "OK",
"untrusted": "false"
}
}
*/
const dataAPI:xcash.xcashInterfaces.APIBlockchainStats = await xcash.API_Blockchain_stats();
console.log(dataAPI.height); // prints 810000
console.log(JSON.stringify(dataAPI));
/* Prints out the following:
{
"height": 810000,
"hash":"c7aa6eb38c47e7f013a5f8042477d1734ff9808fdc8608fb088085d624d2d509",
"reward": 20000000,
"size": 20000,
"version": 13,
"versionBlockHeight": 1000000,
"nextVersionBlockHeight": 0,
"totalPublicTx": 100000,
"totalPrivateTx": 100000,
"circulatingSupply": 10000000,
"generatedSupply": 100000000,
"totalSupply": 100000000,
"emissionReward": 1000000000,
"emissionHeight": 1000000000,
"emissionTime": 1000000000,
"inflationHeight": 1000000000,
"inflationTime": 1000000000
}
*/
}
catch (error)
{
console.log(error);
}
}
main();