🎆OriginTrail DKG

Typed wrapper built around the OriginTrail DKG.js SDK. Learn more about what DKG is and how to use it for your own applications by reading the official docs.

Dev3 SDK exposes the wrapper for anyone to use and build on top of the OriginTrail DKG. Read below on how to start using the wrapper directly from the Dev3 SDK.

Requirements:

  • Installed Dev3 SDK inside the project

    • npm install dev3-sdk

  • OriginTrail Node connection (local, mainnet, or testnet)

  • Wallet funded with TRAC & NEURO tokens

Dev3 provides all its users with free to use OriginTrail node! Testnet Node running at http://dkg-testnet.dev3.sh . Mainnet Node running at http://dkg-mainnet.dev3.sh . Reach out to our discord channel and receive test TRAC & NEURO tokens for free.

Usage

import { DkgClient } from "dev3-sdk";
 
const dkg = new DkgClient({
    endpoint: 'https://dkg-testnet.dev3.sh',  // gateway node URI
    port: 8900,
    blockchain: {
        name: 'otp::testnet',
        publicKey: "public-key",   // wallet must be funded with TRAC tokens and native coins
        privateKey: "private-key", // in order to execute state changing transactions
    }
});

If initialized properly, the DKG object can be used to interact with the OriginTrail DKG!

Fetching Node Info

dkg.node.info().then((result) => {
    console.log("Node info result: ", result);
});

Creating Asset

const publicAssertion = {
    '@context': 'https://schema.org',
    '@id': 'https://tesla.modelX/2321',
    '@type': 'Car',
    'name': 'Tesla Model X',
    'brand': {
        '@type': 'Brand',
        'name': 'Tesla'
    },
    'model': 'Model X',
    'manufacturer': {
        '@type': 'Organization',
        'name': 'Tesla, Inc.'
    },
    'fuelType': 'Electric',
    'numberOfDoors': 5,
    'vehicleEngine': {
        '@type': 'EngineSpecification',
        'engineType': 'Electric motor',
        'enginePower': {
            '@type': 'QuantitativeValue',
            'value': '416',
            'unitCode': 'BHP'
        }
    },
    'driveWheelConfiguration': 'AWD',
    'speed': {
        '@type': 'QuantitativeValue',
        'value': '250',
        'unitCode': 'KMH'
    },
}

// write operation example (using pub/priv key of an operational wallet which is funded with native coins and TRAC tokens)
dkg.asset.create(publicAssertion, { epochsNum: 2 }).then((result) => {
    console.log("Asset created. Result: ", result);
});

Fetching Asset

// taken  for example from asset creation response
const assetUal = "<assset-ual>";

// read operation example
dkg.asset.get(assetUal).then((result) => {
    console.log("Asset fetched. Result: ", result);
});

Dev3 Widget Support

Dev3 Widget now supports DKG interactions natively! This means that if you omit the private/public keypair from the SDK initialization object, DKG interactions will be processed by the Dev3 widget.

To activate Dev3 Widget support for the project, simply:

  1. create the Dev3 Workspace

  2. install the dev3-sdk package ( npm install dev3-sdk )

  3. initialize the module inside your project:

import {Dev3SDK, DkgClient} from "dev3-sdk";

// Activate Dev3 Widget support
Dev3SDK.attach("dev3-workspace-api", "dev3-workspace-project-id"); // your Dev3 project data

window.DkgClient = new DkgClient({
    endpoint: 'http://otp-testnet.dev3.sh',  // gateway node URI
    port: 8900,
    blockchain: {
        name: 'otp::testnet',
        // publicKey: "", // operational wallet address
        // privateKey: "", // operational wallet priv key
    }
});

Quick App Prototyping

To start using the DKG and prototype your application, clone the Dev3 SDK repo and start working on our test project setup!

$ git clone https://github.com/0xdev3/dev3-sdk
$ cd dev3-sdk
$ npm install
$ npm run build
$ cd test/dkg-app
$ npm install
$ npm run build
$ npm start # starts the example dkg app at localhost:1234

The example repo GitHub link:

Last updated