<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ifeoma's Blog]]></title><description><![CDATA[Ifeoma's Blog]]></description><link>https://ifaycodes.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 15:12:50 GMT</lastBuildDate><atom:link href="https://ifaycodes.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Start with Solidity: A Beginner's Guide to Smart Contracts]]></title><description><![CDATA[Are you excited about creating a smart contract for your project but unsure where to begin? This guide will walk you through the process step-by-step, from setting up your development environment to understanding the project folder structure. By the ...]]></description><link>https://ifaycodes.hashnode.dev/how-to-start-with-solidity-a-beginners-guide-to-smart-contracts</link><guid isPermaLink="true">https://ifaycodes.hashnode.dev/how-to-start-with-solidity-a-beginners-guide-to-smart-contracts</guid><category><![CDATA[Solidity]]></category><category><![CDATA[Ethereum]]></category><category><![CDATA[hardhat]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Ifeoma Chidera]]></dc:creator><pubDate>Mon, 10 Jun 2024 07:37:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717990491882/607bca5e-9ecc-4362-976a-6dd91323d103.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Are you excited about creating a smart contract for your project but unsure where to begin? This guide will walk you through the process step-by-step, from setting up your development environment to understanding the project folder structure. By the end, you'll be ready to write, deploy, and test your first Solidity smart contract.</p>
<h3 id="heading-quick-refresher-what-is-solidity">Quick refresher, what is Solidity?</h3>
<p>Solidity is a high-level programming language designed for writing smart contracts on blockchain platforms, primarily Ethereum. It is statically typed and designed to target the Ethereum Virtual Machine (EVM). Solidity has syntax similar to JavaScript, which makes it relatively approachable for developers familiar with JavaScript or similar languages. It focuses on contracts, which are fundamental building blocks of Ethereum. Each contract contains code (functions) and data (state). Like other programming languages, Solidity programming also has variables, functions, classes, arithmetic operations, string manipulation, and many other concepts.</p>
<h3 id="heading-setting-up-our-environment">Setting up our environment</h3>
<p>For a solidity project, you need Node.js and npm (Node Package Manager) or Yarn installed on your system. For Windows users, it is advisable to activate the Windows SubLinux System (WSL). You can follow this <a target="_blank" href="https://learn.microsoft.com/en-us/windows/wsl/install">tutorial</a> to get started. After installing WSL, go to the extension tab in your VSCode and search Remote Development, and install it. You can also use Powershell if you want though you might run into some errors.</p>
<p>Follow these steps to set up your environment:</p>
<ol>
<li><p><strong>Download and Install Node.js and npm:</strong></p>
<ul>
<li><p>Go to the <a target="_blank" href="https://nodejs.org/en/download/package-manager"><strong>Node.js official website</strong></a> and download the latest stable version.</p>
</li>
<li><p>Follow the installation instructions for your operating system.</p>
</li>
<li><p>Confirm you have properly installed Node by running <code>node --version</code> . You should get something like this <code>v20.11.0</code></p>
</li>
</ul>
</li>
<li><p>Install Yarn (alternative to npm):</p>
<p> Nodejs comes with a feature called corepack. To install yarn, run <code>corepack enable</code> . If you are using an older Node version (&lt;16.10), you run <code>npm i -g corepack</code> instead.</p>
</li>
<li><p>Install git</p>
<p> if you don't already have git installed, visit <a target="_blank" href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">git</a> to install it. You'll know you did it right if you can run <code>git --version</code> and you see a response like <code>git version x.x.x</code></p>
</li>
</ol>
<p>Starting a project</p>
<ul>
<li><p>Make a directory where you want your project so <code>mkdir MyProject</code> and then cd into it, <code>cd MyProject</code>. Open up the directory in your VSCode using <code>code .</code></p>
</li>
<li><p>In the terminal, run <code>npm init</code> or <code>yarn init</code> to initial a new project. This will add a package.json file to the directory.</p>
</li>
<li><p>Next, run <code>yarn add --dev hardhat</code> or <code>npm install --save-dev hardhat</code> to start a Hardhat project in our directory.</p>
</li>
<li><p><strong>Quick Note</strong>:</p>
<p>  Hardhat is a development environment for smart contracts/Ethereum software. It consists of different components for editing, compiling, debugging, and deploying your smart contracts and dApps, all of which work together to create a complete development environment. It makes our work easier and faster. There are others like Foundry, and Brownie, which you can explore based on your preferences. Foundry is written in Rust and focuses on performance, while Brownie is Python-based, suitable for those comfortable with Python. For this tutorial, we will use Hardhat due to its extensive documentation and support.</p>
<p>  Keep in mind, Hardhat uses Javascript or Typescript so you need knowledge of them.</p>
</li>
<li><p>After running the above commands, you should get something like this</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717987165128/16b30d59-3634-4dfa-84fe-8ed7a7da6e82.jpeg" alt class="image--center mx-auto" /></p>
</li>
<li><p>You can pick a Javascript project, a Typescript project if that is what you are familiar with, or an empty config file that you will buy from scratch. I'll pick the Javascript project.</p>
</li>
<li><p>Follow the instructions on the screen and you should have something like this finally</p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717987540491/52eb490c-1228-48b7-9fcd-cfbae47f36eb.jpeg" alt class="image--center mx-auto" /></p>
<p>  Now you can go ahead and create your smart contract, deploy it, and test it too.</p>
</li>
</ul>
<h3 id="heading-understanding-the-folder-structure"><strong>Understanding the Folder Structure</strong></h3>
<p>Let's have a quick overview of our project folder.</p>
<ul>
<li><p>.yarn: not something you should bothered with but necessary for hardhat to run so leave it as is.</p>
</li>
<li><p>contracts: this folder will contain all the smart contract files you will create, in our example, Lock.sol. Now, it is not compulsory to have it all in a folder but it gives a cleaner view</p>
</li>
<li><p>Ignition: This folder will contain your deployment scripts. Also not compulsory</p>
</li>
<li><p>Test: this will contain all the test files for your contracts. Unit test, fuzz test, etc, should all be in here.</p>
</li>
<li><p>.gitignore: this will contain files that you do not want to expose should you push your project to GitHub. Files like the .env file for your environmental variables like API key, deployment files, node modules, artifacts, etc.</p>
</li>
<li><p>hardhat.config.js: this contains configurations specific to your project like blockchain networks that you will use, the solidity version, etc.</p>
</li>
<li><p>README.md: The file guides users in navigating the project and should contain key information such as the project title, description, table of contents, technologies used, requirements, installation and usage instructions, contribution guidelines, and more.</p>
</li>
</ul>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Congratulations! You've successfully set up your development environment, initialized a new Solidity project, and learned about the key components of your project folder. With this solid foundation, you're now equipped to dive deeper into writing and deploying smart contracts on the Ethereum blockchain. Remember, practice is key, so keep experimenting with different features and functionalities as you continue your journey into the world of blockchain development. Happy coding!</p>
]]></content:encoded></item><item><title><![CDATA[Unit Testing in Smart Contracts and Why it is Important.]]></title><description><![CDATA[Testing smart contracts is a very important measure for improving smart contract security. Smart contracts, unlike traditional softwares, cannot be updated after launching, making it imperative to test extensively before deploying contracts onto main...]]></description><link>https://ifaycodes.hashnode.dev/unit-testing-in-smart-contracts-and-why-it-is-important</link><guid isPermaLink="true">https://ifaycodes.hashnode.dev/unit-testing-in-smart-contracts-and-why-it-is-important</guid><category><![CDATA[Testing]]></category><category><![CDATA[Solidity]]></category><category><![CDATA[hardhat]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Ifeoma Chidera]]></dc:creator><pubDate>Fri, 23 Feb 2024 15:45:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1708702931379/f4e24db4-5174-475e-80ff-f03e378c893b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Testing smart contracts is a very important measure for improving smart contract security. Smart contracts, unlike traditional softwares, cannot be updated after launching, making it imperative to test extensively before deploying contracts onto mainnet.</p>
<p>A tiny mistake can lead to drastic losses for both users and projects using smart contracts. This is why testing your contract before deployment is very important to avoid these cases.</p>
<h3 id="heading-unit-testings">Unit Testings</h3>
<p>There is a range of testing techniques, from simple manual verifications (interacting with our contract in the terminal console) to complex end-to-end setups, all of them useful in their own way.</p>
<p>In smart contract development, unit testing has proven to be very useful. These tests are simple to write and quick to run, and let you add features and fix bugs in your code with confidence and ease. This testing consists of multiple small, focused tests, which each check a small part of your contract for correctness.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708702767542/3a1b58f6-385a-46a2-91e4-8be0c25867db.jpeg" alt class="image--center mx-auto" /></p>
<p>They can often be expressed in single sentences, such as 'the admin is able to pause the contract', 'transferring tokens emits an event' or 'non-admins cannot mint new tokens', followed by lines of codes to check if these actions actually happen without issues. An example can be seen below:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// test/Load.test.js</span>
<span class="hljs-comment">// Add dependencies</span>
const { expect } <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'chai'</span>);

