Trusted AI for next generation RWAs with OriginTrail and Chainlink

OriginTrail
OriginTrail
Published in
5 min readMar 29, 2024

--

We are witnessing an important convergence of technologies of Artificial Intelligence (AI), Internet, and Crypto promising to reshape our digital landscape. This convergence enables a Verifiable Internet for AI, unlocking AI solutions without hallucinations and ensuring full respect for data ownership and Intellectual Property rights.

Trillion-dollar industries spanning from tokenization of real world assets (RWAs), supply chains, metaverse, construction, life sciences and healthcare, among others, require AI systems to use verifiable information to deliver the multiplication effect to the benefit of users in a safe manner.

A modular and collaborative approach is necessary to achieve that. OriginTrail and Chainlink are working together to bring the vision of the Verifiable Internet for AI to reality, allowing the transformation of real world asset (RWA) tokenization.

OriginTrail Decentralized Knowledge Graph (DKG) is already powering trusted AI solutions across multiple RWA industries, such as protecting whisky authenticity with trusted AI and DNA tagging techniques, helping Swiss Federal Railways increase rail travel safety with cross-border rail operator connectivity, increasing EU build environment sustainability with trusted AI, supporting representatives of over 40% of US imports to safeguard data on security audits for overseas factories, etc.

Expanding the OriginTrail decentralized AI framework with Chainlink oracle capability further extends the strength of RWA solutions by giving them access to real-time real world data. By synergizing the power of the Decentralized Knowledge Graph and Chainlink Data feeds, the capabilities of AI to retrieve verifiable information on RWAs can be applied across any domain.

Integrating Chainlink Data Feeds with OriginTrail DKG to create a Trusted AI solution

Each knowledge resource on the OriginTrail DKG is created as a Knowledge Asset consisting of knowledge content, cryptographic proofs for immutability, and NFT for ownership. For our example, we will create a Knowledge Asset for Chainlink Data Feed. Once created, Knowledge Assets can be used in decentralized Retrieval-Augmented Generation (dRAG) AI applications. For our showcase, we will use an existing DOT/USD data feed in an AI application using the DKG and dRAG in 3 simple steps.

Step 1: Create a Knowledge Asset on the DKG

Since we wish to retrieve DOT/USD data feed in our AI application, we need to start by creating a Knowledge Asset linking to the data feed which we will use to retrieve the live price:

{
"@context": "http://schema.org/",
"@type": "ChainlinkDataFeed",
"@id": "https://data.chain.link/feeds/moonbeam/mainnet/dot-usd",
"description": "Chainlink DataFeed providing real-time DOT/USD price information on the Moonbeam network.",
"baseAsset": {
"@id": "urn:chainlink:base-asset:dot",
"@type": "ChainlinkBaseAsset",
"name": "DOT_CR",
"description": "Polkadot cryptocurrency (DOT)"
},
"quoteAsset": {
"@id": "urn:chainlink:quote-asset:usd",
"@type": "ChainlinkQuoteAsset",
"name": "USD_FX",
"description": "United States Dollar (USD)"
},
"productType": "price",
"productSubType": "reference",
"productName": "DOT/USD-RefPrice-DF-Moonbeam-001",
"contractAddress": "0x1466b4bD0C4B6B8e1164991909961e0EE6a66d8c",
"network": "moonbeam",
"rpcProvider": "https://rpc.api.moonbeam.network"
}

The main entities represented in the Knowledge Asset are:

  • Base asset (DOT_CR) — the first asset listed in a trading pair, this is the asset that is being priced
  • Quote asset (USD_FX) — the second asset listed in a trading pair, this is the currency the base asset is priced in

Necessary fields for DOT/USD value retrieval:

  • Contract address (contractAddress)
  • RPC Provider (rpcProvider)

This Knowledge Asset content can also be visualized in the DKG Explorer:

Step 2: Use AI to query the DKG

