<?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[W Solidity]]></title><description><![CDATA[W Solidity]]></description><link>https://solidityzerotohero.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1593680282896/kNC7E8IR4.png</url><title>W Solidity</title><link>https://solidityzerotohero.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 04:09:33 GMT</lastBuildDate><atom:link href="https://solidityzerotohero.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Simple Storage | Solidity Fundamentals]]></title><description><![CDATA[Setting up first Contract
boiler plate code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // stated our version

contract SimpleStorage {

}

Pointers :

// SPDX-License-Identifier: MIT to ]]></description><link>https://solidityzerotohero.hashnode.dev/simple-storage-solidity-fundamentals</link><guid isPermaLink="true">https://solidityzerotohero.hashnode.dev/simple-storage-solidity-fundamentals</guid><dc:creator><![CDATA[Gambit]]></dc:creator><pubDate>Wed, 26 Aug 2026 16:40:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/64231d28-3e95-4c3a-a8ab-1d84e8b3eb94.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Setting up first Contract</h1>
<p>boiler plate code</p>
<pre><code class="language-plaintext">// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // stated our version

contract SimpleStorage {

}
</code></pre>
<p><strong>Pointers :</strong></p>
<ul>
<li><p><code>// SPDX-License-Identifier: MIT</code> to let people and automated tools know the code is free to use, copy, modify, and share.</p>
</li>
<li><p><code>pragma solidity 0.8.18;</code> says our code needs to be exactly 0.8.18 version, <code>pragma solidity ^0.8.18;</code> our code can be compatible with anything 0.8.18 or above, <code>pragma solidity &gt;=0.8.18 &lt;0.9.0;</code> tells compiler that any version within the range works.</p>
</li>
<li><p>contract is like a Class in other languages.</p>
</li>
</ul>
<hr />
<p><strong>What does compiling a contract mean?</strong></p>
<p>It converts the Solidity code into bytecode and ABI that can be understood and executed by the Ethereum Virtual Machine (EVM). <strong>ABI</strong> stands for <strong>Application Binary Interface</strong>. It is a standard JSON file that acts as a translator between human-readable programming and the Ethereum Virtual Machine (EVM).</p>
<hr />
<h1>Basic Variable Types</h1>
<pre><code class="language-plaintext">// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // stated our version

contract SimpleStorage {
    // Basic types : boolean, uint, int, address, bytes
    bool gay = true;
    uint256 favouriteNumber = 42;
    string name = "0xgambit";
    int256 credit = -250;
    address myAddress = 0xF1Efb0e72A0fCf91D168790b8cD4C97614550A30;
    bytes32 favouriteBytes32 = "cat";
}
</code></pre>
<p>Pointers :</p>
<ul>
<li><p>boolean is a true / false value, uint is a un-signed integer aka a positive whole number, int is a positive or negative whole number, address will be like a wallet address</p>
</li>
<li><p>uint and int are special as we can specify how many bits we want to assign to them while creating a variable, eg : uint256 (256 bits / 32 bytes) of storage, can store [0, 2^256-1], if you do not specify how many bits then unit defaults to uint256. We may also have 8 bits, 16 bits, 56 bits, etc..</p>
</li>
<li><p><code>string</code> is essentially a <code>bytes</code> array wrapper, you can also specify bits for bytes like <code>bytes32</code> , but remember unlike uint bytes32 and bytes are different (will learn later)</p>
</li>
<li><p>The default values for these types are:</p>
<ul>
<li><p><code>bool</code>: <code>false</code></p>
</li>
<li><p><code>uint</code> (all sizes like <code>uint8</code> to <code>uint256</code>): <code>0</code></p>
</li>
<li><p><code>int</code> (all sizes like <code>int8</code> to <code>int256</code>): <code>0</code></p>
</li>
<li><p><code>address</code> (and <code>address payable</code>): <code>0x0000000000000000000000000000000000000000</code> (often referred to as <code>address(0)</code> or the <strong>zero address</strong>)</p>
</li>
<li><p><code>bytes</code> (dynamically-sized): <code>0x</code> (an <strong>empty byte array</strong>)</p>
</li>
<li><p><code>bytes1</code> <strong>to</strong> <code>bytes32</code> (fixed-size): <code>0x00...</code> (padded with zeros to match the specified number of bytes)</p>
</li>
</ul>
</li>
</ul>
<h1>Functions</h1>
<p>Functions execute a code block and may or may not return a value, just like other languages.</p>
<pre><code class="language-plaintext">// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // stated our version

