<?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: Abhiram A</title>
    <description>The latest articles on DEV Community by Abhiram A (@abhiramelf).</description>
    <link>https://dev.to/abhiramelf</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%2F293299%2Fe77f2b25-ee45-470c-b3b5-c5f16cbb90a7.jpeg</url>
      <title>DEV Community: Abhiram A</title>
      <link>https://dev.to/abhiramelf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhiramelf"/>
    <language>en</language>
    <item>
      <title>Get from Zero to Hero in Foundry - Part 2: Deploy &amp; Interact</title>
      <dc:creator>Abhiram A</dc:creator>
      <pubDate>Sun, 10 Aug 2025 15:34:07 +0000</pubDate>
      <link>https://dev.to/abhiramelf/get-from-zero-to-hero-in-foundry-part-2-deploy-interact-2ea4</link>
      <guid>https://dev.to/abhiramelf/get-from-zero-to-hero-in-foundry-part-2-deploy-interact-2ea4</guid>
      <description>&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;In the last part, we saw how to setup Foundry in our systems. We created a simple Counter contract project, compiled it and tested it all using the &lt;code&gt;forge&lt;/code&gt; command&lt;/p&gt;

&lt;p&gt;Please read it if you haven't already before continuing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://dev.to/abhiramelf/get-from-zero-to-hero-in-foundry-part-1-getting-started-57h8"&gt;Foundry: Zero to Hero - Part 1&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn Web3 through live and interactive challenges at &lt;a href="https://www.web3compass.xyz/" rel="noopener noreferrer"&gt;Web3Compass&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Today's Outcome
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tool of focus: &lt;code&gt;anvil&lt;/code&gt; &amp;amp; &lt;code&gt;cast&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Write a Greeting.sol contract&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compile &amp;amp; Test it using &lt;code&gt;forge&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simulate a local blockchain using &lt;code&gt;anvil&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deploy to the local blockchain using &lt;code&gt;forge&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interact with the deployed contract using &lt;code&gt;cast&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Alright, let's dive in!&lt;/em&gt;&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%2Fcxqh15wnltpn9ypgxhxu.gif" 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%2Fcxqh15wnltpn9ypgxhxu.gif" alt="Dive In" width="287" height="498"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ Building the Contract
&lt;/h2&gt;

&lt;p&gt;In a new folder let's use the &lt;code&gt;forge&lt;/code&gt; command to initialize our Greeting contract project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;forge init Greeting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll now have a folder named &lt;code&gt;Greeting&lt;/code&gt; with all the necessary project files.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 Writing the Contract
&lt;/h3&gt;

&lt;p&gt;Inside the &lt;code&gt;src&lt;/code&gt; folder we'll see that the contract file is corresponding to the &lt;code&gt;Counter&lt;/code&gt; contract. This will always be the case when we initialize a new project using &lt;code&gt;forge&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's go ahead and change it to our Greeting contract&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/abhiramelf/15-days-of-foundry/blob/main/day-2/Greeting/src/Greeting.sol" rel="noopener noreferrer"&gt;Greeting.sol Contract&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The contract let's us set a state variable to whatever greeting message we desire and retrieve the stored message through a function call&lt;/p&gt;

&lt;h3&gt;
  
  
  🔬 Compile &amp;amp; Test the Contract
&lt;/h3&gt;

&lt;p&gt;Let's do the same with &lt;code&gt;test&lt;/code&gt; folder&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/abhiramelf/15-days-of-foundry/blob/main/day-2/Greeting/test/Greeting.t.sol" rel="noopener noreferrer"&gt;Greeting.t.sol Test File&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To compile and test the contract, let's go ahead and run the command&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;forge &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Our Greeting.sol contract is now compiled and tested, ready to be Deployed!&lt;/em&gt;&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%2Fs3p7di1ikrfld0uy6cwp.gif" 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%2Fs3p7di1ikrfld0uy6cwp.gif" alt="Let's Do This" width="498" height="372"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Deploying the Contract
&lt;/h2&gt;

&lt;p&gt;Deploying our contract is a two step process&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;anvil&lt;/code&gt; to simulate a local blockchain&lt;/li&gt;
&lt;li&gt;Deploy to it using an account &lt;code&gt;anvil&lt;/code&gt; provides&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Spinning up a local blockchain
&lt;/h3&gt;

