# Custom Data Validation

In this guide, we will walk through a Data Application and a simple example implementation of an IoT use case. Complete code for this guide can be found in the [metagraph examples repo](https://github.com/Constellation-Labs/metagraph-examples) on Github. See the [Water and Energy Use](https://github.com/Constellation-Labs/metagraph-examples/tree/main/examples/DataApi-Water-And-Energy-Usage) example.

**Want more detail?**

Looking for additional detail on Data Application development? More information is available in [Data Application](/metagraph-development/metagraph-framework/data.md).

### Before You Start[​](https://docs.constellationnetwork.io/sdk/guides/custom-data#before-you-start) <a href="#before-you-start" id="before-you-start"></a>

In order to get started, install dependencies as described in the [Quick Start Guide](/metagraph-development/guides/quick-start.md). You will need at least the `global-l0`, `metagraph-l0`, and `metagraph-l1-data` containers enabled in your `euclid.json` file for this guide.

**Example euclid.json values**

```
  "version": "0.9.1",
  "tessellation_version": "2.2.0",
  "project_name": "custom-project",
  "framework": {
    "name": "currency",
    "modules": [
      "data"
    ],
    "version": "v2.2.0",
    "ref_type": "tag"
  },
  "layers": [
    "global-l0",
    "metagraph-l0",
    "currency-l1",
    "data-l1"
  ],
```

**Installing Templates with Hydra**

To initiate a metagraph using a template, we provide several options in our [GitHub repository](https://github.com/Constellation-Labs/metagraph-examples). Follow these steps to utilize a template:

1\.  List Available Templates: First, determine th\`e templates at your disposal by executing the command below:

```
./scripts/hydra install-template --list
```

2\.  Install a Template: After selecting a template, replace `:repo_name` with your chosen repository's name to install it. For instance:

```
./scripts/hydra install-template :repo_name
```

As a practical example, if you wish to install the `water-and-energy-usage` template, your command would look like this:

```
./scripts/hydra install-template water-and-energy-usage
```

This process will set up a metagraph based on the selected template.

Within your Euclid modules directory (source/project/water-and-energy-usage/modules) you will see three module directories: l0 (metagraph l0), l1 (currency l1), and data\_l1 (data l1). Each module has a Main.scala file that defines the application that will run at each corresponding layer.

```
- source
  - project
    - water-and-energy-usage
      - modules
        - l0
        - l1
        - data_1
        - shared_data
      - project
```

### Send Data[​](https://docs.constellationnetwork.io/sdk/guides/custom-data#send-data) <a href="#send-data" id="send-data"></a>

Edit the `send_data_transaction.js` script and fill in the `globalL0Url`, `metagraphL1DataUrl`, and `walletPrivateKey` variables. The private key can be generated with the `dag4.keystore.generatePrivateKey()` method if you don't already have one.

Once the variables are updated, save the file. You can now run `node send_data_transaction.js` to send data to the `/data` endpoint.

#### Check State Updates[​](https://docs.constellationnetwork.io/sdk/guides/custom-data#check-state-updates) <a href="#check-state-updates" id="check-state-updates"></a>

Using the custom endpoint created in the data\_l1 Main.scala `routes` method, we can check the metagraph state as updates are sent.

Using your browser, navigate to `<your L1 base url>/data-application/addresses` to see the complete state including all devices that have sent data. You can also check the state of an individual device using the `<your L1 base url>/data-application/addresses/:address` endpoint.

You should see a response like this:

```
{
    "DAG4bQGdnDJ5okVdsdtvJzBwQoPGjLNzN7HC1CBV": {
        "energy": {
            "usage": 7,
            "timestamp": 1689441998946
        },
        "water": {
            "usage": 7,
            "timestamp": 1689441998946
        }
    }
}
```

### Next Steps[​](https://docs.constellationnetwork.io/sdk/guides/custom-data#next-steps) <a href="#next-steps" id="next-steps"></a>

This brief guide demonstrates the ability to update and view on-chain state based on the Metagraph Framework's Data Application layer. Detailed information about the framework methods used can be found in the [example README file](https://github.com/Constellation-Labs/metagraph-examples/blob/main/examples/DataApi-Water-And-Energy-Usage/README.md) and in comments throughout the code. Also see additional break downs of the application lifecycle methods in the [Data API](/metagraph-development/metagraph-framework/data.md) section.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.constellationnetwork.io/metagraph-development/guides/custom-data-validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
