<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shweta Kale</title>
    <description>The latest articles on DEV Community by Shweta Kale (@shweta).</description>
    <link>https://dev.to/shweta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F397383%2Ff2c04c98-f7c1-49de-b666-68d7954bd698.jpg</url>
      <title>DEV Community: Shweta Kale</title>
      <link>https://dev.to/shweta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shweta"/>
    <language>en</language>
    <item>
      <title>Fluencr - Find Instagram Influencer For your brand</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Mon, 26 May 2025 06:57:21 +0000</pubDate>
      <link>https://dev.to/shweta/fluencr-find-instagram-influencer-for-your-brand-5617</link>
      <guid>https://dev.to/shweta/fluencr-find-instagram-influencer-for-your-brand-5617</guid>
      <description>&lt;h1&gt;
  
  
  🧠 AI-Powered Influencer Discovery Engine
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I built an AI-powered platform that helps &lt;strong&gt;brands discover ideal influencers&lt;/strong&gt; by tapping into real-time social media data. Unlike static influencer directories, this tool dynamically finds creators who align with a brand’s &lt;strong&gt;tone, values, target audience&lt;/strong&gt;, and &lt;strong&gt;preferred content style&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The system uses an AI agent to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Collect brand intent via a clean, guided interface&lt;/li&gt;
&lt;li&gt;Generate a natural language brief for influencer matching&lt;/li&gt;
&lt;li&gt;Transform that into search signals (hashtags, keywords, captions)&lt;/li&gt;
&lt;li&gt;Crawl Instagram in real time using &lt;strong&gt;Bright Data's MCP&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This lets brands &lt;strong&gt;find relevant, high-performing influencers&lt;/strong&gt; based on their current content—not stale bios or outdated databases.&lt;/p&gt;




&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;GitHub Repo: github.com/raibove/Fluencr&lt;br&gt;&lt;br&gt;
Live Demo: https://fluencr.pages.dev/&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmk737ll5nwuzr614sngj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmk737ll5nwuzr614sngj.png" alt="Image description" width="800" height="495"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  How I Used Bright Data's Infrastructure
&lt;/h2&gt;

&lt;p&gt;To power the &lt;strong&gt;real-time influencer discovery system&lt;/strong&gt;, I used Bright Data’s &lt;strong&gt;MCP (Mobile Cloud Proxy)&lt;/strong&gt; and automation tools. Here's how it helped:&lt;/p&gt;

&lt;h3&gt;
  
  
  🔍 Discover – Crawler-Based Search
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Used &lt;strong&gt;Search Engine Crawler API&lt;/strong&gt; to scan TikTok, Instagram, and YouTube content based on AI-generated hashtags, keywords, and even video transcript data.&lt;/li&gt;
&lt;li&gt;Dynamically prioritized &lt;strong&gt;posts with high engagement and recency&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🧭 Access – Platform Navigation with JS Rendering
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Platforms like TikTok and Instagram require &lt;strong&gt;login, scrolling, and human behavior simulation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Bright Data’s helped &lt;strong&gt;avoid detection&lt;/strong&gt; and ensure reliability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📥 Extract – Scraping Key Data
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Collected structured content:

&lt;ul&gt;
&lt;li&gt;Creator handles, bios, and follower count
&lt;/li&gt;
&lt;li&gt;Common hashtags and captions
&lt;/li&gt;
&lt;li&gt;Engagement stats and collaboration links
&lt;/li&gt;
&lt;li&gt;Video transcripts (when available)
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Stored this data with &lt;strong&gt;content embeddings&lt;/strong&gt; for future AI-based matching.&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Performance Improvements
&lt;/h2&gt;

&lt;p&gt;Traditional influencer tools rely on pre-populated databases or partner networks, which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Often outdated&lt;/li&gt;
&lt;li&gt;Miss dynamic trends&lt;/li&gt;
&lt;li&gt;Lack true intent-based matching&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using &lt;strong&gt;real-time social content scraping&lt;/strong&gt;, I was able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Surface creators based on &lt;strong&gt;live content behavior&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Identify micro-influencers aligned with niche values like &lt;strong&gt;sustainability or tech innovation&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Deliver &lt;strong&gt;10x more relevant results&lt;/strong&gt; for brands with very specific audience goals&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Tools Used&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Frontend&lt;/td&gt;
&lt;td&gt;React&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Backend AI&lt;/td&gt;
&lt;td&gt;Cloudflare Worker + GPT-4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scraping Infra&lt;/td&gt;
&lt;td&gt;Bright Data MCP&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  App Flow: From Brand Brief to Influencer Match
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enter Brand Details&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
→ Dropdowns for brand tone, audience, platform, values  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI Improves Prompt&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
→ GPT-4 generates a structured brand profile:&lt;br&gt;&lt;br&gt;
&lt;em&gt;“Looking for creators who post funny, women-focused, Gen Z content around self-love on Instagram”&lt;/em&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Generate Search Signals&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
→ AI outputs hashtags, content types, keywords  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Search &amp;amp; Extract&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
→ Bright Data crawls platforms, simulates interaction, and extracts data  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deliver Matches&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
→ Ranked influencer shortlist with metrics and links&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;This tool blends &lt;strong&gt;AI prompt generation&lt;/strong&gt;, &lt;strong&gt;real-time web scraping&lt;/strong&gt;, and &lt;strong&gt;content analysis&lt;/strong&gt; to solve one of the biggest challenges in influencer marketing: &lt;strong&gt;finding creators who truly align with a brand’s evolving voice and values&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By using &lt;strong&gt;Bright Data’s infrastructure&lt;/strong&gt;, I was able to go beyond APIs and get &lt;strong&gt;dynamic, actionable insights&lt;/strong&gt; directly from the platforms that matter.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>brightdatachallenge</category>
      <category>ai</category>
      <category>webdata</category>
    </item>
    <item>
      <title>🎨 Come Build and Deploy a Random Color Generator with Me Using Next.js, AWS, and Pulumi</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Mon, 07 Apr 2025 06:56:40 +0000</pubDate>
      <link>https://dev.to/shweta/come-build-and-deploy-a-random-color-generator-with-me-using-nextjs-aws-and-pulumi-2llp</link>
      <guid>https://dev.to/shweta/come-build-and-deploy-a-random-color-generator-with-me-using-nextjs-aws-and-pulumi-2llp</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/pulumi"&gt;Pulumi Deploy and Document Challenge&lt;/a&gt;: Fast Static Website Deployment&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I created a Random Color Generator—a lightweight web app built with Next.js that displays a new random background color on each page load. It’s a small but fun tool for designers, developers, or anyone who loves color. It's also a great way to demonstrate deploying static websites to AWS using infrastructure as code with Pulumi.&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Demo Link
&lt;/h2&gt;

&lt;p&gt;🔗 &lt;a href="https://dtdysydbnr00s.cloudfront.net/" rel="noopener noreferrer"&gt;View Live Demo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Repo
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/raibove" rel="noopener noreferrer"&gt;
        raibove
      &lt;/a&gt; / &lt;a href="https://github.com/raibove/random-color-generator" rel="noopener noreferrer"&gt;
        random-color-generator
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Generate random color
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;🎨 Random Color Generator&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A lightweight, fun static web app built with &lt;strong&gt;Next.js&lt;/strong&gt; that displays a new random background color on every page load. This project also showcases how to deploy static websites to AWS using &lt;strong&gt;Pulumi&lt;/strong&gt; and &lt;strong&gt;infrastructure as code&lt;/strong&gt; principles.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;🚀 Live Demo&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;👉 &lt;a href="https://dtdysydbnr00s.cloudfront.net/" rel="nofollow noopener noreferrer"&gt;View Live Demo&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;📁 Project Structure&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/app&lt;/code&gt;&lt;/strong&gt; – The main Next.js app (exported as static HTML)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Pulumi/&lt;/code&gt;&lt;/strong&gt; – Infrastructure code to deploy to AWS S3 + CloudFront using Pulumi (in TypeScript)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;📸 Preview&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/150ccd07c4dc86d18855170a5a0dc38f1d9c39449b44e015ebfb7685d7319fd0/68747470733a2f2f6465762d746f2d75706c6f6164732e73332e616d617a6f6e6177732e636f6d2f75706c6f6164732f61727469636c65732f6a6a6f307a7373677138717573747131786166762e706e67"&gt;&lt;img src="https://camo.githubusercontent.com/150ccd07c4dc86d18855170a5a0dc38f1d9c39449b44e015ebfb7685d7319fd0/68747470733a2f2f6465762d746f2d75706c6f6164732e73332e616d617a6f6e6177732e636f6d2f75706c6f6164732f61727469636c65732f6a6a6f307a7373677138717573747131786166762e706e67" alt="Color Generator Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;⚙️ How It Works&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Each time you refresh the page, the background color changes randomly using a &lt;code&gt;generateRandomColor()&lt;/code&gt; function in JavaScript. The app was statically exported using &lt;code&gt;next export&lt;/code&gt; and deployed securely using AWS services via Pulumi.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;🛠️ Deployment Using Pulumi&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;The infrastructure is defined in TypeScript and includes:&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;1. &lt;strong&gt;S3 Bucket (Private)&lt;/strong&gt;
&lt;/h3&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Hosts the exported static site.&lt;/li&gt;
&lt;li&gt;Blocked public access.&lt;/li&gt;
&lt;li&gt;Configured using &lt;code&gt;BucketV2&lt;/code&gt; and &lt;code&gt;BucketWebsiteConfigurationV2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;2. &lt;strong&gt;CloudFront Distribution&lt;/strong&gt;
&lt;/h3&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Serves…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/raibove/random-color-generator" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
You’ll find:

