# How to Construct a Workflow

{% embed url="<https://youtu.be/YajjCaKQOD4>" %}

This guide will walk you through how to construct a **KRNL Studio workflow** that fetches real estate data, analyzes it with AI, and encodes the results for on-chain submission.

We’ll break it down step by step so you understand what each part of the workflow does, and then show you the final JSON config you’ll use.

Again, this is just a demo, and this might defer depending on the problem you are trying to solve with using KRNL in dApp

**⏱ Time to complete**: \~15 minutes

### What You’ll Build

A workflow that:

1. Fetches property data from Zillow (mocked API in this example)
2. Fetches market estimates (value, rent, etc.)
3. Runs an AI property analysis (GPT-based)
4. Encodes the results into an EVM transaction
5. Prepares it for blockchain submission with cryptographic proof

### Step 1: Launch KRNL Studio

Open <https://studio.krnl.xyz> in your browser. You should see the KRNL Studio interface.

### Step 2: Set Up Your Workflow Foundation

#### Create a New Workflow

1. Click **"Start Building"**
2. Name your workflow: `Real Estate Investment Analyzer`
3. Select `Sepolia Testnet` as the Blockchain Network
4. Paste the target contract address (deployed in [local-dev](https://docs.krnl.xyz/getting-started/getting-started-with-krnl/local-dev "mention"))
5. Next you will have option to fetch your ABI automatically from Etherscan or manually input the ABI
6. Select `submitPropertyAnalysis((uint256,uint256,bytes32,(bytes32,bytes,bytes)[],bytes,bool,bytes))` as the function signature
7. Finally you will have a canvas with pre-filled nodes

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2F7pnRYd95fO0cU1bqhjWg%2FScreenshot%202025-09-29%20at%2012.16.36%E2%80%AFPM.png?alt=media&#x26;token=ed08fbc3-72e6-472f-9f01-a7da11f1b97a" alt=""><figcaption></figcaption></figure>

The canvas will display the default nodes:

* **Basic Info**: Workflow metadata and configuration
* **dApp Config**: Target contract settings
* **Workflow Steps**: To add custom workflow steps

#### Configure Basic Information

1. Hover over **Basic Info** node and click on the settings
2. You might see all the fields already filled in
3. After verifying the fields, let's move on to the next node

#### Configure dApp Information

1. Hover over the **dApp Config** node and click on the settings
2. You might see all the fields already filled in
3. Again after verifying the fields, let's move on to the next node

### Step 3: Add Workflow Steps

#### Add a Property Data Fetcher Step

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FzBs9zHfBdVhq0Lrf8SC8%2FScreenshot%202025-10-03%20at%207.53.30%E2%80%AFPM.png?alt=media&#x26;token=be9cf864-2bd9-4784-ab61-52aebd1d36d7" alt=""><figcaption></figcaption></figure>

1. Click on Add Node and drag and drop the **HTTP GET under HTTP** step into the workflows
2. Hover over the step and click on settings
3. First, let's name it `property-data-fetcher` (This name could be anything you like)

#### Configure the API Request

* In the settings page, there is a section called **Inputs,** under this configure your API request
* URL: `https://poc.platform.lat/zillow/webservice/GetSearchResults.htm?zws-id=demo-api-key&address=1234-Maple-Street&citystatezip=Austin,TX`
* Method: `GET`

#### Set Outputs

* `zpid` → `response.body.searchResults.zpid`
* `address.street` → `response.body.searchResults.address.street`
* `address.city` → `response.body.searchResults.address.city`
* `address.state` → `response.body.searchResults.address.state`
* `address.zipcode` → `response.body.searchResults.address.zipcode`

Close the **Settings**.

#### Add a Market Data Fetcher Step

1. Click on Add Node and drag and drop the **HTTP GET under HTTP** step into the workflows
2. Hover over the step and click on settings
3. First, let's name it `market-data-fetcher` (This name could be anything you like)

#### Configure the API Request

* URL: `https://poc.platform.lat/zillow/webservice/GetZestimate.htm?zws-id=demo-api-key&zpid=${property-data-fetcher.zpid}`
* Method: `GET`

#### Set Outputs

* `zestimate.amount.value` → `response.body.zestimate.amount.value`
* `zestimate.amount.currency` → `response.body.zestimate.amount.currency`
* `zestimate.rent.value` → `response.body.zestimate.rentZestimate.value`
* `zestimate.rent.currency` → `response.body.zestimate.rentZestimate.currency`
* `property.bedrooms` → `response.body.property.bedrooms`
* `property.bathrooms` → `response.body.property.bathrooms`
* `property.finishedSqFt` → `response.body.property.finishedSqFt`
* `property.yearBuilt` → `response.body.property.yearBuilt`
* `property.type` → `response.body.property.propertyType`

Close the **Settings**.

{% hint style="warning" %}
Output type should be string for all the outputs
{% endhint %}

#### Add an AI Node

1. Click on Add Node and drag and drop the **OpenAI GPT under AI Assistant** step into the workflows
2. Hover over the step and click on settings
3. First, let's name it `ai-property-analysis` (This name could be anything you like)

#### Configure the AI Request

* URL: `https://api.openai.com/v1/chat/completions`
* Method: `POST`
* Headers:

  ```json
  {
    "Accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": "Bearer ${_SECRETS.OPENAI_API_KEY}"
  }
  ```
* Body:

  ```json
  {
    "model": "gpt-4o-mini",
    "temperature": 0,
    "response_format": { "type": "json_object" },
    "messages": [
      { "role": "system", "content": "You are a professional real estate analyst. Only output valid JSON." },
      { "role": "user",
        "content": "Analyze this property for investment potential. Property: ${property-data-fetcher.address.street}, ${property-data-fetcher.address.city}, ${property-data-fetcher.address.state} ${property-data-fetcher.address.zipcode}. Bedrooms: ${market-data-fetcher.property.bedrooms}, Bathrooms: ${market-data-fetcher.property.bathrooms}, SqFt: ${market-data-fetcher.property.finishedSqFt}, Year Built: ${market-data-fetcher.property.yearBuilt}, Type: ${market-data-fetcher.property.type}. Zillow Estimate: ${market-data-fetcher.zestimate.amount.value}(${market-data-fetcher.zestimate.amount.currency}). Rent: ${market-data-fetcher.zestimate.rent.value}(${market-data-fetcher.zestimate.rent.currency}). Return JSON: { recommendation: INVEST/HOLD/PASS, property_value: number*10^20, investment_grade: A+/A/B+/B/C+/C/D, expected_annual_yield: number*10^18, confidence: number (1-100), invest_value: number * 10^18 }."
      }
    ]
  }
  ```

#### Set Outputs

* &#x20;`ai_analysis.result` → `response.body.choices.0.message.content`

Close the **Settings**.

### Step 4: Construct & Submit EVM Payload

This node will be automatically added as soon as you add the first step in the workflow. Now click on edit to open the settings

#### Configure Parameters -> Expected Response in the contract

Under the settings we need to first configure the response fields which are expected by the target smart contract, in our case,

```
confidence -> uint256
expectedAnnualYield -> uint256
investmentGrade -> string
propertyValue -> uint256
recommendation -> string
```

#### Map Parameters -> Expected Response in the contract

As we have configured the field as components under Configuration in the Settings. Now we can map the workflow results to the fields as per the requirement, in our case this is how the mapping should look like where each field is being mapped via internal referencing of selective workflow steps.

```json
propertyInfo: {
  confidence: "${ai-property-analysis.result.confidence}",
  expectedAnnualYield: "${ai-property-analysis.result.expected_annual_yield}",
  investmentGrade: "${ai-property-analysis.result.investment_grade}",
  propertyValue: "70000000000000000000000",
  recommendation: "${ai-property-analysis.result.recommendation}"
}
```

#### Set Outputs

* No change needed

Close the **Settings**.

### Step 5: Preview, Save, and Export

1. Verify all connections
2. Check node outputs
3. Save workflow (auto-save enabled)
4. Export workflow: Workflow Name → Export → Download JSON
