CLI

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

  • Install Docker

  • Etherscan (for verifying smart contracts on Sepolia network) - Find the API key here

  • Sepolia testnet - "Add a custom network" on your MetaMask wallet

  • Funds - make sure you have a SepoliaETH by claiming them from faucets here.

    • Sepolia token ≈ 0.1 SepoliaETH

  • Privy App ID and Secret

  • MetaMask - You can download and install using this link

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:

Follow this 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:

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

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

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)

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

Your app will be available at http://localhost:5173/

5. Run your KRNL workflow

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

5.3 Delegate execution to KRNL smart contract account

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

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

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