<span class="hljs-comment">// Start test block</span>
describe(<span class="hljs-string">'Load'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  before(async <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">this</span>.Load <span class="hljs-operator">=</span> await ethers.getContractFactory(<span class="hljs-string">'Load'</span>);
  });

  beforeEach(async <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">this</span>.load <span class="hljs-operator">=</span> await <span class="hljs-built_in">this</span>.Load.deploy();
    await <span class="hljs-built_in">this</span>.load.deployed();
  });

  <span class="hljs-comment">// Test case</span>
  it(<span class="hljs-string">'retrieve returns a value previously stored'</span>, async <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// Store a value</span>
    await <span class="hljs-built_in">this</span>.load.store(<span class="hljs-number">39</span>);

    <span class="hljs-comment">// Test if the returned value is the same one</span>
    <span class="hljs-comment">// Note that we need to use strings to compare the 256 bit integers</span>
    expect((await <span class="hljs-built_in">this</span>.load.retrieve()).toString()).to.equal(<span class="hljs-string">'42'</span>);
  });
});
</code></pre>
<h3 id="heading-setting-up-testing-environment">Setting up Testing Environment</h3>
<p>To run this test, we need a testing environment. Using mainnet is expensive and testnet can be very slow. So a local blockchain is very useful in this case. Hardhat, an ethereum development environment, has a local blockchain that can be used. You just need to keep it running in your terminal.</p>
<p>Another important component is Chai. Chai is an assertion library that you can pair with javascript testing framework. This where we get keywords like 'expect', and 'assert' for testing.</p>
<p>You create a file named after the contract you want to test. In the example above, Load.sol is the contract we are testing, so our test file will be Load.test.js.</p>
<p>Finally to run this test, we use command 'yarn hardhat test' or 'npx hardhat test'. If it passes we should get this in terminal:</p>
<pre><code class="lang-solidity">yarn hardhat test
</code></pre>
<p>Congratulations! You just successfully ran a unit test.</p>
<h3 id="heading-wrap-up">Wrap up</h3>
<p>Now depending on how big your contract file is, you can continue taking it in bits till you take care of everything (advisable), you can also run more complex tests using <a target="_blank" href="https://docs.openzeppelin.com/test-helpers/0.5/">Openzeppelin Tests Helper</a> zeppelin Tests Helper. This helps you to capture parts of your code that might not get properly tested in unit testing.</p>
<p>There are of course other testing options available. You can check those out and use them to complement your unit testings for a more secured contract.</p>
<p>Now you know what unit testing is and how to go about it. Get testing!!</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Solidity Syntax and Data Types]]></title><description><![CDATA[Solidity is a programming language specifically designed for creating smart contracts on the Ethereum Virtual Machine (EVM). The syntax is similar to JavaScript and supports a variety of data types and constructs.
Like any other programming language,...]]></description><link>https://ifaycodes.hashnode.dev/understanding-solidity-syntax-and-data-types</link><guid isPermaLink="true">https://ifaycodes.hashnode.dev/understanding-solidity-syntax-and-data-types</guid><category><![CDATA[Solidity]]></category><category><![CDATA[Ethereum]]></category><category><![CDATA[General Programming]]></category><dc:creator><![CDATA[Ifeoma Chidera]]></dc:creator><pubDate>Thu, 22 Feb 2024 12:59:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/6YFgGY6kn6Q/upload/c8f3dfccab1543be739421439877cd69.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Solidity is a programming language specifically designed for creating smart contracts on the Ethereum Virtual Machine (EVM). The syntax is similar to JavaScript and supports a variety of data types and constructs.</p>
<p>Like any other programming language, you work with variables. When declaring a variable in solidity, you need to state the data type and the visibility before the variable name. This is to help prevent unnecessary type conversion and to help the compiler know how much space to allocate to each variable. so it looks like this:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// Signed integer (int) and unsigned integer (uint) </span>
    <span class="hljs-keyword">int256</span> <span class="hljs-keyword">public</span> number <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;
    <span class="hljs-keyword">uint256</span> <span class="hljs-keyword">public</span> number <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;

 <span class="hljs-comment">//Strings</span>
    <span class="hljs-keyword">string</span> <span class="hljs-keyword">public</span> greeting <span class="hljs-operator">=</span> <span class="hljs-string">"Hello, World!"</span>;
