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
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
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
Go to dashboard.privy.io
Create an app
Copy the App ID and secret

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:
npm install -g @krnl-dev/krnl-cli
2. Clone the repo
Go to your terminal and run this command:
git clone https://github.com/KRNL-Labs/poc-dapp-realestateinvestment-7702.git hello-krnl
3. Go to contract folder
Run this command:
cd hello-krnl/contracts
Create the .env file
1.1 Copy .env.example to .env
cp .env.example .env
1.2 Fill the .env file with these values:
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=0xFFB5C2684532D8B24313Fc084d65DDaa0B946040 //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
Deploy the contract
1.1 Run the following command to install the forge dependencies:
forge install OpenZeppelin/openzeppelin-contracts --no-commit
forge install eth-infinitism/[email protected] --no-commit
forge install foundry-rs/forge-std --no-commit
1.2 Run the following command to deploy the contract:
krnl deploy --network sepolia --contract RealEstateInvestment --verify
1.3 After the deployment you get screen like this:

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
krnl create-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

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

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
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=0xFFB5C2684532D8B24313Fc084d65DDaa0B946040 // 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
5. Run your KRNL workflow
5.1 Connect your wallet

5.2 Fund the embedded wallet with Sepolia ETH token

This wallet is different from your EOA wallet and this is created automatically as soon as you sign in
5.3 Delegate execution to KRNL smart contract account

5.4 Run the workflow DSL

5.5 Verify the execution in your target contract

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