clipboard-listCLI

Goal: To complete the integration of kOS into your smart contract and to be able to call transactions within a dApp.

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

Deploy the Target Contract

1. Install the KRNL CLI

Go to your terminal and run this command:

2. Clone the repo

Go to your terminal and run this command:

3. Go to contract folder

Run this command:

Create the .env file

1.1 Copy .env.example to .env

1.2 Fill the .env file with these values:

circle-info

Follow thisarrow-up-right guide to export MetaMask private key

Deploy the contract

1.1 Run the following command to install the forge dependencies:

1.2 Run the following command to deploy the contract:

1.3 After the deployment you get screen like this:

circle-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

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

2. Follow the onscreen instruction

2.1 Enter your project name:

2.2 Enter Docker registry, it should docker.io

2.3 Enter your docker username

circle-exclamation

2.4 Enter your private key

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

circle-exclamation

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)

circle-exclamation
circle-info

We will learn more about workflow DSL later in Workflows. For now make sure to add the exact key pair as a part of creating attestor image

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

Setup the dApp

1. Go to frontend folder from the contract folder

2. Create the .env file

2.1 Copy .env.example to .env

2.2 Fill the .env file with these values:

3. Install the dependencies

4. Run the application

circle-info

Your app will be available at http://localhost:5173/arrow-up-right

5. Run your KRNL workflow

circle-info

We are running this workflow from your user's point of view

5.1 Connect your wallet

5.2 Fund the embedded wallet with Sepolia ETH token

circle-exclamation

5.3 Delegate execution to KRNL smart contract account

circle-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

5.4 Run the workflow DSL

circle-info

The time taken for the execution depends on the latency of the external services being used in the workflow.

5.5 Verify the execution in your target contract

circle-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.

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 to understand all the concepts and flows in detail.

Last updated