Documentation
EVM based Chains

On-chain App Guide for EVM based Chains

The On-chain app allows you to create tasks that are completed on-chain. This is useful when you need to verify task completion on the blockchain. In this guide, we'll walk you through the process of setting up an On-chain Graph Task in your campaign.

Step 1: Create a new campaign

Create a new campaign: Start by creating a new campaign. Refer this guide to learn how to launch a new campaign: Create and launch a Campaign.

Step 2: Add the On-chain App

You can view all the available apps on the left panel. Choose the Onchain option and select Onchain Graph task app.

Select onchain

Select Onchain Task

Step 3: Configure the On-chain App

Configure Onchain

To configure the On-chain app, you need to provide the following details in the right panel:

3.1 Graph Endpoint

The Graph Endpoint is typically provided by the server hosting the GraphQL service. This is where you'll send your GraphQL queries over HTTP. The endpoint usually follows this structure:

https://api.thegraph.com/subgraphs/id/subgraph_id 

or

https://api.thegraph.com/subgraphs/name/user_name/subgraph_name

For instance:

https://api.thegraph.com/subgraphs/id/QmSiDZELGRXEieEkyK7jq98zqanRLvVrJQJVpMQSxrz7bo

or

https://api.thegraph.com/subgraphs/name/adarshkumar790/stakedfxdxroutervault

3.2 Graph Query

The Graph Query is the query that will be run to determine whether the user's task completion is valid.

For example:

query info ($address: Bytes) {
    stakes(orderBy: amount, where: {amount_gte: "100000000000000000000", account: $address}) {
        account 
        amount
    }
}

3.3 Graph Expression

The Expression is any logic that needs to be applied to the response data to determine whether the user's task completion is valid.

For instance, if the above query returns the following response when a user's task completion is valid:

{
  "data": {
    "stakes": [
      {
        "account": "0x26XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXe92",
        "amount": "100000000000000000000"
      }
    ]
  }
}

For invalid users, it returns the following response:

{
  "data": {
    "stakes": []
  }
}

To validate the above two responses, you can define an expression like this:

function(response) { 
  if (response.stakes != null && response.stakes.length > 0) { 
    return 1;
  } 
  return 0;
}

This expression checks if the stakes array is not null and has at least one element. If it does, the task completion is considered valid.

Step 4: Save and submit your campaign

Once you've finished all the steps, click the "Save changes" button at the top right corner of the dashboard. Your On-chain Graph Task Campaign is now ready!

And that's it! You've successfully created an On-chain Graph Task in your campaign. You can now preview your campaign on the dashboard and test the task to ensure it's working as expected.