contract SimpleStorage {
    uint256 public favoriteNumber;

    function updateFavorite(uint256 _favoriteNumber) public{
        favoriteNumber = _favoriteNumber;
    }
}
</code></pre>
<p>We can compile and deploy the contract in remix test environment now.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/a119dc31-6e62-4ebd-95b2-01839f612e1c.png" alt="" style="display:block;margin:0 auto" />

<p>if we call the favouriteNumber (doesn't cost gas as we aren't changing blockchain data) we get the value 0.</p>
<p>If we call the <code>updateFavourite</code> function with a number of our own (costs gas) it will update the variable value.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/034d47cd-bb97-4362-9d74-68405130dff3.png" alt="" style="display:block;margin:0 auto" />

<p>Now if we call the data we will get the value 69, as updateFavourite changed the state of blockchain.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/e1704ea4-c6b1-48bc-bfa3-8bcd10edeacd.png" alt="" style="display:block;margin:0 auto" />

<h2><strong>Function Visibility Specifiers</strong></h2>
<p>Visibility keywords dictate <strong>where</strong> and <strong>who</strong> can call the function. You must choose one for every function:</p>
<ul>
<li><p><code>public</code>: Callable internally by the contract and externally by users or other contracts, it also creates a getter function for storage/state variables.</p>
</li>
<li><p><code>external</code>: Only callable from outside the contract. (Saves gas for large array inputs).</p>
</li>
<li><p><code>internal</code> (default): Only accessible inside the current contract or contracts inheriting it.</p>
</li>
<li><p><code>private</code>: Only accessible inside the exact contract where it is defined.</p>
</li>
</ul>
<p><strong>scope</strong> of variables inside or outside functions are just like other languages, follow the curly brackets {}</p>
<pre><code class="language-plaintext">// getter function

function retrieve() public view returns(uint256){
    return favoriteNumber;
}
</code></pre>
<p>We are saying that we wanna return <code>favouriteNumber</code> of type uint256.</p>
<h2><strong>State Mutability Modifiers</strong></h2>
<p>These keywords notify the Ethereum Virtual Machine (EVM) how the function interacts with the blockchain state, directly impacting gas fees:</p>
<ul>
<li><p><strong>Default (State-changing)</strong>: Modifies state variables and requires a paid transaction fee (gas).</p>
</li>
<li><p><code>view</code>: Reads data from the blockchain but <strong>cannot modify</strong> it. Free to call externally.</p>
</li>
<li><p><code>pure</code>: <strong>Neither reads nor modifies</strong> blockchain state. Used for isolated math or helper logic.</p>
</li>
</ul>
<hr />
<h1>Arrays and Structs</h1>
<h2>Struct basics</h2>
<p>A struct allows us to create custom data structure with multiple fields.</p>
<pre><code class="language-plaintext">struct User {
    uint256 id;
    string name;
    bool isActive;
}

// Creating and storing a struct instance
User public newUser = User(1, "Alice", true);

// Accessing fields using dot notation
string memory userName = newUser.name; // Returns "Alice"
</code></pre>
<h2>Array basics</h2>
<p>Arrays in solidity are collection of elements of the exact same data type (including structs).</p>
<p>They can be fixed(decided at compile time) or dynamic(can grow/shrink during run time).</p>
<pre><code class="language-plaintext">// Example syntax of fixed size array
uint256[5] public numbers;

// Example syntax of dynamic size array
uint256[] public IDs;
</code></pre>
<p><strong>Common Array Operations (Dynamic Arrays Only):</strong></p>
<ul>
<li><p><code>.push(element)</code>: Adds an item to the end of the array. Increases length by 1.</p>
</li>
<li><p><code>.pop()</code>: Removes the last item from the array. Decreases length by 1.</p>
</li>
<li><p><code>.length</code>: Returns the current number of elements in the array.</p>
</li>
</ul>
<h2>Combined Example</h2>
<pre><code class="language-plaintext">// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // stated our version

