Skip to content

Official repository of the DCore SDK for JavaScript in the browser and Node.js

License

Notifications You must be signed in to change notification settings

DCTDAO/DCoreJS-SDK

 
 

Repository files navigation

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));

Official DCore SDKs for other platforms

About

Official repository of the DCore SDK for JavaScript in the browser and Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.9%
  • Other 0.1%