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)
import { DkgClient } from"dev3-sdk";constdkg=newDkgClient({ 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
constpublicAssertion= {'@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 responseconstassetUal="<assset-ual>";// read operation exampledkg.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:
To start using the DKG and prototype your application, clone the Dev3 SDK repo and start working on our test project setup!
$gitclonehttps://github.com/0xdev3/dev3-sdk$cddev3-sdk$npminstall$npmrunbuild$cdtest/dkg-app$npminstall$npmrunbuild$npmstart# starts the example dkg app at localhost:1234