From your application, you can use an LLM to generate DKG queries based on the user prompts. This step can have different degrees of complexity, so for this showcase, we will use the selected LLM to:

  • Determine if the prompt is relevant for the data feed (in our case, is the user’s question mentioning DOT token)
  • Use the LLM to structure a SPARQL query for the OriginTrail DKG to retrieve the Data Feed URL

An example of an engineered prompt to determine the relevance of the question for DOT token:

Given that the chatbot primarily responds to inquiries about the Polkadot ecosystem, including its native token, DOT, analyze the provided question to determine if there's a direct or indirect reference to DOT. Provide a response indicating 'true' if the question pertains to the value, function, or any aspect of DOT, within the context of discussions related to Polkadot ecosystem, either explicitly or implicitly, and 'false' if it does not. Question: {question}

If the above prompt determines the question as relevant (returns true), we proceed with a SPARQL query for the OriginTrail Decentralized Knowledge Graph. There are various techniques to obtain a SPARQL query with the LLM you’re using. In our case, we seek ChainlinkDataFeed type entities (Knowledge Assets) with DOT as the BaseAsset. The query result in our case will be a single Knowledge Asset containing information about the DOT/USD value. The SPARQL query should look like this:

PREFIX schema: <http://schema.org/>
SELECT ?dataFeed ?contractAddress ?rpcProvider
WHERE {
?dataFeed a schema:ChainlinkDataFeed ;
schema:baseAsset ?baseAsset ;
schema:contractAddress ?contractAddress ;
schema:rpcProvider ?rpcProvider .
?baseAsset a schema:ChainlinkBaseAsset ;
schema:name "DOT_CR" .
}

Step 3: Retrieve the data and display it in your application

Retrieve all the necessary information from the Knowledge Assets obtained through the SPARQL query. Essential information includes the contract address and RPC endpoint, as they are required to execute the code fetching price information from Chainlink. In our case, we are fetching the DOT/USD price.

Code execution

The following code uses ethers.js to fetch the requested value from the retrieved Data Feed. Here’s a simple example:

const { ethers } = require('ethers');

//Your code that executes SPARQL queries.

const rpcProvider = sparqlResult.data[0].rpcProvider;
const contractAddress = sparqlResult.data[0].contractAddress;

const provider = new ethers.providers.JsonRpcProvider(rpcProvider);
const abi = [{
inputs: [],
name: "latestRoundData",
outputs: [
{ internalType: "uint80", name: "roundId", type: "uint80" },
{ internalType: "int256", name: "answer", type: "int256" },
{ internalType: "uint256", name: "startedAt", type: "uint256" },
{ internalType: "uint256", name: "updatedAt", type: "uint256" },
{ internalType: "uint80", name: "answeredInRound", type: "uint80" },
],
stateMutability: "view",
type: "function",
}
];
async function getDOTUSDPrice() {
const contract = new ethers.Contract(contractAddress, abi, provider);
const [ , price] = await contract.latestRoundData();

console.log(`DOT/USD Price: ${ethers.utils.formatUnits(price, 8)}`);
}
getDOTUSDPrice();

Include Chainlink Data feed into the final response

You can modify how the LLM will perform the decentralized Retrieval Augmented Generation and include the data feed as a part of the response by engineering the prompt based on your requirements. Here’s one example that appends it at the end of the generated response.

The next generation RWA solutions will be using the best of what the Internet, Crypto and AI have to offer. Combining the power of OriginTrail DKG and Chainlink unlocks avenues of value in the RWA industries that can disrupt the way those industries operate today. Your path to disrupting the trillion dollar industries can start with the 3 steps shown above. Join us in Discord to let us know how OriginTrail and Chainlink can boost your solution with trusted AI.

Build transformative AI solutions on OriginTrail by diving into ChatDKG.ai and joining our Inception program today.

--

--

OriginTrail
OriginTrail

OriginTrail is the Decentralized Knowledge Graph that organizes AI-grade knowledge assets, making them discoverable & verifiable for sustainable global economy.