# CLI

**Read time - 30 minutes**

This guide contains the instructions for deploying relevant smart contracts and using the KRNL SDK and KRNL CLI . For this demo we will use a mock realestate dApp where you can list your property, analyze the property score using a bunch of external APIs, run this dataset through OpenAI GPT API and get a final score to use in the contract and the best part is we will do all of this in a atomic transaction. This demo will help you understand the steps to follow to integration KRNL protocol to your smart contract and create a KRNL integrated dApp

***

### Preparations

* **Install Docker**
  * Go to <https://www.docker.com/get-started/> and install Docker Desktop
  * Make sure you sign in/create an account for docker desktop
* **Etherscan (for verifying smart contracts on Sepolia network)** - Find the API key [here](https://etherscan.io/)
* **Sepolia testnet** - "Add a custom network" on your MetaMask wallet
* **Funds** - make sure you have a **SepoliaETH** by claiming them from [faucets here](https://docs.krnl.xyz/helpful-resources/testnet-faucets).
  * Sepolia token ≈ **0.1 SepoliaETH**
* **Privy App ID and Secret**
  * Go to [dashboard.privy.io](https://dashboard.privy.io/)
  * Create an app
  * Copy the App ID and secret
* MetaMask - You can download and install using this [link](https://metamask.io/en-GB/download)

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FUTAwpmGtYOynFXXt7kse%2F1.png?alt=media&#x26;token=ddb56138-d644-494c-8d39-4029a81225fd" alt=""><figcaption></figcaption></figure>

* **Pimlico API Key**
  * Go to <https://dashboard.pimlico.io/sign-in> and create an account/sign in with your existing account
  * Then navigate to <https://dashboard.pimlico.io/apikeys> and create your api key
  * Keep this API key for later use

### Deploy the Target Contract

#### 1. Install the KRNL CLI

Go to your terminal and run this command:

```bash
npm install -g @krnl-dev/krnl-cli
```

#### 2. Clone the repo

Go to your terminal and run this command:

```bash
git clone https://github.com/KRNL-Labs/poc-dapp-realestateinvestment-7702.git hello-krnl
```

#### 3. Go to contract folder

Run this command:

```bash
cd hello-krnl/contracts
```

#### Create the .env file

1.1 Copy .env.example to .env

```bash
cp .env.example .env
```

1.2 Fill the .env file with these values:

```bash
PRIVATE_KEY=<your_wallet_private_key> //Add your private key with 0x like 0x.....

MOCK_USDC_ADDRESS=0x038b5f24FF651d174411F15f8cc64C4156A9a6D0 //We have already deployed a mock USD for testing

DELEGATED_ACCOUNT_ADDRESS=0x9969827E2CB0582e08787B23F641b49Ca82bc774 //This is the SCA you will be authorizing to interact with KRNL

# Optional: Etherscan API key for contract verification
ETHERSCAN_API_KEY=<your_etherscan_api>

SEPOLIA_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com //Use any Ethereum Sepolia RPC you have
```

{% hint style="info" %}
Follow [this](https://support.metamask.io/configure/accounts/how-to-export-an-accounts-private-key) guide to export MetaMask private key
{% endhint %}

#### Deploy the contract

1.1 Run the following command to install the forge dependencies:

```bash
forge install OpenZeppelin/openzeppelin-contracts 
forge install eth-infinitism/account-abstraction@v0.7.0 
forge install foundry-rs/forge-std 
```

1.2 Run the following command to deploy the contract:

```bash
krnl deploy --network sepolia --contract RealEstateInvestment --verify
```

1.3 After the deployment you get screen like this:

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2Ft9gfX3o3VXXD2HAw6jPr%2FScreenshot%202025-09-27%20at%208.59.01%E2%80%AFAM.png?alt=media&#x26;token=bc5d63da-c672-41e4-b3ed-eb3583672e8d" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You have to deploy your own target contract where your EOA will be used as the master key for signature verification, you will learn about this later in the docs
{% endhint %}

### Setup the Attestor Image

Attestor is a component which will attest and also resolve the secrets in your DSL workflow (don't worry we will learn about all of this in the core concepts)

#### 1. Run the Attestor&#x20;

```
krnl create-attestor
```

#### 2. Follow the onscreen instruction

2.1 Enter your project name:

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FT5KtVRBGmbSqCxPPm48s%2FScreenshot%202025-09-27%20at%2010.23.01%E2%80%AFAM.png?alt=media&#x26;token=751efad8-e502-4ab2-8ce0-412c42623bf2" alt=""><figcaption></figcaption></figure>

2.2 Enter Docker registry, it should `docker.io`&#x20;

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2F2psnSQWANQpBiU98iccb%2FScreenshot%202025-09-27%20at%2010.35.30%E2%80%AFAM.png?alt=media&#x26;token=e6775c4a-d5e5-4d5a-b039-2767ab7e304c" alt=""><figcaption></figcaption></figure>

2.3 Enter your docker username

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FwdMyBQI6dWIiHZbcXfoZ%2FScreenshot%202025-09-27%20at%208.53.41%E2%80%AFPM.png?alt=media&#x26;token=36825046-8034-4d78-9dba-108ce2636acb" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
The script pushes an attestor image to your docker hub so make sure to sign in and ensure that your docker desktop is running in the background while this script is being executed
{% endhint %}

2.4 Enter your private key

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FihfGlRl5a6hRdye6un7U%2FScreenshot%202025-09-27%20at%208.00.18%E2%80%AFPM.png?alt=media&#x26;token=e369fe06-854a-4017-bc31-6958a2d5f109" alt=""><figcaption></figcaption></figure>

2.5 Create a encryption secret which is a password to the safe carrying your private key to make your private key is handled safely. Press enter to auto generate

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FnEsFpRBJP1Dq263sk3lP%2FScreenshot%202025-09-27%20at%208.01.23%E2%80%AFPM.png?alt=media&#x26;token=53ef5ee5-7127-47c8-9a4f-1b623f2fd679" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
This is the same private key which you have derived from your MetaMask wallet
{% endhint %}

2.6 Pass the secrets to resolve in the DSL workflow during execution. For our real estate workflow example, we need:

* rpcSepoliaURL=\<ethereum\_sepolia\_rpc>
* pimlico-apikey=\<api\_key\_of\_your\_pimlico\_account>
* OPENAI\_API\_KEY=mock-api (We are using a mock api in our DSL for the sake of the demo)

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FwDaIJGL23ecnY2J3tR1r%2FScreenshot%202025-09-27%20at%208.14.14%E2%80%AFPM.png?alt=media&#x26;token=38f564aa-e7c9-40ca-99a5-51daece01678" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Make sure to replace '<>' with actual values
{% endhint %}

{% hint style="info" %}
We will learn more about workflow DSL later in [workflows](https://docs.krnl.xyz/core-concepts/workflows "mention"). For now make sure to add the exact key pair as a part of creating attestor image
{% endhint %}

2.7 Wait for few seconds and you will see a success screen with your attestor image&#x20;

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FrG63LPhVilSCQ2f8Wsmo%2FScreenshot%202025-09-27%20at%208.51.41%E2%80%AFPM.png?alt=media&#x26;token=be923f85-0e2f-46e5-a666-ba19bda9a3f9" alt=""><figcaption></figcaption></figure>

### Setup the dApp

#### 1. Go to frontend folder from the contract folder

```
cd ../frontend
```

#### 2. Create the .env file

2.1 Copy .env.example to .env

```
cp .env.example .env
```

2.2 Fill the .env file with these values:

```
VITE_PRIVY_APP_ID=<your_privy_app_id>
VITE_PRIVY_APP_SECRET=<your_privy_secret>

VITE_CHAIN_ID=11155111 //Chain ID for Ethereum Sepolia

VITE_DELEGATED_ACCOUNT_ADDRESS=0x9969827E2CB0582e08787B23F641b49Ca82bc774 // Do not change this

VITE_DELEGATE_OWNER=<your_eoa_address> // This should be the same address you used to create your attestor
VITE_REAL_ESTATE_INVESTMENT_ADDRESS=0x038b5f24FF651d174411F15f8cc64C4156A9a6D0 //Replace this with the target contract address we just deployed
VITE_MOCK_USDC_ADDRESS=0xaC66E9916dCe765405E4A4297DdDF61729CbDFF9

VITE_ATTESTOR_IMAGE=image://docker.io/ash20pk20/attestor-realestate:latest //Replace this image with your attestor image link, make to keep the image:// prefix

VITE_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com //Use any Ethereum Sepolia RPC you have
```

#### 3. Install the dependencies

```
npm install
```

#### 4. Run the application

```
npm run dev
```

{% hint style="info" %}
Your app will be available at <http://localhost:5173/>
{% endhint %}

#### 5. Run your KRNL workflow&#x20;

{% hint style="info" %}
We are running this workflow from your user's point of view&#x20;
{% endhint %}

5.1 Connect your wallet

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FX7Dk3qd2dLqLTWbJ0ICF%2FScreenshot%202025-09-27%20at%2010.04.21%E2%80%AFPM.png?alt=media&#x26;token=0f675403-5610-4ca6-88c4-196cd56e4dfd" alt=""><figcaption></figcaption></figure>

5.2 Fund the embedded wallet with Sepolia ETH token

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FXfzf70w5ruwJeMgrku9E%2FScreenshot%202025-09-27%20at%2010.06.48%E2%80%AFPM.png?alt=media&#x26;token=5334c51b-ff36-4ad1-b698-8881f7b96585" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
This wallet is different from your EOA wallet and this is created automatically as soon as you sign in
{% endhint %}

5.3 Delegate execution to KRNL smart contract account

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2Fz0UJDwFeCW6xpf9alqig%2FScreenshot%202025-09-27%20at%2010.06.48%E2%80%AFPM.png?alt=media&#x26;token=09a10a73-605f-4724-9849-f3adc9dafe72" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
This embedded wallet is completely independent of your EOA wallet to make sure your user's personal wallets are safe when delegating execution to our SCA
{% endhint %}

5.4 Run the workflow DSL

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2FLCE4j3T5sOpvjUV76l4Z%2FScreen%20Recording%202025-09-28%20at%201.19.08%E2%80%AFAM.gif?alt=media&#x26;token=b45ddeac-a284-45a5-bbb3-bc2168fa3d40" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The time taken for the execution depends on the latency of the external services being used in the workflow.
{% endhint %}

5.5 Verify the execution in your target contract

<figure><img src="https://4254516379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9YZopA2A53QCZtcc7WU0%2Fuploads%2F4U4kcjOFHAAXeUAu9KBh%2FScreenshot%202025-09-28%20at%201.28.23%E2%80%AFAM.png?alt=media&#x26;token=49612aeb-f044-45a4-ac7e-fface548f57b" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The solidity event signifies that the function was called with the KRNL response -> the response signature was verified by the modifier and the response was decoded for the computation.
{% endhint %}

These steps signifies the happy path to deploying using first KRNL integrated application which let's you use functions from our EVM contracts across multiple chains as well using external API letting you build dApps like apps without being limited by the existing smart contracts design

### What's next?

Congrats on completing your first hands-on tutorial using KRNL now it's time to learn the [core-concepts](https://docs.krnl.xyz/core-concepts "mention") to understand all the concepts and flows in detail.
