Quickstart with Node.js
Create your first Knowledge Asset on OriginTrail Decentralized Knowledge Graph using the DKG JavaScript SDK
🚀 Step 1: Set up your project and install the SDK
1.1 Create your project folder
Create a new folder on your computer named
OT-DKG-Quickstart
Open the folder in your code editor:
VS Code: File → Open Folder → Select
OT-DKG-Quickstart
Cursor: File → Open → Select
OT-DKG-Quickstart
1.2 Open a terminal in your project folder
VS Code: Right-click the folder in Explorer → "Open in Integrated Terminal"
Cursor: Click the folder → "Open Terminal Here"
1.3 Initialize project and install SDK
1.4 Set up your private key
Create a new file named
.env
in your project rootAdd your wallet's private key:
Note: Replace your_private_key_here
with your actual private key. Never share this file or commit it to version control!
How to get your private key from MetaMask:
Open MetaMask
Click the three dots menu
Select "Account Details"
Click "Export Private Key"
Enter your password and copy the key
📝 Step 2: Publish your first knowledge asset
A Knowledge Asset (KA) is structured data stored on the DKG. Let's create a simple one!
Example Knowledge Asset
Here's the JSON-LD KA we'll publish
JavaScript implementation
Create a new file named
publish_ka.mjs
in your project folderCopy and paste this code, replacing the content part with your custom values if you'd like (as described in the Example Knowledge Asset section above):
Run the script by entering the following into the terminal:
🔍 Step 3: Query & Retrieve Your Knowledge Asset
Now let's retrieve your published Knowledge Asset using a SPARQL query.
Create a new file in your project folder named
query_ka.mjs
, paste in the code below, and update the query name if you changed the name of the KA when creating it:
Run the query by entering the following into your terminal:
⚠️ Query Troubleshooting
If your query returns no results:
Check the name: Ensure the name in your SPARQL query exactly matches what you published
Wait a moment: Sometimes it takes a few seconds for the KA to be fully indexed
Verify publication: Check that your publish script completed successfully
Example: If you changed the name to "My Custom KA", update your query:
🎉 Congratulations!
You've successfully:
Published your first Knowledge Asset to the DKG
Created a verifiable, ownable asset that you control
Retrieved it using a SPARQL query
Learned the basics of the OriginTrail SDK
Your Knowledge Asset now lives on the DKG, where it's:
Owned by you - secured by your wallet
Verifiable - anyone can cryptographically verify you as the publisher
Discoverable - can be found by anyone while you maintain ownership
🚀 What's Next?
Now that you've mastered the basics, here's what comes next.
Everything you need to build with the DKG: publish and query knowledge, deploy autonomous AI agents, and launch decentralized knowledge ecosystems with paranets—all from a unified toolkit.
Take control of your stack: deploy agents, paranets, and private Knowledge Assets on your own infrastructure—fully customizable and privacy-first.
You’re now on the path to building a semantic, decentralized, and AI-ready knowledge ecosystem!
Last updated
Was this helpful?