contract SimpleStorage {

    // custom data structure called Person
    struct Person{
        uint256 favouriteNumber;
        string name;
    }

    // dynamic array of type Person
    Person[] public listOfpeople;

    function addPerson(string memory _name, uint256 _favouriteNumber) public {
        // Person memory newPerson = Person(_favouriteNumber, _name);
        // listOfpeople.push(newPerson);

        listOfpeople.push(Person(_favouriteNumber, _name));
    }

}
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/4e6fc335-1a6a-40bc-9846-5e420697ffd5.png" alt="" style="display:block;margin:0 auto" />

<p>example Person added after deploying contract.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/90157460-d110-4e97-a0dc-3da83b3c83b1.png" alt="" style="display:block;margin:0 auto" />

<p>Since <code>listOfpeople</code> is public we can check it by proving the index number.</p>
<h1>Memory Storage and Calldata</h1>
<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/2335554b-87db-496c-b278-752ba86c8360.png" alt="" style="display:block;margin:0 auto" />

<p>Key distinctions:</p>
<ul>
<li><p><code>storage</code> changes are saved on the blockchain and cost gas. A <code>storage</code> reference points to the actual state variable. If you make a variable outside of function inside a contract it defaults to storage variable.</p>
</li>
<li><p><code>memory</code> is temporary workspace. It disappears when the transaction/call finishes. Generally used as parameter defining in functions. You usually write <code>memory</code> for temporary arrays, strings, structs, mapping, or <code>bytes</code>, simple values don't need <code>memory</code> .</p>
</li>
<li><p><code>calldata</code> , read-only delivery package , holds externally supplied arguments without copying them into memory. It is generally cheaper than <code>memory</code>, but immutable. Using <code>calldata</code> avoids making an unnecessary temporary copy, so it is usually cheaper than using <code>memory</code> for input you only read.</p>
</li>
</ul>
<p>Example code :</p>
<pre><code class="language-plaintext">contract Notes {
    string[] public savedNotes; // storage: stays on the blockchain

    function save(string calldata newNote) external {
        string memory editableNote = newNote;

        // We can change the temporary copy if needed
        // editableNote = "Updated note";

        savedNotes.push(editableNote); // copied into permanent storage
    }
}
</code></pre>
<p>When <code>save()</code> finishes:</p>
<ul>
<li><p><code>editableNote</code> (in <code>memory</code>) disappears.</p>
</li>
<li><p><code>newNote</code> (in <code>calldata</code>) also disappears.</p>
</li>
<li><p><code>savedNotes</code> (in <code>storage</code>) remains permanently on the blockchain.</p>
</li>
</ul>
<h1>Mapping</h1>
<pre><code class="language-plaintext">// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // stated our version

contract SimpleStorage {

    // custom data structure called Person
    struct Person{
        uint256 favouriteNumber;
        string name;
    }

    // dynamic array of type Person
    Person[] public listOfpeople;

    // Mapping, name =&gt; favouriteNumber
    mapping(string =&gt; uint256) public nameToFavouriteNumber;

    function addPerson(string memory _name, uint256 _favouriteNumber) public {
        // Person memory newPerson = Person(_favouriteNumber, _name);
        // listOfpeople.push(newPerson);

        listOfpeople.push(Person(_favouriteNumber, _name));
        nameToFavouriteNumber[_name] = _favouriteNumber;
    }

}
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/9073f70f-1b0a-47cd-b180-565bb170999a.png" alt="" style="display:block;margin:0 auto" />

<img src="https://cdn.hashnode.com/uploads/covers/696d30df368830e43dc35b6d/02c103a2-419e-446c-92df-66ae480bfc39.png" alt="" style="display:block;margin:0 auto" />

<p>If we don't give a key for a value it give the default value of it's data type.</p>
]]></content:encoded></item></channel></rss>