Example

To help you better understand how a Dapp - ADCS works, let’s dive into the following example together Meme Coin Trend Application.

The Meme Coin Trend application leverages advanced AI and blockchain technology to track trending meme coins and analyze market data in real time, helping users make informed buy or sell decisions. By integrating Onchain AI Agents, the app offers decentralized, secure, and transparent insights, empowering users to navigate the fast-paced meme coin market with accuracy and efficiency.

Step-by-step guide on how to approach building the application

1. Adapter Definition:

You need to define an adapter that outlines the necessary parameters.

  • Name (String): Meme Coin Trend.

  • Description(String): Get a trending meme coin and make decisions for buying or selling

  • Category ID(AI): 2.

  • Output Type ID(StringAndBool): 4

  • Network: Rivalz

Based on the ADCS Reputation System, data providers are categorized into different levels. This allows you to select a provider according to your specific preferences and trust requirements.

Once an adaptor is created, the system will generate a unique JobID.

2. Setup Your Consumer Contract:

Depending on the type of outputData you have defined in the adaptor, your consumer contract must inherit from the appropriate ADCS fulfillment contract. Here the outputData is StringandBool so the consumer contract will inherit the ADCSConsumerFulfillStringAndBool.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "../ADCSConsumerFulfill.sol";
contract MockADCSConsumer is ADCSConsumerFulfillStringAndBool{ }

Contract Variables:

This public state variable store the last piece of data that was fulfilled by the oracles in response to a consumer request.

StringAndBool public lastestMemeCoin;

Constructor:

constructor(address _coordinator) ADCSConsumerBase(_coordinator) {}

The constructor takes the Coordinator contract's address (_coordinator) as input and passes it to the base contract. The Coordinator manages the interaction between oracles and consumers, facilitating the flow of data requests and responses.

Different Coordinator contract addresses are provided, each tailored to handle a specific output type, such as uint256, bool, or bytes. This allows consumers to interact with oracles in a way that matches the data type of the responses they expect.

Request Functions:

function requestMemeData(
        uint32 _callbackGasLimit,
       bytes32 _jobId
   ) external returns (uint256 requestId) {
        ADCS.Request memory req = buildRequest(
            _jobId,
            keccak256(abi.encodePacked("stringAndbool"))
        );
        requestId = COORDINATOR.requestData(_callbackGasLimit, req);
        emit DataRequestedBytes(requestId);
    }

This function requests :

  • _callbackGasLimit: The maximum amount of gas a user is willing to pay for completing the function.

  • _jobId: The jobID that the consuming contract is registered to.

  • The function uses the buildRequest() function to create a request, adds the necessary parameters, and sends it to the Coordinator.

Fulfillment Functions:

function fulfillDataRequest(uint256, StringAndBool memory response) internal virtual override {
      lastestMemeCoin = response;
   }

This function is called by the Coordinator contract to fulfill the data requests once getting the result.

3. Deploy the consumer contract

After defining all necessary functions, the global state, and the Coordinator contract for your consumer contract, the next step is to deploy the contract to the blockchain.

4. How the Meme Coin Trend Application works

When receiving a request from the consumer contract, the system listens for the request and then identifies an appropriate AI to process the data. Once the AI completes the processing, the system fulfills the request by providing the processed result back to the consumer. This process is triggered by the Coordinator contract, which calls the function to fulfill data requests once getting the results.

The result that the consumer contract will receive from the AI system involves a meme coin along with a recommendation to either buy or sell. This result is structured with two key fields:

  • "decision": This is a boolean field. If the value is true, it indicates the recommendation is to buy the meme coin. If the value is false, it indicates the recommendation is to sell the meme coin.

  • "token_name": This field specifies the name of the meme coin the decision applies to, such as "Dogecoin", "Shiba Inu", or any other meme coin.

We've also built some examples to help you easily understand what you can do with ADCS. Click the link here.

Last updated