&lt;ul&gt;
&lt;li&gt;The full Pulumi deployment code&lt;/li&gt;
&lt;li&gt;Instructions on setting up the Next.js app&lt;/li&gt;
&lt;li&gt;A clean, minimal README to help you get started quickly&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  My Journey
&lt;/h2&gt;


&lt;h3&gt;
  
  
  🧪 Step 1: Let’s Build Something Simple
&lt;/h3&gt;

&lt;p&gt;I started with a local Next.js project that randomly changes the background color every time the page is refreshed. I created a method called &lt;code&gt;generateRandomColor&lt;/code&gt; to generate the random color dynamically, and the result was both playful and vibrant.&lt;/p&gt;

&lt;p&gt;Once it looked good locally, I was ready to put it on the web.&lt;/p&gt;
&lt;h3&gt;
  
  
  🌐 Step 2: Hosting Static Files with AWS S3
&lt;/h3&gt;

&lt;p&gt;The Next.js app was exported using next export, creating static files in the out/ directory.&lt;/p&gt;

&lt;p&gt;To deploy these files, I used Pulumi to create an S3 bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bucket = new aws.s3.Bucket("color-bucket", {
  website: {
      indexDocument: "index.html",
  },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I uploaded all the files using Node’s fs module, and created s3 BucketObject for each path to deploy site assets&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// for each dir we used this code
  new aws.s3.BucketObject(relativeFilePath, {
    bucket: bucket.id,
    source: new pulumi.asset.FileAsset(filePath),
    contentType: lookup(filePath) || undefined,
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔐 Step 3: Oh No—Access Denied?!
&lt;/h3&gt;

&lt;p&gt;After uploading, I tried to open the website via the bucket endpoint—and got blocked.&lt;br&gt;
S3 had blocked public access by default. I briefly made the bucket public just to test, and while it worked, I immediately realized this wasn’t secure or scalable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjo0zssgq8qustq1xafv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjo0zssgq8qustq1xafv.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  🛡️ Step 4: Enter CloudFront – Secure + Fast
&lt;/h3&gt;

&lt;p&gt;Instead of making the bucket public, I used CloudFront with an Origin Access Identity (OAI) to serve files securely. This way, CloudFront could fetch content from S3, and S3 remained private.&lt;/p&gt;

&lt;p&gt;Here’s how I linked CloudFront and S3 securely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const oai = new aws.cloudfront.OriginAccessIdentity("oai", {
  comment: "OAI for secured S3 access",
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, I wrote a bucket policy granting s3:GetObject only to this OAI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bucketPolicy = new aws.s3.BucketPolicy("bucket-policy", {
  bucket: bucket.id,
  policy: pulumi.all([bucket.bucket, oai.iamArn]).apply(([bucketName, iamArn]) =&amp;gt; {
    return JSON.stringify({
      Version: "2012-10-17",
      Statement: [
        {
          Effect: "Allow",
          Principal: { AWS: iamArn },
          Action: "s3:GetObject",
          Resource: `arn:aws:s3:::${bucketName}/*`,
        },
      ],
    });
  }),
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🌍 Step 5: Create a CloudFront Distribution to Serve Your Website Globally
&lt;/h3&gt;

&lt;p&gt;To deliver your static website with low latency and improved performance across the globe, we configure an AWS CloudFront distribution. CloudFront acts as a Content Delivery Network (CDN), caching your website content at edge locations.&lt;/p&gt;

&lt;p&gt;This block sets up CloudFront to serve content securely from the S3 bucket, enforce HTTPS, cache static assets, and handle errors gracefully. The Origin Access Identity (OAI) ensures that only CloudFront (not the public internet) can access your S3 bucket content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cloudfrontDistribution = new aws.cloudfront.Distribution("web-distribution", {
  enabled: true,

  // Define the S3 bucket as the origin
  origins: [{
    originId: bucket.id,
    domainName: bucket.bucketRegionalDomainName,
    s3OriginConfig: {
      originAccessIdentity: oai.cloudfrontAccessIdentityPath,
    },
  }],

  // Default behavior for all requests
  defaultCacheBehavior: {
    targetOriginId: bucket.id,
    viewerProtocolPolicy: "redirect-to-https", // Enforce HTTPS
    allowedMethods: ["GET", "HEAD", "OPTIONS"],
    cachedMethods: ["GET", "HEAD", "OPTIONS"],
    forwardedValues: {
      queryString: false,
      cookies: { forward: "none" }, // Improve cacheability
    },
    minTtl: 0,
    defaultTtl: 3600,
    maxTtl: 86400,
  },

  defaultRootObject: "index.html",

  // Error responses are redirected to index.html to support clean URLs or fallback content
  customErrorResponses: [
    {
      errorCode: 403,
      responseCode: 200,
      responsePagePath: "/index.html",
    },
    {
      errorCode: 404,
      responseCode: 200,
      responsePagePath: "/index.html",
    },
  ],

  priceClass: "PriceClass_100", // Use cost-efficient edge locations
  viewerCertificate: {
    cloudfrontDefaultCertificate: true, // Use default CloudFront SSL certificate
  },

  restrictions: {
    geoRestriction: {
      restrictionType: "none", // No country-based restrictions
    },
  },
}, {
  dependsOn: [bucketPolicy], // Ensure the S3 bucket policy is in place before distribution
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✨ Step 6: Refactoring Pulumi Static Site Deployment: From Complex to Clean with BucketV2
&lt;/h3&gt;

&lt;p&gt;While exploring Pulumi for deploying a static site to AWS, I initially started by stitching together different snippets—mostly influenced by Pulumi Copilot suggestions and online examples. The deployment worked, but the code felt a bit heavy and overly complex for what was essentially a simple use case: serve a static site securely via S3 and CloudFront.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 Discovery: What’s BucketV2?&lt;/strong&gt;&lt;br&gt;
While chatting with Pulumi copilot and reading deeper through Pulumi docs, I came across &lt;code&gt;BucketV2&lt;/code&gt; and &lt;code&gt;BucketWebsiteConfigurationV2&lt;/code&gt;. These are part of the updated AWS S3 API and give a more modular and future-proof way to define bucket behavior, especially website settings and public access restrictions. That was the cue to start refactoring.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅Improvements After Refactoring&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Switched to BucketV2 + BucketWebsiteConfigurationV2
Before:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bucket = new aws.s3.Bucket(...);
bucket.website = { indexDocument: "index.html" };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bucket = new aws.s3.BucketV2("bucket", {});
const websiteConfig = new aws.s3.BucketWebsiteConfigurationV2("config", {
  bucket: bucket.id,
  indexDocument: { suffix: "index.html" },
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🟢 &lt;strong&gt;Why it’s better:&lt;/strong&gt; Clear separation of concerns. &lt;code&gt;BucketV2&lt;/code&gt; handles just the bucket, and the website settings are defined explicitly in &lt;code&gt;BucketWebsiteConfigurationV2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🔐 2. Tighter CloudFront + OAI Integration&lt;br&gt;
The original setup required manually managing bucket policy, blocking public access, and wiring the OAI correctly—while juggling dependencies across resources.&lt;/p&gt;

&lt;p&gt;🟢** What improved:** The refactored version keeps the OAI logic clear, makes policy assignment more predictable, and ensures the S3 bucket is accessible only through CloudFront.&lt;/p&gt;

&lt;p&gt;📦 3. Cleaner File Upload with BucketObject&lt;br&gt;
Used a recursive upload function to mirror the folder structure into the S3 bucket, without overcomplicating ACLs or dealing with public access issues.&lt;/p&gt;

&lt;p&gt;🟢 &lt;strong&gt;Improvement:&lt;/strong&gt; Now everything is private by default and securely served via CloudFront.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧩 What I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not all snippets are created equal. What works in isolation might not scale or feel right when put together.&lt;/li&gt;
&lt;li&gt;BucketV2 and friends are the way forward if you're starting a new project. They’re cleaner, more modular, and aligned with AWS’s evolving APIs.&lt;/li&gt;
&lt;li&gt;Understanding resource relationships (like between OAI, bucket policies, and public access blocks) is key to avoiding common pitfalls in AWS infrastructure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This refactor was more than just cleanup—it was a learning exercise in how Pulumi encourages modular and declarative infrastructure. With a better understanding of the tools and a simpler setup, I now have a static site deployment stack that’s secure, scalable, and easy to maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Pulumi 🛠️
&lt;/h2&gt;

&lt;p&gt;As a frontend developer, I’ve mostly relied on platforms like Vercel or Netlify to deploy my sites. They’re super convenient, especially when you just want to push to Git and get a live preview. I always felt that diving into AWS directly was a bit too involved for static sites—until I discovered Pulumi.&lt;/p&gt;

&lt;p&gt;Pulumi changed my perspective completely.&lt;/p&gt;

&lt;p&gt;With Pulumi, I was able to define my entire infrastructure using TypeScript, the same language I use for building my frontend apps. That familiarity made it surprisingly approachable. Instead of clicking around the AWS Console or writing CloudFormation, I could write real code—loop over files, conditionally configure resources, and reuse logic just like in any other app.&lt;/p&gt;

&lt;p&gt;Now that I understand how Pulumi works, I feel like I have the best of both worlds:&lt;/p&gt;

&lt;p&gt;The power and flexibility of AWS,&lt;/p&gt;

&lt;p&gt;Combined with the ease and speed of modern frontend tooling.&lt;/p&gt;

&lt;p&gt;💬 Pulumi Copilot: The AI Teammate I Didn't Know I Needed&lt;br&gt;
I also tried out Pulumi Copilot while working on this. Some of the prompts I used were:&lt;/p&gt;

&lt;p&gt;“Deploy a static site to AWS using S3 and CloudFront with Pulumi in TypeScript.”&lt;/p&gt;

&lt;p&gt;“How do I make sure S3 is only accessible through CloudFront?”&lt;/p&gt;

&lt;p&gt;“How to configure custom error responses for a single page app?”&lt;/p&gt;

&lt;p&gt;It gave me a solid foundation to start with—but I still had to refactor a lot (see above 😅). That said, it was a great assistant to explore AWS resource options and common configurations quickly.&lt;/p&gt;

&lt;p&gt;Pulumi didn’t just help me deploy a site—it helped me understand what’s really happening under the hood. I now feel more confident using AWS, setting up secure and production-ready infrastructure, and doing it all in a repeatable, code-first way.&lt;/p&gt;

&lt;h3&gt;
  
  
  ⏭️ What’s Next: Automating Deployment with GitHub Actions
&lt;/h3&gt;

&lt;p&gt;Now that I’ve got the hang of using Pulumi manually, my next weekend goal is to fully automate the deployment process. I want to set up GitHub Actions so that every time I push to the main branch, Pulumi runs and updates the infrastructure automatically.&lt;/p&gt;

&lt;p&gt;This would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep my stack always in sync with my latest code&lt;/li&gt;
&lt;li&gt;Help avoid manual errors or missed steps&lt;/li&gt;
&lt;li&gt;Make the project feel like a real production-grade setup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Excited to explore Pulumi's GitHub Action and see how to manage secrets, handle preview/diff steps, and maybe even set up different stacks for staging and production down the line.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>pulumichallenge</category>
      <category>webdev</category>
      <category>cloud</category>
    </item>
    <item>
      <title>DOM Question #8 - closest interactive element</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Tue, 04 Mar 2025 05:25:26 +0000</pubDate>
      <link>https://dev.to/shweta/dom-question-8-closest-interactive-element-4lf4</link>
      <guid>https://dev.to/shweta/dom-question-8-closest-interactive-element-4lf4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Find the closest interactive element (button, input, link) to a given DOM node.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To find closest element we can use element.closest so it will be something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const closestInteractiveEl = (node) =&amp;gt; {
 return node.closest('button, a, input');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this will only return el if current node or parent nodes are interactive. Because closest traverse till root from current element and returns if selector matches.&lt;/p&gt;

&lt;p&gt;According to question we need to find closest interactive element. This can be sibling, children or ancestor.&lt;/p&gt;

&lt;p&gt;We can solve this by getting all interactive nodes and their distance from current node. We will return element who has minimum distance from current node. If we have to get distance by traversing DOM this will be a complex problem as calculating distance between two nodes is time consuming task. Instead we will find visual proximity, which means that we will find distance between current and interactive node when they are rendered on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkigsxkvdzav2t9efruv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkigsxkvdzav2t9efruv.png" alt="Image description" width="800" height="458"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const findClosestIinteractiveElement = ()=&amp;gt; {
  const interactiveSelectors = ['button', 'a', 'input', '[role="button"]', '[role="link"]','[role="checkbox"]',
    '[role="radio"]'];

  const interactiveElements = Array.from(document.querySelectorAll(interactiveSelectors.join(',')))
}

if(interactiveElements.length===0){
 return {element: null, distance: Infinity};
}

 // Get the position of the reference node
  const nodeRect = node.getBoundingClientRect();
  const nodeCenter = {
    x: nodeRect.left + nodeRect.width / 2,
    y: nodeRect.top + nodeRect.height / 2
  };

let closestElement = null;
let shortestDistance = Infinity;

// finding distance between given and interactive node.
for(const interactiveElement of interactiveElements){
  if(node===interactiveElement || node.contains(interactiveElement)){
    return {node: element, distance: 0}
  }

  const elementRect = interactiveElement.getBoundingClientRect();
  const elementCenter = {
    x: elementRect.left + elementRect.width/2,
    y: elementRect.top + elementRect.height/2
  };

// calculate Euclidian distance
  const distance = Math.sqrt(Math.pow(elementCenter.x-nodeCenter.x, 2) + Math.pow(elementCenter.y - nodeCenter.y, 2))

  if(distance &amp;lt; shortestDistance){
   shortestDistance = distance;
   closestElement = interactiveElement;
  }
}

return {element: closestElement, distance: shortestDistance};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>DOM Question #7 - Circular Reference</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Sun, 02 Mar 2025 13:59:29 +0000</pubDate>
      <link>https://dev.to/shweta/dom-question-7-circular-reference-3hgj</link>
      <guid>https://dev.to/shweta/dom-question-7-circular-reference-3hgj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Detect cycles in a DOM tree (circular references)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DOM is a tree which means it should have hierarchical structures, which means it should not have circular reference. &lt;/p&gt;

&lt;p&gt;But circular reference can still occur due to &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Improper DOM manipulation:
eg. If a node's child references the parent node, you would introduce a cycle in what was supposed to be a tree structure.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const parent = document.createElement('div');
const child = document.createElement('div');

// Setting up a circular reference
parent.appendChild(child);
child.appendChild(parent); // This creates a cycle

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How can we detect circular reference?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We traverse the DOM and track visited nodes. If we encounter node which is already visited then DOM has circular reference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function detectCycle(root){
 const visitedNodes = new Set();

 function traverse(node){
  if(visitedNode.has(node)){
    return true;
  }

  visitedNodes.add(node);

  for(let child of node.children){
    if(traverse){
      return true;
    }
  }
 return false;
 }
  return traverse(root)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is time complexity of this code?&lt;br&gt;
To traverse tree we used DFS, so we visit each node once.&lt;br&gt;
Considering N is number of nodes time complexity of this will become O(N)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>DOM Question #6 - Serialization</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Fri, 28 Feb 2025 04:36:04 +0000</pubDate>
      <link>https://dev.to/shweta/dom-question-6-serialization-55kh</link>
      <guid>https://dev.to/shweta/dom-question-6-serialization-55kh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Write code to serialize given HTML&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Serialization means converting given HTML to JSON format. In the JSON we need to store node name, node type, children, props.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="foo"&amp;gt;
  &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
  &amp;lt;p class="bar"&amp;gt;
    &amp;lt;span&amp;gt;World!&amp;lt;/span&amp;gt;
  &amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will create a function and call it recursively on all HTML children to get JSON data in required format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getNodeProps(node){
  let props = {};
  for(let i=0; i&amp;lt; node.attributes.length; i++){
    const attribute = node.attributes[i];
    props[attribute.nodeName] = attribute.nodeValue;
  }
  return props;
}

function serialize(node){
  const serializedJSON = {};
  serializedJSON.nodeName = node.nodeName;
  serializedJSON.nodeType = node.nodeType;

  const props = getNodeProps(node);
  serializedJSON.props = props;

  let children = [];
  if(node.children.length&amp;gt;0){
   for(let i=0; i&amp;lt; node.children.length; i++){
    children.push(serialize(node.children[i]));
   }}
  serializedJSON.children = children;

  return serializedJSON;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give us serialized JSON but what about time complexity?&lt;/p&gt;

&lt;p&gt;Total time complexity: Since the function recursively visits every node in the tree, the total time complexity is proportional to the number of nodes and the number of attributes and children. In the worst case, the time complexity is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;O(N×(A+C))&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;N: is the total number of nodes.&lt;/li&gt;
&lt;li&gt;A: is the average number of attributes per node.&lt;/li&gt;
&lt;li&gt;C: is the average number of children per node.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>DOM Challenge #5 Deepest node</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Tue, 25 Feb 2025 14:38:54 +0000</pubDate>
      <link>https://dev.to/shweta/dom-challenge-5-2hch</link>
      <guid>https://dev.to/shweta/dom-challenge-5-2hch</guid>
      <description>&lt;p&gt;&lt;strong&gt;Find the deepest node in a DOM tree.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To get deepest node in DOM tree we can use Depth first search (DFS). &lt;br&gt;
Considerations -&amp;gt;&lt;br&gt;
We can have multiple nodes at deepest levels or single node as well. So I will consider we need to return first deepest node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getDeepestNode = (root) =&amp;gt; {
  const stack = [{node: root, depth: 0}];
  let deepestNode = root;
  let maxDepth = 0;
  while(stack.length &amp;gt; 0){
    const {node, depth} = stack.pop();
    if (depth &amp;gt; maxDepth) {
       maxDepth = depth;
       deepestNode = node;
    }
    for (let i=node.children.length - 1; i &amp;gt;= 0; i++){
       stack.push({node: node.children[i], depth: depth + 1})
    }
  }
  return deepestNode;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This problem can also be modified to return all nodes at deepest level.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>DOM Question #4 All siblings</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Fri, 21 Feb 2025 17:44:24 +0000</pubDate>
      <link>https://dev.to/shweta/dom-question-4-139m</link>
      <guid>https://dev.to/shweta/dom-question-4-139m</guid>
      <description>&lt;p&gt;&lt;strong&gt;Find all siblings of a given DOM element.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this question we need to return all siblings so they can have same parent or different, but need to be on same level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsghn84pax9fb3qcvdd2p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsghn84pax9fb3qcvdd2p.png" alt="Image description" width="730" height="718"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To solve this question BFS will be the most suitable algorithm. We will do level order traversal and return nodes at current level if targetNode exist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const getRoot = (targetNode )=&amp;gt; {
  let parent = targetNode;
  while(parent.parentElement){
    parent = parent.parentElement;
  }
  return parent;
}

const getSiblings = (targetNode )=&amp;gt; {
  if(!targetNode ) return null;
  const root = getRoot(targetNode);
  const queue= [root, null];
  let nodesAtSameLevel = [];
  let currentLevelIncludeTarget = false;

  while(queue.length &amp;gt; 0){
    const currentN = queue.shift();



    if(currentN === null){
      if(currentLevelIncludeTarget){
        return nodesAtSameLevel;
      }
      nodesAtSameLevel = [];
      if(queue.length) queue.push(null);
    } else {
      if(currentN === targetNode){
         currentLevelIncludeTarget = true;
      } else {
        nodesAtSameLevel.push(currentN);
      }
      queue.push(...currentN.children);
    }
  }
  return [];
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to return only immediate siblings of given node we can get parentNode and then return all its child nodes after removing targetNode.&lt;/p&gt;

&lt;p&gt;Something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 const getSiblings = (node) =&amp;gt; {
  if (!node || !node.parentElement) return [];

  return Array.from(node.parentElement.childNodes).filter((sibling) =&amp;gt; sibling !== node);
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>DOM question #3 Distance between two DOM</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Thu, 20 Feb 2025 17:13:30 +0000</pubDate>
      <link>https://dev.to/shweta/dom-question-3-327o</link>
      <guid>https://dev.to/shweta/dom-question-3-327o</guid>
      <description>&lt;p&gt;&lt;strong&gt;Find the distance (number of edges) between two DOM elements.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9esf4xshu6h87pqmnfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9esf4xshu6h87pqmnfj.png" alt="Image description" width="777" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can get distance between given 2 nodes by calculating LCA and then adding the distance between LCA to these two nodes.&lt;/p&gt;

&lt;p&gt;So we can write code as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getParentList = (node)=&amp;gt;{
   const parentList = [node];
let tempNode = node;
  while(tempNode.parentElement){
    parentList.push(tempNode.parentElement);
      tempNode = tempNode.parentElement;
  }

return parentList;
}

const LCA = (node1, node2)=&amp;gt;{
  const parentList1 = getParentList(node1);
  const parentList2 = getParentList(node2);

   for(let i=0; i&amp;lt;parentList1.length; i++){
       const index2 = parentList2.findIndex(item=&amp;gt; item === parentList1[i]);
       if(index2!==-1){
          return index2 + i;
       }
   }
return -1;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>DOM Challenge #2 nth parent</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Tue, 18 Feb 2025 14:01:01 +0000</pubDate>
      <link>https://dev.to/shweta/dom-challenge-2-b00</link>
      <guid>https://dev.to/shweta/dom-challenge-2-b00</guid>
      <description>&lt;p&gt;Today's question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find the nth parent of a given DOM element.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp8xha6on3rz1rmzhrhnu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp8xha6on3rz1rmzhrhnu.png" alt="Image description" width="800" height="866"&gt;&lt;/a&gt;&lt;br&gt;
If input is Div.6 &amp;amp; n is 2 we should output Div.2&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Considerations&lt;/strong&gt;:&lt;br&gt;
1) What if n &amp;gt; number of parents?&lt;br&gt;
In that case we return null.&lt;br&gt;
2) n &amp;gt; 0&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Get all parentNodes of DOM and return (n-1)th element from array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const parentList = (node)=&amp;gt;{
   let tempNode = node;
   const parentNodes = [];
   while(tempNode.parentElement){
     parentNodes.push(tempNode.parentElement);
    tempNode = tempNode.parentElement;
   }
   return parentNodes;
}

const getNthParent = (node, n) =&amp;gt; {
   const parentNodes = parentList(node);
   if(n &amp;gt; parentNodes.length){
      return parentNodes[n-1];
   }
  return null;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>DOM Challenge - #1 common ancestor</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Mon, 17 Feb 2025 17:16:45 +0000</pubDate>
      <link>https://dev.to/shweta/dom-challenge-1-39jp</link>
      <guid>https://dev.to/shweta/dom-challenge-1-39jp</guid>
      <description>&lt;p&gt;I'm planning to write around 30 posts covering various questions related to DOM traversal, manipulation, and optimization.&lt;/p&gt;

&lt;p&gt;Today's question is related to DOM traversal&lt;/p&gt;

&lt;p&gt;Question:&lt;br&gt;
&lt;strong&gt;Find the common ancestor of two given DOM elements.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this question we have DOM tree and we need to find common ancestor of given nodes. The first approach I can think of is collect all parent nodes of both elements and find the first common node.&lt;/p&gt;

&lt;p&gt;We can get parentNodes using this method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const parentList = (element)=&amp;gt;{
    let el = element;
   const list = [];
    while(true){
        list.push(el);

        if(!el.parentNode) break;
        el = el.parentNode;
    }

    return list;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can use this list to find LCA -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const findLCA = (el1, el2)=&amp;gt;{
    const parentList1 = parentList(el1);
    const parentList2 = parentList(el2);

    for(let i=0; i&amp;lt;parentList1.length; i++){
     if(parentList2.includes(parentList1[i])){
         return parentList1[i];
     } 
    }
    return null;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This solution works, but it has a time complexity of O(n²) due to the includes() check inside the loop.&lt;/p&gt;

&lt;p&gt;We can improve this by using Set to store parent list, so that we can use &lt;code&gt;parentList2.has(parentList1[i])&lt;/code&gt;, this is of O(1) complexity so time complexity for our code will be O(n).&lt;/p&gt;

&lt;p&gt;💡 Note: These posts are primarily for my learning and practice. They are not meant as official guides but might be helpful for someone preparing for interviews.&lt;/p&gt;

</description>
      <category>learning</category>
    </item>
    <item>
      <title>Learning Smart Contract Development using Okashi</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Mon, 19 Aug 2024 06:41:31 +0000</pubDate>
      <link>https://dev.to/shweta/learning-smart-contract-development-using-okashi-4ci4</link>
      <guid>https://dev.to/shweta/learning-smart-contract-development-using-okashi-4ci4</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/stellar"&gt;Build Better on Stellar: Smart Contract Challenge &lt;/a&gt;: Create a Tutorial&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Tutorial
&lt;/h2&gt;

&lt;p&gt;I worked on creating a tutorial that uses Okashi to explain How Stellar Smart Contract work and create different Smart contracts. This tutorial can be accessed here - &lt;a href="https://dev.to/shweta/crafting-stellar-smart-contracts-learn-by-creating-smart-contracts-in-browser-5gg5"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Created
&lt;/h2&gt;

&lt;p&gt;I'm excited to share with you what I've been working on. I've created a beginner-friendly tutorial on Stellar smart contract development using Soroban. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I have included A step-by-step guide covering five different smart contracts, each introducing new concepts:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Basic "Hello World" contract&lt;/li&gt;
&lt;li&gt;Multi-method contract with data storage&lt;/li&gt;
&lt;li&gt;Increment counter with TTL management&lt;/li&gt;
&lt;li&gt;User authentication in smart contracts&lt;/li&gt;
&lt;li&gt;Persistent storage implementation&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;An introduction to the Okashi platform for in-browser smart contract development and testing.&lt;/li&gt;
&lt;li&gt;Explanations of key Stellar-specific concepts like contract instances, Time-To-Live (TTL), and different types of storage (temporary, instance, persistent).&lt;/li&gt;
&lt;li&gt;A walkthrough of the smart contract deployment process on the Stellar testnet.&lt;/li&gt;
&lt;li&gt;Visual aids including screenshots and diagrams to enhance understanding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope that this tutorial will help other developers like me to:&lt;br&gt;
 -Get started with Soroban without feeling overwhelmed&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand when to use different types of storage (trust me, it matters!)&lt;/li&gt;
&lt;li&gt;Learn best practices through real-world examples&lt;/li&gt;
&lt;li&gt;Feel confident deploying your first smart contract&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Journey
&lt;/h2&gt;

&lt;p&gt;Creating this tutorial has been quite the adventure! &lt;/p&gt;

&lt;p&gt;When I first started learning about Stellar smart contracts, I found the existing resources a bit scattered. I thought to myself, "Wouldn't it be great if there was a guide that took you from absolute beginner to deploying your first contract?" So, I decided to create the guide I wish I had when I was starting out. It helps in understanding basic concepts without doing any local setup.&lt;/p&gt;

&lt;p&gt;I spent a lot of time experimenting with the Okashi. It's such a great tool for learning – being able to test your contract instantly is a game-changer. I wanted to make sure I showcased its capabilities in the tutorial.&lt;/p&gt;

&lt;p&gt;Creating each example contract was a learning experience in itself. I'd write a contract, test it, realize I misunderstood something, and then revise. It was a cycle of continuous learning, which I've tried to distill into the tutorial.&lt;/p&gt;

&lt;p&gt;Through this process, I've gained a much deeper understanding of Soroban and the Stellar ecosystem. Looking ahead, I'm excited to dive even deeper. I'm thinking about creating more advanced tutorials – maybe something on cross-contract calls or integrating with frontend apps.&lt;/p&gt;

&lt;p&gt;This journey helped me to be a bit more confident on web3 development and Stellar. When I started writing this tutorial, I had lot's of confusion like how is backend handled? where is data stored? how can we interact with it? and more silly questions 😂&lt;/p&gt;

&lt;p&gt;I'm proud that I can now write a contract and understand different contracts that I come across on github or community.&lt;/p&gt;

&lt;p&gt;I would like to give credit to Stella, she was life saver for me. This tutorial is written because she helped me in clarifying all doubts I had as a beginner.&lt;/p&gt;

&lt;p&gt;I hope my tutorial helps smooth the path for other new developers entering this exciting space. Happy coding, everyone!&lt;/p&gt;

&lt;p&gt;Thank you and hope you give the tutorial a read too, here's the link - &lt;a href="https://dev.to/shweta/crafting-stellar-smart-contracts-learn-by-creating-smart-contracts-in-browser-5gg5"&gt;https://dev.to/shweta/crafting-stellar-smart-contracts-learn-by-creating-smart-contracts-in-browser-5gg5&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>stellarchallenge</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Crafting Stellar Smart Contracts: Learn by creating Smart Contracts in browser</title>
      <dc:creator>Shweta Kale</dc:creator>
      <pubDate>Mon, 19 Aug 2024 06:19:38 +0000</pubDate>
      <link>https://dev.to/shweta/crafting-stellar-smart-contracts-learn-by-creating-smart-contracts-in-browser-5gg5</link>
      <guid>https://dev.to/shweta/crafting-stellar-smart-contracts-learn-by-creating-smart-contracts-in-browser-5gg5</guid>
      <description>&lt;p&gt;Hey there!👋 Thank you for opening this blog, its my attempt to help everyone understand stellar blockchain as I learn the concepts.&lt;br&gt;
By end of this blog, we'll have built five smart contract, right in your browser. No complicated setup, no downloads, - just you, this blog, and some code. Let's get started!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixjtwuk1n44roh65aq2g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixjtwuk1n44roh65aq2g.png" alt="What we will learn" width="800" height="1131"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What's a Smart Contract Anyway?
&lt;/h2&gt;

&lt;p&gt;Imagine a vending machine. You put in a coin, press a button, and out comes your snack. Now, picture that vending machine running on a blockchain, handling not just snacks, but any kind of digital transaction you can think of. That's essentially what Smart Contract does!&lt;/p&gt;

&lt;p&gt;In technical terms, a smart contract is a self executing program that lives on blockchain. It automatically makes things happen when certain conditions are met. Here's why this is cool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;They're Transparent:&lt;/strong&gt; Everyone can see the rules (i.e the code and associated transactions), so there are no surprises.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They're Trustworthy:&lt;/strong&gt; Once a smart contract is deployed on blockchain, it can't be changed. What you see is what you get😄&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They're Efficient:&lt;/strong&gt; They cut out middlemen, making transactions faster and cheaper.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They're Permissionless:&lt;/strong&gt; Anyone can write a smart contract and deploy it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, Stellar has its own flavor of smart contract, and that's what we are going to learn today. Stellar's smart contract platform is called Sorban, and its designed to be simple, fast, and developer-friendly.&lt;/p&gt;

&lt;p&gt;The best part? We are going to write this smart contract in Rust on Browser, to do that we are going to use Okashi platform. Don't worry if you are new to Rust - we'll cover everything you need to know.&lt;/p&gt;
&lt;h2&gt;
  
  
  Rust basics for Stellar Smart Contract
&lt;/h2&gt;

&lt;p&gt;For writing Stellar Smart Contracts we make use of Rust. Rust is a systems programming language that emphasizes safety, concurrency, and performance. Here are some key Rust concepts you'll frequently use in Soroban development:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structs:&lt;/strong&gt; Define custom data types, similar to classes in other languages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;struct&lt;/span&gt; &lt;span class="nx"&gt;MyStruct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;field1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Type1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;field2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Type2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Impl Blocks:&lt;/strong&gt; Used to implement methods for Structs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;impl&lt;/span&gt; &lt;span class="nx"&gt;MyStruct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;my_method&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// method body&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Functions:&lt;/strong&gt; Defined using the fn keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arg1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Method body&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Attributes:&lt;/strong&gt; Metadata applied to code elements, starting with #&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;struct&lt;/span&gt; &lt;span class="nx"&gt;MyStruct&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are just four basic ... related to Rust that we need to know to get started.&lt;/p&gt;

&lt;h1&gt;
  
  
  Sorban Structure, Data Type and Imports
&lt;/h1&gt;

&lt;p&gt;Soroban is Stellar's smart contract platform. It uses Rust with some specific structures and types that includes:&lt;br&gt;
&lt;strong&gt;1. No Standard Library:&lt;/strong&gt;&lt;br&gt;
Sorban Contracts typically start with &lt;code&gt;#![no_std]&lt;/code&gt; to indicate they don't use Rust standard library. We do this to make smart contract smaller and more efficient.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="c1"&gt;// Now we're writing a lean, Stellar-ready contract!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Importing Sorban SDK:&lt;/strong&gt;&lt;br&gt;
We need to bring in special Stellar tools. We do this by importing from the Stellar SDK.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;sorban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;// Now we've access to Stellar specific features.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Contract Structure:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Contract are defined as Struct with the &lt;code&gt;#[contract]&lt;/code&gt; attribute.&lt;/li&gt;
&lt;li&gt;Functions are implemented in an &lt;code&gt;impl&lt;/code&gt; block with the &lt;code&gt;#[contractimpl]&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;ContractName&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;ContractName&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Important Data Types:&lt;/strong&gt;&lt;br&gt;
a) Env&lt;br&gt;
Env is like smart contract's connection to Stellar World. It let's us access storage, call other imports and more.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;sorban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;my_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;current_ledger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.ledger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.sequence&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b) Symbol&lt;br&gt;
Symbol is a special, efficient type for short strings. It is often used as keys in storage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;sorban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_symbol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;symbol!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c) String&lt;br&gt;
This is similar to Rust's standard String, but optimized for Sorban&lt;/p&gt;

&lt;p&gt;d) SymbolShort&lt;br&gt;
This is a way to create Symbols at compile-time, which is even more efficient.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use soroban_sdk::{symbol_short};

const MY_KEY: Symbol = symbol_short!("key");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was just an overview, to get you familiar with the terms and syntax. Don't worry if you didn't understood the keywords and its usage. By end of this tutorial you definitely will.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our First Smart Contract
&lt;/h2&gt;

&lt;p&gt;Now that we have basic understanding, let's write our "Hello World" contract step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: The Contract Structure -
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;soroban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contractimpl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;HelloContract&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;HelloContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// We'll add our functions here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We start with &lt;code&gt;#![no_std]&lt;/code&gt; to indicate we're not using the standard library.&lt;/li&gt;
&lt;li&gt;We import necessary items from &lt;code&gt;soroban_sdk&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We define our contract &lt;code&gt;struct HelloContract&lt;/code&gt; and mark it with &lt;code&gt;#[contract]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We start an implementation block for &lt;code&gt;HelloContract&lt;/code&gt; and mark it 
with &lt;code&gt;#[contractimpl]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Its all same thing that we learned above, we have just put the blocks together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Implementing the method
&lt;/h3&gt;

&lt;p&gt;The code we saw above was just structure, without including any public function in it the code does not have any meaning even if we deploy it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt; &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;greeting_from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Hello, I'm "&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We created a public function called &lt;code&gt;greeting_from&lt;/code&gt; which has two arguments - &lt;code&gt;Env&lt;/code&gt; and &lt;code&gt;from&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-&amp;gt; Vec&amp;lt;String&amp;gt;&lt;/code&gt; signifies that we are returning a vector of type &lt;code&gt;String&lt;/code&gt;, with text "Hello, I'm " and  input user entered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Putting it together we will have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;soroban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contractimpl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;HelloContract&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;HelloContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;greeting_from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Hello, I'm "&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Running Smart Contract on Okashi
&lt;/h3&gt;

&lt;p&gt;Okashi is a place where we can experiment with our stellar smart contract in browser, so no need to setup any code locally.&lt;br&gt;
It's like a digital workspace with three main sections:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code Window:&lt;/strong&gt; Where we will write our smart contract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contract Window:&lt;/strong&gt; Calling the functions from our smart contract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Console Window:&lt;/strong&gt; Show us result of our experiment, i.e output.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8lcarkafh68gelfi3lp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8lcarkafh68gelfi3lp.png" alt="Okashi.dev" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To try the code we wrote &lt;br&gt;
a) Go to &lt;a href="https://okashi.dev/playground" rel="noopener noreferrer"&gt;Okashi.dev&lt;/a&gt; playground.&lt;br&gt;
b) Paste the code in code section.&lt;br&gt;
c) Click on Compile.&lt;br&gt;
d) In the contract window you should see a method &lt;code&gt;greeting_from&lt;/code&gt;, click on it and enter input in modal.&lt;br&gt;
e) You will see the output in the Console window.&lt;/p&gt;

&lt;p&gt;You can also see the output in this &lt;a href="https://okashi.dev/playground/bmocpjqucvlculytjpkplyqleycb" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;br&gt;
Congratulations!🎉 You've just written your first Soroban smart contract in Rust.&lt;/p&gt;
&lt;h2&gt;
  
  
  Second Smart Contract - Creating multiple methods in one contract.
&lt;/h2&gt;

&lt;p&gt;For our second smart contract we will work on creating more that one method in contract and learn how to access it.&lt;/p&gt;

&lt;p&gt;Let's try creating a new smart contract &lt;code&gt;TitleContract&lt;/code&gt; which has two methods&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;set_title:&lt;/code&gt; Get's input from user and save the title.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;get_title:&lt;/code&gt; Returns input user entered.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Step 1: Basic structure
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;soroban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contractimpl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symbol_short&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;


&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;TitleContract&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;TitleContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;set_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;get_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As mentioned in task we have two methods &lt;code&gt;get_title&lt;/code&gt; and &lt;code&gt;set_title&lt;/code&gt;, the structure is similar to first contract.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Implementing the methods
&lt;/h3&gt;

&lt;p&gt;Before we implement the method we need to understand basics of data storage in stellar smart contract. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Smart Contract Storage in Stellar&lt;/strong&gt;:&lt;br&gt;
Smart contract storage in Stellar is designed to accommodate a wide range of uses affordably. It's primarily used for storing data related to the state and functionality of smart contracts deployed on the Soroban platform.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To store the data we need to have a key using which we can identify the data stored to use it.&lt;/li&gt;
&lt;li&gt;Data in storage can be set using &lt;code&gt;set&lt;/code&gt; method and retrieved using &lt;code&gt;get&lt;/code&gt; method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Stellar we have three type of storage&lt;br&gt;
&lt;strong&gt;a) Temporary Storage&lt;/strong&gt; - Temporary storage is ideal for data that is only needed for a short period and can be discarded afterwards without consequences. It's the cheapest option but has a limited lifespan.&lt;/p&gt;

&lt;p&gt;Example: A contract that stores the recent price of BTC against USD.&lt;/p&gt;

&lt;p&gt;Can be accessed using -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// save the VALUE in temporary storage using set with key as KEY&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.temporary&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;VALUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// get the VALUE from temporary storage using key, KEY&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.temporary&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;b) Persistent Storage&lt;/strong&gt; - Persistent storage is used for long-term data storage. When the TTL (Time to Live) reaches zero, the data is archived rather than deleted and can be restored when needed.&lt;/p&gt;

&lt;p&gt;Example: A loyalty points system where users accumulate points.&lt;/p&gt;

&lt;p&gt;Can be accessed using -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// save the VALUE in persistent storage using set with key as KEY&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.persistent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;VALUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// get the VALUE from persistent storage using key, KEY&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.persistent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;c) Instance Storage&lt;/strong&gt; - Instance storage is a type of storage that is tied directly to the contract instance itself. &lt;/p&gt;

&lt;p&gt;Example: A voting system where each contract instance represents a unique vote.&lt;/p&gt;

&lt;p&gt;Can be accessed using -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// save the VALUE in instance storage using set with key as KEY&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;VALUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// get the VALUE from instance storage using key, KEY&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will understand this more in next examples, For this example we will use instance storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating Key for Storage in our contract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will create key, TITLE to access instance storage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;TITLE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;symbol_short!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Saving and Retrieving Title data&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// set_title&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;TITLE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// get_title&lt;/span&gt;
&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;TITLE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"No Title Set"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above code we are setting instance storage with key TITLE&lt;br&gt;
We are retrieving it using &lt;code&gt;get()&lt;/code&gt; and if no value is present we return a default title &lt;em&gt;"No Title Set"&lt;/em&gt; using &lt;code&gt;unwrap_or&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Putting it together
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#![no_std]
use soroban_sdk::{contract, contractimpl, symbol_short, Env, Symbol, String};

const TITLE: Symbol = symbol_short!("title");

#[contract]
pub struct TitleContract;

#[contractimpl]
impl TitleContract {
    pub fn set_title(env: Env, title: String) {
        env.storage().instance().set(&amp;amp;TITLE, &amp;amp;title);
    }

    pub fn get_title(env: Env) -&amp;gt; String {
        env.storage().instance().get(&amp;amp;TITLE).unwrap_or(String::from_str(&amp;amp;env, "No title set"))
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;In above code &lt;code&gt;set_title&lt;/code&gt; accepts argument called title and sets it with instance storage.&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;get_title&lt;/code&gt; we retrieve the key and return the value present, if value is not present we return default value.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Step 4: Testing code in Okashi.dev
&lt;/h3&gt;

&lt;p&gt;Paste the code in Okashi playground and click on Compile.&lt;br&gt;
The contract window should have two methods.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you click on &lt;code&gt;get_title&lt;/code&gt; you should see default value in console.&lt;/li&gt;
&lt;li&gt;Now set title by clicking on &lt;code&gt;set_title&lt;/code&gt; and click on &lt;code&gt;get_title&lt;/code&gt;. You should see the title you entered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yep, that's it. We have our second smart contract working fine. I know you might have some doubt about storage, different types available and why did we select instance storage. I've been there too, it would be much clearer before we end this blog, so for now let us keep basic in mind - Smart contract have three type of storage - In our &lt;code&gt;TitleContract&lt;/code&gt;, we used instance as we only want to use it till the contract instance is active.&lt;/p&gt;

&lt;p&gt;You can try the code here: &lt;a href="https://okashi.dev/playground/btpyseknmnjmhfedbrxilgirhnvo" rel="noopener noreferrer"&gt;https://okashi.dev/playground/btpyseknmnjmhfedbrxilgirhnvo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations!🎉 We have worked on creating smart contract with two methods and learned about different types of smart contract storage and used instance storage.&lt;/p&gt;
&lt;h2&gt;
  
  
  Our Third Smart Contract
&lt;/h2&gt;

&lt;p&gt;Let us create a new smart contract that use &lt;code&gt;instance storage&lt;/code&gt; to increment counter. &lt;/p&gt;

&lt;p&gt;You need to create a new Smart Contract - &lt;code&gt;IncrementCounterContract&lt;/code&gt;. This contract should have one public method called as increment and a key which you will use for saving and retrieving data from instance storage &lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Coding the contract
&lt;/h3&gt;

&lt;p&gt;This part is similar to second contract we wrote, so let's create contract, it should be a good revision for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;soroban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contractimpl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symbol_short&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;symbol_short!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COUNTER"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Increment the count.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Save the count.&lt;/span&gt;
        &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Return the count to the caller.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above code we have method increment, which return integer value, i.e count.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 Understanding contract instance and TTL
&lt;/h3&gt;

&lt;p&gt;Well, the contract we wrote above is fine but with instance storage, the contract storage and its instance have default lifetime determined by network's minimum time to live(TTL) for contract's instance.&lt;/p&gt;

&lt;p&gt;To handle that we need to extend the time to live (TTL) for the instance storage. Before doing that let's first understand technical terms I mentioned above&lt;/p&gt;

&lt;h4&gt;
  
  
  Contract Instance:
&lt;/h4&gt;

&lt;p&gt;A contract instance refers to a deployed smart contract on the Stellar network. When you deploy a contract, you're creating an instance of that contract on the blockchain. This instance has its own unique identifier and can maintain its own state.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
Let's say you deploy a token contract. This deployed contract becomes an instance, and it can have its own storage, including things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The token's name&lt;/li&gt;
&lt;li&gt;Total supply&lt;/li&gt;
&lt;li&gt;Administrator address&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Time To Live (TTL)
&lt;/h4&gt;

&lt;p&gt;Contract instances on Stellar have an archival TTL (Time-To-Live) that determines how long they remain active. This TTL is tied to the contract instance itself.&lt;/p&gt;

&lt;p&gt;A contract instance becomes inactive when its TTL expires. However, it's important to note that the TTL can be extended to keep the contract instance active for a longer period.&lt;/p&gt;

&lt;p&gt;We are using &lt;em&gt;Instance Storage&lt;/em&gt;. As we discussed above anything stored in instance storage has an archival TTL that is tied to the contract instance itself. So, if a contract is live and available, the instance storage is guaranteed to be so, too.&lt;/p&gt;

&lt;p&gt;Now, we will learn how to prevent instance storage from expiring and extend its TTL&lt;/p&gt;
&lt;h4&gt;
  
  
  Extending Instance Storage TTL
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.extend_ttl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This line of code is used to extend the Time-To-Live (TTL) of the contract's instance storage. Here's how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It extends the TTL by 50 ledgers.&lt;/li&gt;
&lt;li&gt;It sets a minimum TTL of 100 ledgers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What this means:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the current TTL is less than 100 ledgers, it will be set to 100.&lt;/li&gt;
&lt;li&gt;If the current TTL is already 100 or more, it will be extended by 50 ledgers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This operation ensures that the contract instance and its associated instance storage remain active and accessible for at least the specified number of ledgers.&lt;/p&gt;

&lt;p&gt;To summarize:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Contract instances become inactive when their TTL expires.&lt;/li&gt;
&lt;li&gt;The TTL is tied to the contract instance and its associated data.&lt;/li&gt;
&lt;li&gt;Developers can extend the TTL to keep contract instances active for longer periods.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By managing the TTL, developers can control how long their contract instances remain active on the Stellar blockchain.&lt;/p&gt;

&lt;p&gt;Let's add relevant code in our contract&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;soroban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contractimpl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symbol_short&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;


&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;symbol_short!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COUNTER"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/// Increment increments an internal counter, and returns the value.&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Get the current count.&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// If no value set, assume 0.&lt;/span&gt;
        &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"count: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Increment the count.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Save the count.&lt;/span&gt;
        &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// The contract instance will be bumped to have a lifetime of at least 100 ledgers if the current expiration lifetime at most 50.&lt;/span&gt;
        &lt;span class="c1"&gt;// If the lifetime is already more than 100 ledgers, this is a no-op. Otherwise,&lt;/span&gt;
        &lt;span class="c1"&gt;// the lifetime is extended to 100 ledgers. This lifetime bump includes the contract&lt;/span&gt;
        &lt;span class="c1"&gt;// instance itself and all entries in storage().instance(), i.e, COUNTER.&lt;/span&gt;
        &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.extend_ttl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Return the count to the caller.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can access the code in this playground -&lt;br&gt;
&lt;a href="https://okashi.dev/playground/bcjohutecdojquhnafveonzkttxk" rel="noopener noreferrer"&gt;https://okashi.dev/playground/bcjohutecdojquhnafveonzkttxk&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Compiling the contract
&lt;/h3&gt;

&lt;p&gt;Simply copy paste the code in Okashi playground, and click on Compile.&lt;br&gt;
Vola!! You can test your increment counter and it should work just fine.&lt;/p&gt;

&lt;p&gt;Try reloading the playground, and run the method again. Counter starts from zero. Why? because we did not deploy the contract and its running in a mock environment.&lt;/p&gt;

&lt;p&gt;Well we did compile this and all our previous smart contract. Does that mean its available on blockchain?&lt;br&gt;
Not really, To make it available on blockchain we will deploy it on testnet. Let's do that in next step.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4: Deploying Smart Contract on Okashi
&lt;/h3&gt;

&lt;p&gt;Did we not deploy our contract earlier?&lt;br&gt;
No, Okashi allows you to run and test your contract locally without deploying it to the actual network. This is incredibly useful for development and testing purposes.&lt;/p&gt;

&lt;p&gt;What does it mean that we deploy our contract?&lt;br&gt;
Deploying a contract means uploading your smart contract code to the blockchain and making it available for interaction. It's essentially the process of putting your contract "live" on the network. Here's what happens when you deploy a contract:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The contract's compiled WebAssembly (Wasm) code is uploaded to the network.&lt;/li&gt;
&lt;li&gt;A unique contract ID is generated for your deployed contract.&lt;/li&gt;
&lt;li&gt;The contract becomes accessible and can be interacted with by users or other contracts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Deployment in Sorban&lt;/strong&gt;&lt;br&gt;
In Sorban deployment is typically a two-step process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install: This install the contract's WASM bytecode to the network.&lt;/li&gt;
&lt;li&gt;Deploy: This creates instance of contract with unique contract ID.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnc92jmhiwbww4j49vs70.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnc92jmhiwbww4j49vs70.png" alt="Okashi deploy" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To deploy smart contract on testnet simply click on settings icon in left panel and select testnet as shown in above image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdjfb27kw974j8oxl4vjb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdjfb27kw974j8oxl4vjb.png" alt="Deploy smart contract" width="800" height="634"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hurray!!! Now we have completed 3 contracts, and learned to deploy it on the network so that even other users can interact with it.&lt;br&gt;
All this in browser. Isn't that great??&lt;/p&gt;
&lt;h2&gt;
  
  
  Our Fourth Smart Contract - User Authentication
&lt;/h2&gt;

&lt;p&gt;Picture this, instead of increment counter you have a balance book where balance increase and decrease. We only have one balance so anyone who run this method the balance will be affected. Huhh, so everyone has a common balance? That's not correct right?&lt;/p&gt;

&lt;p&gt;To handle this we will use user authentication to our increment counter code. &lt;/p&gt;

&lt;p&gt;In stellar we can use &lt;code&gt;user.require_auth()&lt;/code&gt; to make sure user has authenticated the transaction. &lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Adding &lt;code&gt;require_auth&lt;/code&gt; in code
&lt;/h3&gt;

&lt;p&gt;a) Update imports from sdk to import &lt;code&gt;Address&lt;/code&gt;.&lt;br&gt;
b) Accept one more argument from &lt;code&gt;increment&lt;/code&gt; method called user of type Address.&lt;br&gt;
c) Add &lt;code&gt;user.require_auth()&lt;/code&gt; before we perform any computation or updates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt; &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="nf"&gt;.require_auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// other code remain same&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can access code here - &lt;a href="https://okashi.dev/playground/buscouoocaofizhsoeddwufiiwke" rel="noopener noreferrer"&gt;https://okashi.dev/playground/buscouoocaofizhsoeddwufiiwke&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What does this mean? It means that whenever increment is called, user is authenticating to make the change. &lt;/p&gt;

&lt;p&gt;d) Compile contract and run the increment method. You will notice that you have a new field as input -&amp;gt; some user options.&lt;br&gt;
Select one user, Alex and &lt;em&gt;click on call&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkivfnql2075sw4i57vu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkivfnql2075sw4i57vu9.png" alt="Okashi compile" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, our code complied successfully and we have output. Are we done?&lt;br&gt;
No not at all, we just implemented user authentication. All the data is stored in same key. If you try calling increment again, this time select Bart. The value is updated with count Alex had. We don't want this to happen!!&lt;/p&gt;

&lt;p&gt;To handle this we need unique key for each user. Let's do that in second step.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Adding unique key for each user
&lt;/h3&gt;

&lt;p&gt;Instead of having a same key, i.e COUNTER. Let's use User's address as a key to store the increments. We can do that by replacing current key with &lt;code&gt;&amp;amp;user.clone()&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;.clone()&lt;/code&gt; is called on user to create a new copy of the address. This is necessary if user is not owned by this part of the code or if it needs to be used elsewhere after this operation.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;        &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is complete code for your reference&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;soroban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contractimpl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/// Increment increments an internal counter, and returns the value.&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="nf"&gt;.require_auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Get the current count.&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// If no value set, assume 0.&lt;/span&gt;
        &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"count: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Increment the count.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Save the count.&lt;/span&gt;
        &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.instance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


        &lt;span class="c1"&gt;// Return the count to the caller.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Compile and deploy the code
&lt;/h3&gt;

&lt;p&gt;You can use Okashi to test the code and check if it works fine.&lt;br&gt;
If you call increment from one user, Alex, it should not affect value stored in other user.&lt;br&gt;
You can access the code here- &lt;a href="https://okashi.dev/playground/asuxzxwasubvfypwzyqhaqyfgywz" rel="noopener noreferrer"&gt;https://okashi.dev/playground/asuxzxwasubvfypwzyqhaqyfgywz&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Our Fifth Smart Contract
&lt;/h2&gt;

&lt;p&gt;This is last contract we are going to discuss for this blog. &lt;br&gt;
Till now we &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;understood smart contract structure&lt;/li&gt;
&lt;li&gt;Learned three type of smart contract storage&lt;/li&gt;
&lt;li&gt;used instance storage to implement increment counter and title contract&lt;/li&gt;
&lt;li&gt;Learned about Contract instance and TTL.&lt;/li&gt;
&lt;li&gt;Learned how to use authentication in contract&lt;/li&gt;
&lt;li&gt;Deployed our contract on Testnet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's a lot we covered in this blog, but I'm sure you are still confused between instance storage and persistent storage.&lt;br&gt;
This is our chance to understand proper difference between these two.&lt;/p&gt;

&lt;p&gt;In our fourth smart contract we used user authentication, so many users can use same contract and each will have their separate counter as we have unique key. Everything seems to be correct right? &lt;br&gt;
Not exactly, this works but in this case we can use persistent storage as&lt;br&gt;
instance storage wouldn't work well for this use case:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a) Limited Storage&lt;/strong&gt;: Instance storage has a limited amount of space. With a growing number of users, you could quickly run out of storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b) Performance Impact&lt;/strong&gt;: Every piece of data stored in instance() storage is retrieved from the ledger every time the contract is invoked. Even if the invoked function does not interact with any ledger data at all.&lt;br&gt;
This means that as your user base grows, contract invocations would become increasingly expensive and slower, as all counts would be loaded each time. &lt;/p&gt;

&lt;p&gt;Persistent storage is ideal for this scenario because it allows for efficient storage and retrieval of individual user data, scales well with a growing user base, and ensures data availability regardless of the contract instance's active status.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dui7ldrbirpx0pq9osk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dui7ldrbirpx0pq9osk.png" alt="Storage type difference" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Converting our code to use persistent storage is easy, you just need to replace instance storage with persistent storage and its done.&lt;br&gt;
Here is complete code for your reference -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#![no_std]&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;soroban_sdk&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;contractimpl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symbol_short&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;


&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;symbol_short!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COUNTER"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nd"&gt;#[contract]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;#[contractimpl]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;IncrementContract&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/// Increment increments an internal counter, and returns the value.&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="nf"&gt;.require_auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Get the current count.&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.persistent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// If no value set, assume 0.&lt;/span&gt;
        &lt;span class="k"&gt;log&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"count: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Increment the count.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Save the count.&lt;/span&gt;
        &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="nf"&gt;.storage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.persistent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;COUNTER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


        &lt;span class="c1"&gt;// Return the count to the caller.&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can try the code here- &lt;a href="https://okashi.dev/playground/caavrhvfctirmkryboblgxkwxshl" rel="noopener noreferrer"&gt;https://okashi.dev/playground/caavrhvfctirmkryboblgxkwxshl&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That was a longest blog I have ever written, and I really learned a lot of stuff while writing this blog.&lt;/p&gt;

&lt;p&gt;In this blog we learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The basics of smart contracts and their importance in blockchain technology&lt;/li&gt;
&lt;li&gt;Fundamental Rust concepts used in Soroban development&lt;/li&gt;
&lt;li&gt;How to structure Soroban smart contracts&lt;/li&gt;
&lt;li&gt;Different types of storage in Stellar smart contracts (temporary, persistent, instance)&lt;/li&gt;
&lt;li&gt;How to implement multiple methods within a single contract&lt;/li&gt;
&lt;li&gt;The concept of contract instances and Time To Live (TTL)&lt;/li&gt;
&lt;li&gt;How to use user authentication in smart contracts&lt;/li&gt;
&lt;li&gt;The process of deploying smart contracts on the Stellar testnet&lt;/li&gt;
&lt;li&gt;When to use persistent vs instance storage for scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbc1xlewj5ugyrpr5pdm6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbc1xlewj5ugyrpr5pdm6.png" alt="Contract Recap" width="800" height="1131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this knowledge, we can start working on more complex Stellar smart contracts, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Token systems&lt;/li&gt;
&lt;li&gt;Decentralized exchanges&lt;/li&gt;
&lt;li&gt;Voting systems&lt;/li&gt;
&lt;li&gt;Multi-signature wallets&lt;/li&gt;
&lt;li&gt;Cross-chain atomic swaps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The examples we explored were adapted from &lt;a href="https://github.com/stellar/soroban-examples" rel="noopener noreferrer"&gt;https://github.com/stellar/soroban-examples&lt;/a&gt;, which is an excellent resource for further learning and experimentation.&lt;/p&gt;

&lt;p&gt;This tutorial aimed to provide a solid foundation for beginners to start their journey into Stellar smart contract development. Would love to hear your feedback and thoughts!&lt;/p&gt;

&lt;p&gt;Remember, the best way to learn is by doing. So don't hesitate to experiment with the concepts we've covered, modify the example contracts, and create your own unique smart contracts on the Stellar network. Happy coding!&lt;/p&gt;

</description>
      <category>stellarchallenge</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
