dcorejs-sdk
v3.0.3
Published
DcoreJS SDK.
Downloads
8
Readme
DCore SDK for JS
Set of APIs for accessing the DCore Blockchain. If you are looking for other platforms you can find info below.
Requirements
Installation
npm install --save rxjs
npm install --save dcorejs-sdk
Make sure you import reflect-metadata
in an entry class to your application, eg. import "reflect-metadata";
To enable debug logging you can use rxjs-spy
.
Usage
You can find example project with SDK usage here.
You can find developer documentation for latest release here.
Use DCoreSdk
to initialize the API.
The DCoreApi
provides different groups of APIs for accessing the blockchain and default configuration values.
The supported operations are located in ch.decent.sdk.model.operation
package, suffixed with Operation
eg. TransferOperation(...)
.
Use the BroadcastApi
to apply the operations to DCore or use appropriate methods in APIs.
Access api using rest
import "reflect-metadata";
import { DCoreSdk } from "dcorejs-sdk";
// create the API
const api = DCoreSdk.createForHttp({ baseUrl: "https://testnet.dcore.io/" })
// get account by name, resolves to account id '1.2.27'
const disposable = api.accountApi.get("public-account-9")
.subscribe((account) => console.log(account.id));
Access api using websocket.
We need to install some websocket library beforehand if we are not running in the browser.
Eg. npm install --save ws
import "reflect-metadata";
import { AssetFormatter, ChainObject, Credentials, DCoreSdk } from "dcorejs-sdk";
import { create } from "rxjs-spy";
import * as WebSocket from "ws";
// debug logging: init rxjs-spy and log all tags
const spy = create();
spy.log();
// create api for websocket
const api = DCoreSdk.createForWebSocket(() => new WebSocket("wss://testnet-socket.dcore.io/"));
// create account credentials
const credentials = new Credentials(ChainObject.parse("1.2.27"), "5Hxwqx6JJUBYWjQNt8DomTNJ6r6YK8wDJym4CMAH1zGctFyQtzt");
// send 1DCT to account id '1.2.28 (public-account-10)' with encrypted 'hello memo' memo
const disposable = api.accountApi.transfer(credentials, "public-account-10", AssetFormatter.DCT.amount(1), "hello memo")
.subscribe((confirmation) => console.log(confirmation.id));