</code></pre>
<ul>
<li><p>int256, uint256, string - data types</p>
</li>
<li><p>public - visibility</p>
</li>
<li><p>number, greetings - variable name</p>
</li>
</ul>
<p>Signed integers represent both negative and positive integers and unsigned integers only represent non-negative integers (zero and positive numbers).</p>
<h3 id="heading-visibilities"><strong>Visibilities</strong></h3>
<p>Visibilities attached to variables determine how those variables can be accessed or modified by other parts of the contract or by external contracts. The four visibility levels are public, private, eternal and internal.</p>
<ul>
<li><p>A public contract can be accessed outside the contract, typically using getter functions but it cannot be modified directly from outside the contract.</p>
</li>
<li><p>A private variable can only be accessed and modified within the same contract where they are declared. They are not visible to external contracts or even derived contracts.</p>
</li>
<li><p>External variables are similar to public variables in that they can be accessed from outside the contract, but they cannot be read directly within the contract. They are typically used for function parameters to prevent direct access to the variable's value within the contract.</p>
</li>
<li><p>Internal variables are visible to the contract that declares them and any contracts derived from it (i.e., contracts that inherit from it). They cannot be accessed from external contracts.</p>
</li>
</ul>
<h3 id="heading-data-typeshttpssorobanstellarorgdocsmigrateevmsolidity-and-rust-basicsdata-types">Data Types<a target="_blank" href="https://soroban.stellar.org/docs/migrate/evm/solidity-and-rust-basics#data-types">​</a></h3>
<p>Solidity supports various data types, such as:</p>
<ul>
<li><p>Boolean: <code>bool</code> - true or false</p>
</li>
<li><p>Integer: <code>int</code> <a target="_blank" href="https://soroban.stellar.org/docs/migrate/evm/solidity-and-rust-basics#data-types"></a>(signed) and <code>uint</code> (unsigned)</p>
</li>
<li><p>Address: <code>address</code></p>
</li>
<li><p>String: <code>string</code> - letters</p>
</li>
<li><p>Bytes: <code>bytes</code> <a target="_blank" href="https://soroban.stellar.org/docs/migrate/evm/solidity-and-rust-basics#data-types"></a>(dynamic-size) and <code>bytes32</code> (fixed-size)</p>
</li>
<li><p>Arrays: dynamic-size or fixed-size and can be declared with other types.</p>
</li>
<li><p>Structs: <code>struct</code> - user-defined types that group multiple variables of possibly different types under a single name.</p>
</li>
<li><p>Enums: <code>enum</code> - user-defined type with a finite set of possible values</p>
</li>
<li><p>Mapping: <code>mapping</code> - an array of key-value pairs</p>
</li>
</ul>
<p>Here are implementations for each data type:</p>
<pre><code class="lang-solidity">    <span class="hljs-comment">// Boolean</span>
    <span class="hljs-keyword">bool</span> <span class="hljs-keyword">public</span> isCompleted <span class="hljs-operator">=</span> <span class="hljs-literal">false</span>;

    <span class="hljs-comment">// Integer (signed and unsigned)</span>
    <span class="hljs-keyword">int256</span> <span class="hljs-keyword">public</span> number <span class="hljs-operator">=</span> <span class="hljs-number">-10</span>;
    <span class="hljs-keyword">uint256</span> <span class="hljs-keyword">public</span> number <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;

    <span class="hljs-comment">// Address</span>
    <span class="hljs-keyword">address</span> <span class="hljs-keyword">public</span> userAddress <span class="hljs-operator">=</span> <span class="hljs-number">0x742d35Cc6634C0532925a3b844Bc454e4438f44e</span>;

    <span class="hljs-comment">// String</span>
    <span class="hljs-keyword">string</span> <span class="hljs-keyword">public</span> greeting <span class="hljs-operator">=</span> <span class="hljs-string">"Hello, World!"</span>;

    <span class="hljs-comment">// Bytes (dynamic-size and fixed-size)</span>
    <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">public</span> dynamicBytes <span class="hljs-operator">=</span> <span class="hljs-string">"hello, solidity"</span>;
    <span class="hljs-keyword">bytes32</span> <span class="hljs-keyword">public</span> fixedBytes <span class="hljs-operator">=</span> <span class="hljs-string">"hello, solidity"</span>;

    <span class="hljs-comment">// Arrays (dynamic-size and fixed-size)</span>
    <span class="hljs-keyword">uint</span>[] <span class="hljs-keyword">public</span> dynamicArray <span class="hljs-operator">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
    <span class="hljs-keyword">uint</span>[<span class="hljs-number">5</span>] <span class="hljs-keyword">public</span> fixedArray <span class="hljs-operator">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];

    <span class="hljs-keyword">address</span>[] <span class="hljs-keyword">public</span> dynamicAddressArray <span class="hljs-operator">=</span> [<span class="hljs-number">0xd41d1744871f42Bb724D777A2d0Bf53FB43a0040</span>, <span class="hljs-number">0x1f514ae9834aEAF6c2c3eb6D20E27e865F419010</span>];
    <span class="hljs-keyword">address</span>[<span class="hljs-number">3</span>] <span class="hljs-keyword">public</span> fixedAddressArray <span class="hljs-operator">=</span> [<span class="hljs-number">0xC90cd0D820D6dc447B3cD9545185B046873786A6</span>, <span class="hljs-number">0x401997E856CE51e0D4A8f26ce64952313BEA0E25</span>, <span class="hljs-number">0x221d3b9821f3Cc49B42E7dd487E2a6d1b3ed0E05</span>];

    <span class="hljs-keyword">bool</span>[] <span class="hljs-keyword">public</span> dynamicBoolArray <span class="hljs-operator">=</span> [<span class="hljs-literal">true</span>, <span class="hljs-literal">false</span>, <span class="hljs-literal">true</span>];
    <span class="hljs-keyword">bool</span>[<span class="hljs-number">2</span>] <span class="hljs-keyword">public</span> fixedBoolArray <span class="hljs-operator">=</span> [<span class="hljs-literal">true</span>, <span class="hljs-literal">false</span>];

    <span class="hljs-comment">// Struct</span>
    <span class="hljs-keyword">struct</span> <span class="hljs-title">Person</span> {
        <span class="hljs-keyword">string</span> name;
        <span class="hljs-keyword">uint</span> age;
    }
    Person <span class="hljs-keyword">public</span> person <span class="hljs-operator">=</span> Person(<span class="hljs-string">"Alice"</span>, <span class="hljs-number">30</span>);

    <span class="hljs-comment">// Enums</span>
    <span class="hljs-keyword">enum</span> <span class="hljs-title">Status</span> { Open, Closed, Pending }
    Status <span class="hljs-keyword">public</span> currentStatus <span class="hljs-operator">=</span> Status.Open;
    Status <span class="hljs-keyword">public</span> nextStatus <span class="hljs-operator">=</span> Status.Closed;
    Status <span class="hljs-keyword">public</span> previousStatus <span class="hljs-operator">=</span> Status.Pending;

    <span class="hljs-comment">// Mapping</span>
    <span class="hljs-keyword">mapping</span>(<span class="hljs-keyword">address</span> <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> <span class="hljs-keyword">uint</span>) <span class="hljs-keyword">public</span> balances;
</code></pre>
<p>There are a lot more I didn't touch on but hope this helps with readability the next time you come across a solidity code block. Have fun and enjoy!!</p>
]]></content:encoded></item></channel></rss>