&lt;p&gt;All we have to do here is spin up a new instance of terminal and run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;anvil
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we have a local blockchain running in our system with sample wallets to do transactions from&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; anvil


                             _   _
                            &lt;span class="o"&gt;(&lt;/span&gt;_&lt;span class="o"&gt;)&lt;/span&gt; | |
      __ _   _ __   __   __  _  | |
     / _&lt;span class="sb"&gt;`&lt;/span&gt; | | &lt;span class="s1"&gt;'_ \  \ \ / / | | | |
    | (_| | | | | |  \ V /  | | | |
     \__,_| |_| |_|   \_/   |_| |_|

    1.2.3-stable (a813a2cee7 2025-06-08T15:42:40.147013149Z)
    https://github.com/foundry-rs/foundry

Available Accounts
==================

(0) 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000.000000000000000000 ETH)
(1) 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000.000000000000000000 ETH)
(2) 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC (10000.000000000000000000 ETH)
(3) 0x90F79bf6EB2c4f870365E785982E1f101E93b906 (10000.000000000000000000 ETH)
(4) 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 (10000.000000000000000000 ETH)
(5) 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc (10000.000000000000000000 ETH)
(6) 0x976EA74026E726554dB657fA54763abd0C3a0aa9 (10000.000000000000000000 ETH)
(7) 0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 (10000.000000000000000000 ETH)
(8) 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f (10000.000000000000000000 ETH)
(9) 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 (10000.000000000000000000 ETH)

Private Keys
==================

(0) 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
(1) 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
(2) 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
(3) 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
(4) 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a
(5) 0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
(6) 0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
(7) 0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356
(8) 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
(9) 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6

Wallet
==================
Mnemonic:          test test test test test test test test test test test junk
Derivation path:   m/44'&lt;/span&gt;/60&lt;span class="s1"&gt;'/0'&lt;/span&gt;/0/


Chain ID
&lt;span class="o"&gt;==================&lt;/span&gt;

31337

Base Fee
&lt;span class="o"&gt;==================&lt;/span&gt;

1000000000

Gas Limit
&lt;span class="o"&gt;==================&lt;/span&gt;

30000000

Genesis Timestamp
&lt;span class="o"&gt;==================&lt;/span&gt;

1754829094

Genesis Number
&lt;span class="o"&gt;==================&lt;/span&gt;

0

Listening on 127.0.0.1:8545
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let's Deploy
&lt;/h3&gt;

&lt;p&gt;With our local blockchain running and providing us dummy wallets with test ETH, only think left to do is deploy out contract to it&lt;/p&gt;

&lt;p&gt;Each deployment is considered as a transaction on the blockchain. And for a transaction to happen it needs to be initiated from an address in the blockchain. Hence, we need to use a wallet's &lt;strong&gt;Private Key&lt;/strong&gt; provided by &lt;code&gt;anvil&lt;/code&gt; in the previous step&lt;/p&gt;

&lt;p&gt;Cool, let's deploy&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;forge create Greeting &lt;span class="nt"&gt;--interactive&lt;/span&gt; &lt;span class="nt"&gt;--broadcast&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;forge create&lt;/code&gt; - initiates the deployment&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--interactive&lt;/code&gt; - opens interactive mode to enter wallet private key&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--broadcast&lt;/code&gt; - broadcasts the deployment transaction across the chain&lt;/li&gt;
&lt;/ul&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%2Fcg4dt96pf34nd5flndfi.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%2Fcg4dt96pf34nd5flndfi.png" alt="Deployed" width="785" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, we have the address of the wallet from which the contract was deployed, the deployed contract address and the associated transaction hash!&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%2F7lk0y0d0ruitl723xfe3.gif" 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%2F7lk0y0d0ruitl723xfe3.gif" alt="Enter deployed" width="498" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;AANDDD... DEPLOYED!!!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  💻 Interacting with the Contract
&lt;/h2&gt;

&lt;p&gt;Awesome! Great getting this far! 👏&lt;/p&gt;

&lt;p&gt;When it comes to interacting with our deployed contract, &lt;code&gt;cast&lt;/code&gt; is our friend&lt;/p&gt;

&lt;h3&gt;
  
  
  Set our Greeting Message
&lt;/h3&gt;

&lt;p&gt;Let's see the &lt;code&gt;cast&lt;/code&gt; command to do this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cast send &amp;lt;Deployed Contract Address&amp;gt; &lt;span class="s2"&gt;"setGreeting(string)"&lt;/span&gt; &lt;span class="s2"&gt;"Hello from cast!"&lt;/span&gt; &lt;span class="nt"&gt;--private-key&lt;/span&gt; &amp;lt;wallet private key&amp;gt; &lt;span class="nt"&gt;--rpc-url&lt;/span&gt; http://127.0.0.1:8545/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break it down&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cast send&lt;/code&gt; - send a transaction&lt;/li&gt;
&lt;li&gt; - in my case it's 0x5FbDB2315678afecb367f032d93F642f64180aa3&lt;/li&gt;
&lt;li&gt;The name of the function to call along with any return types and  arguments it has&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--private-key&lt;/code&gt; - follow this option with a wallet private key&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--rpc-url&lt;/code&gt; - &lt;a href="http://127.0.0.1:8545/" rel="noopener noreferrer"&gt;http://127.0.0.1:8545/&lt;/a&gt;, the default url to which &lt;code&gt;anvil&lt;/code&gt; deploys&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your &lt;code&gt;greeting&lt;/code&gt; state variable should now be updated with the value "Hello from cast!". But, let's see for ourselves and not just assume&lt;/p&gt;

&lt;h3&gt;
  
  
  Get our Greeting Message
&lt;/h3&gt;

&lt;p&gt;The function to get the greeting message is a &lt;code&gt;view&lt;/code&gt; only function. This means we are only reading from the state variable and doesn't need to initiate a transaction to do this&lt;/p&gt;

&lt;p&gt;Here's the &lt;code&gt;cast&lt;/code&gt; command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cast call &amp;lt;Deployed Contract Address&amp;gt; &lt;span class="s2"&gt;"goGreet() returns (string)"&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--abi-decode&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break it down&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cast call&lt;/code&gt; - calls a function without broadcasting as a transaction&lt;/li&gt;
&lt;li&gt; - in my case it's 0x5FbDB2315678afecb367f032d93F642f64180aa3&lt;/li&gt;
&lt;li&gt;The name of the function to call along with any return types and  arguments it has&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-- --abi-decode&lt;/code&gt; - (IMPORTANT)The response we get while calling the function will be in hex. This flag helps decode it to a readable string&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Read more about &lt;a href="https://docs.soliditylang.org/en/develop/abi-spec.html" rel="noopener noreferrer"&gt;ABIs here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This should return "Hello from cast!". &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If that's the case, well my friend, CONGRATULATIONS are in order!!&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%2Fmg0covpus3dj7cy7ut0d.gif" 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%2Fmg0covpus3dj7cy7ut0d.gif" alt="Well Done" width="498" height="369"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  And that's a Wrap! (For now 😬)
&lt;/h2&gt;

&lt;p&gt;By now we should have &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Our Greeting.sol contract compiled, tested&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;anvil&lt;/code&gt; running a local blockchain&lt;/li&gt;
&lt;li&gt;Greeting.sol deployed to our local blockchain&lt;/li&gt;
&lt;li&gt;Used &lt;code&gt;cast&lt;/code&gt; to interact with the deployed contract&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Part 3, we'll be&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing a simple bank contract&lt;/li&gt;
&lt;li&gt;Focusing majorly on writing proper tests for the logic while handling all edge cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Don't miss it! I'll see you soon!&lt;/strong&gt; 😎&lt;/p&gt;

</description>
      <category>web3</category>
      <category>foundry</category>
      <category>solidity</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Get from Zero To Hero in Foundry - Part 1: Getting Started</title>
      <dc:creator>Abhiram A</dc:creator>
      <pubDate>Sat, 09 Aug 2025 14:59:21 +0000</pubDate>
      <link>https://dev.to/abhiramelf/get-from-zero-to-hero-in-foundry-part-1-getting-started-57h8</link>
      <guid>https://dev.to/abhiramelf/get-from-zero-to-hero-in-foundry-part-1-getting-started-57h8</guid>
      <description>&lt;h2&gt;
  
  
  Let's Begin
&lt;/h2&gt;

&lt;p&gt;Get ready to sweat it out in style while you Forge some piping hot Smart Contracts with molten, smoldering Solidity inside blockchain Foundry&lt;/p&gt;

&lt;p&gt;This article is the first of many in which we'll dive deep into building, testing and deploying Smart Contracts using Foundry. We'll also see how to use Foundry to interact with the deployed Smart Contracts.&lt;/p&gt;

&lt;p&gt;One article per day and by the end of the series you would be able to use Foundry like a PRO&lt;/p&gt;

&lt;p&gt;LFG! 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  Today's Outcome
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;What's Foundry?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Install Foundry on our systems&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Build and Test a basic Counter contract&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Foundry, What!? 😮
&lt;/h2&gt;

&lt;p&gt;Imagine a beautiful Saturday night - you have a wondrous steak simmering on your pan, ready and staring back at you. What do you do next? Do you just leave it there like that? Do you just walk away? That would be ludicrous!&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Steaks, Me like - Spice Boo
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'll get the steak out and slice it, taste test it(I know you're drooling!), transfer the slices to a plate and use cutlery to consume that beauty!&lt;/p&gt;

&lt;p&gt;Congratulations! You've become the Foundry of Steaks!&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%2Fii0tlgg1c2qx6lh09gcy.gif" 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%2Fii0tlgg1c2qx6lh09gcy.gif" alt="Salt Bae Meme" width="200" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Enter Foundry
&lt;/h3&gt;

&lt;p&gt;OOOKAYY!! - this is exactly what Foundry does for your Smart Contracts&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have your Smart Contract simmering in your IDE&lt;/li&gt;
&lt;li&gt;Foundry lets you taste "Test" it&lt;/li&gt;
&lt;li&gt;Helps you "Deploy" it to your blockchain plate, and&lt;/li&gt;
&lt;li&gt;Finally let's you "Interact" with the plated Smart Contract&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;BOOM! Everything you need in ONE SINGLE PACKAGE! And everything written in pure Solidity, no JS/TS!&lt;/p&gt;

&lt;p&gt;Enough about steaks, let's start forging&lt;/p&gt;




&lt;h2&gt;
  
  
  Foundry, How? 🔨
&lt;/h2&gt;

&lt;p&gt;Let's look at how we can setup Foundry in our systems. But, before we do that let's make sure our systems are prepped for installing Foundry&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%2Fa76gu3v7e2n9kw40pnqs.gif" 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%2Fa76gu3v7e2n9kw40pnqs.gif" alt="Tell me how" width="498" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  📦 Prerequisite
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Rust compiler and Cargo&lt;/strong&gt; - The easiest way to install them is to go to &lt;a href="https://rustup.rs/" rel="noopener noreferrer"&gt;&lt;strong&gt;rustup.rs&lt;/strong&gt;&lt;/a&gt; and follow the steps.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  &lt;em&gt;On Windows:&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Make sure you have a recent version of &lt;a href="https://visualstudio.microsoft.com/downloads/" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Visual Studio&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;with the&lt;/em&gt; &lt;strong&gt;&lt;em&gt;"Desktop Development with C++"&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;workload installed.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  🛠️ Install Foundry
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Foundryup&lt;/strong&gt; is the official installer for the Foundry toolchain.&lt;br&gt;
📘 Learn more &lt;a href="https://github.com/foundry-rs/foundry/blob/master/foundryup/README.md" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Foundryup
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://foundry.paradigm.xyz | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will install the &lt;code&gt;foundryup&lt;/code&gt; command in your CLI&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Follow this up with running the command
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;foundryup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will automatically install the latest stable versions of &lt;code&gt;forge&lt;/code&gt;, &lt;code&gt;cast&lt;/code&gt;, &lt;code&gt;anvil&lt;/code&gt; and &lt;code&gt;chisel&lt;/code&gt;. Each of these have it's own role to play. We'll get to each of them as we progress in the series&lt;/p&gt;
&lt;h3&gt;
  
  
  Start Cooking
&lt;/h3&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%2Fxgnj2rk1ugr8l8ze2g5a.gif" 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%2Fxgnj2rk1ugr8l8ze2g5a.gif" alt="Cooking" width="278" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For today's lesson, we'll be looking into how &lt;code&gt;forge&lt;/code&gt; helps us build and test Smart Contracts&lt;/p&gt;

&lt;p&gt;Let's create a folder named &lt;code&gt;foundry-learn&lt;/code&gt; and move into that. Add a simple Counter contract using a &lt;code&gt;forge&lt;/code&gt; command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;forge init Counter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new &lt;code&gt;Counter&lt;/code&gt; folder within your project folder. Once you move inside this folder you'll see a whole bunch of stuff, but let's just focus on 3 folder for now&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;lib&lt;/code&gt; - Holds &lt;code&gt;forge-std&lt;/code&gt; library, which helps us write Tests and Deploy scripts using pure Solidity&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;src&lt;/code&gt; - Holds all your &lt;code&gt;.sol&lt;/code&gt; Smart Contract files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;test&lt;/code&gt; - Holds all your &lt;code&gt;.t.sol&lt;/code&gt; test files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We have our sample contract and test file in their respective folders. Let's look at how easy it's to test and build our contract&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Here's our &lt;code&gt;Counter.sol&lt;/code&gt; code in &lt;code&gt;src&lt;/code&gt; folder
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

// This is a simple counter contract that allows you to set a number,
// increment it, and decrement it, with a check to prevent negative values.
contract Counter {
    uint256 public number; // The current value of the counter

    // Sets the initial value of the counter
    function setNumber(uint256 newNumber) public {
        number = newNumber;
    }

    // Increments the counter by 1
    function increment() public {
        number++;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The simple contract lets us write a number to a state variable and increment it by 1 by calling a public function&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;And here's the &lt;code&gt;Counter.t.sol&lt;/code&gt; test file in the &lt;code&gt;test&lt;/code&gt; folder
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";

// This is a test contract for the Counter contract.
// It includes tests for incrementing, decrementing, and setting the counter value.
contract CounterTest is Test {
    Counter public counter; // Instance of the Counter contract

    // Sets up the test environment before each test
    function setUp() public {
        counter = new Counter();
        counter.setNumber(0);
    }

    // Tests if the counter increments correctly
    function test_Increment() public {
        counter.increment();
        assertEq(counter.number(), 1);
    }

    // Fuzz test for setting the counter value
    function testFuzz_SetNumber(uint256 x) public {
        counter.setNumber(x);
        assertEq(counter.number(), x);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tests if the state variable is being set properly and incrementing is working on function call&lt;/p&gt;




&lt;h3&gt;
  
  
  Build
&lt;/h3&gt;

&lt;p&gt;It's time to compile/build our Contract. To do that, let's run this command while in the &lt;code&gt;Counter&lt;/code&gt; folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;forge build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Contract will now be compiled using the latest Solidity compiler&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%2F3k5o9swif26xkvgkps6o.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%2F3k5o9swif26xkvgkps6o.png" alt="Successful Compiler Output" width="570" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Test
&lt;/h3&gt;

&lt;p&gt;To Test the Contract all you have to do is run this command while in the &lt;code&gt;Counter&lt;/code&gt; folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;forge &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is setup properly, you'll see that the tests passing successfully&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%2Fxhv3bsavdu0gve57vpth.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%2Fxhv3bsavdu0gve57vpth.png" alt="Successful Test Output" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  And that's a Wrap! (For now 😬)
&lt;/h2&gt;

&lt;p&gt;By now you should have &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Foundry and all it's tools installed in your system.&lt;/li&gt;
&lt;li&gt;Created Counter project using &lt;code&gt;forge&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Understood important folder structure of generated project&lt;/li&gt;
&lt;li&gt;Built and Tested the simple Counter contract using &lt;code&gt;forge&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Part 2, we'll dig into&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploying your tested Contracts&lt;/li&gt;
&lt;li&gt;Interacting with deployed Contract using terminal commands&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don't miss it! I'll see you soon! 😎&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>solidity</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
