<?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: AbhayPatel98</title>
    <description>The latest articles on DEV Community by AbhayPatel98 (@abhaypatel).</description>
    <link>https://dev.to/abhaypatel</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%2F991804%2F32b5a142-e431-481d-8d6f-4d208a7419f6.jpeg</url>
      <title>DEV Community: AbhayPatel98</title>
      <link>https://dev.to/abhaypatel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhaypatel"/>
    <language>en</language>
    <item>
      <title>Escrow in blockchain.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Sat, 24 Jun 2023 05:35:41 +0000</pubDate>
      <link>https://dev.to/abhaypatel/escrow-in-blockchain-4f76</link>
      <guid>https://dev.to/abhaypatel/escrow-in-blockchain-4f76</guid>
      <description>&lt;p&gt;Blockchain-based escrow works by locking the funds or assets in a smart contract until specific conditions are fulfilled. These conditions can be based on time, delivery of goods or services, or any other predefined criteria agreed upon by the parties involved. Once the conditions are met, the smart contract automatically releases the funds or assets to the appropriate party.&lt;/p&gt;

&lt;p&gt;The benefits of using blockchain for escrow include:&lt;/p&gt;

&lt;p&gt;Transparency: Since the smart contract and its execution are recorded on the blockchain, all parties involved can verify the transaction details and ensure transparency.&lt;/p&gt;

&lt;p&gt;Security: Blockchain employs strong cryptographic techniques, making it difficult for malicious actors to tamper with the escrowed funds or assets. This provides an additional layer of security compared to traditional escrow systems.&lt;/p&gt;

&lt;p&gt;Efficiency: Blockchain-based escrow eliminates the need for intermediaries, such as banks or escrow agents, thereby reducing costs and accelerating transaction settlement times.&lt;/p&gt;

&lt;p&gt;Global accessibility: Blockchain operates on a decentralized network, enabling escrow transactions to be conducted globally without relying on a centralized authority or jurisdiction.&lt;/p&gt;

&lt;p&gt;However, it's important to note that while blockchain-based escrow offers advantages, it does not eliminate all risks associated with transactions. Parties should still exercise due diligence and carefully define the terms and conditions of the escrow agreement to ensure their interests are protected.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Libraries in Solidity.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Sun, 29 Jan 2023 10:30:14 +0000</pubDate>
      <link>https://dev.to/abhaypatel/libraries-in-solidity-2a5e</link>
      <guid>https://dev.to/abhaypatel/libraries-in-solidity-2a5e</guid>
      <description>&lt;p&gt;When you need to share code between Solidity Contracts, it's time to utilize Libraries.&lt;/p&gt;

&lt;p&gt;Libraries are a great place to store functions that are common to many Smart Contracts. These functions can range from re-usable math functions to contract patterns and permissions.&lt;/p&gt;

&lt;p&gt;Using libraries can:&lt;/p&gt;

&lt;p&gt;Reduce new code, limiting the opportunity for bugs.&lt;/p&gt;

&lt;p&gt;Save development time by not re-inventing the wheel. &lt;/p&gt;

&lt;p&gt;Secure your contracts with audited code and best practices.&lt;/p&gt;

&lt;p&gt;*Save gas on deployments by making use of already deployed code.&lt;/p&gt;

&lt;p&gt;*Saving gas depends on how you use the library. Libraries can be deployed on their own, like contracts, and they can also be compiled into the contract bytecode directly. &lt;/p&gt;

</description>
      <category>microsoft</category>
      <category>learning</category>
      <category>career</category>
      <category>productivity</category>
    </item>
    <item>
      <title>ERC-20 Tokens</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Tue, 17 Jan 2023 16:13:04 +0000</pubDate>
      <link>https://dev.to/abhaypatel/erc-20-tokens-4on6</link>
      <guid>https://dev.to/abhaypatel/erc-20-tokens-4on6</guid>
      <description>&lt;p&gt;An &lt;strong&gt;ERC-20 token&lt;/strong&gt; is a representation of some sort of asset on the Ethereum network. These could be anything:&lt;/p&gt;

&lt;p&gt;shares in a company&lt;br&gt;
reward system points&lt;br&gt;
voting rights&lt;br&gt;
cryptocurrency&lt;br&gt;
lottery tickets&lt;br&gt;
on-chain Chuck E Cheese tokens&lt;br&gt;
anything you can think of!&lt;br&gt;
This is what has made Ethereum a popular choice for many different use cases across industries - anyone can tokenize any asset.&lt;/p&gt;

&lt;p&gt;Importance of the ERC-20 Token Standard&lt;br&gt;
A key point to understand here is that ERC-20 is a technical standard! 💡&lt;/p&gt;

&lt;p&gt;The main use of the ERC-20 standard is to increase compatibility of the ecosystem. Exchanges like Uniswap are then able to build incredibly powerful applications because they create infrastructure that supports the ERC-20 interface; this then triggers developers who use the ERC-20 standard to develop, instant compatibility with Uniswap and many other dApps!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ERC-20 Token Smart Contract&lt;/strong&gt;&lt;br&gt;
At the base level, an ERC-20 token smart contract simply uses a mapping to keep track of fungible tokens: any one token is exactly equal to any other token; no tokens have special rights or behavior associated with them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ERC-20 Token Interface&lt;/strong&gt;&lt;br&gt;
As we covered above, ERC-20 defines a common interface so that any application can use them in a standard way.&lt;/p&gt;

&lt;p&gt;This simplifies and eases developers’ tasks, because they can proceed with their work, knowing that each and every new project won’t need to be redone every time a new token is released, as long as the token follows the rules.&lt;/p&gt;

&lt;p&gt;The interface consists of a number of functions that must be present in every implementation of the standard, as well as some optional.&lt;/p&gt;

&lt;p&gt;An ERC-20-compliant token contract must provide at least the following:&lt;/p&gt;

&lt;p&gt;name, symbol, and decimals are all optional fields&lt;br&gt;
totalSupply defines the current circulating supply of the tokens&lt;br&gt;
balanceOf will return the balance for a particular user&lt;br&gt;
transfer which is the bread and butter, transfer from one account to another&lt;br&gt;
approve, transferFrom and allowance are methods for other contracts moving your funds&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CEOmdi0D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blbfcyjz0w6mvqe84x5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CEOmdi0D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blbfcyjz0w6mvqe84x5t.png" alt="Image description" width="880" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ERC-20 Data Structures&lt;/strong&gt;&lt;br&gt;
There are two important data structures used by the ERC-20 token standard that we should review:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;balances&lt;/strong&gt;: mapping of token balances, by owner. Each transfer is a deduction from one balance and an addition to another balance.&lt;br&gt;
&lt;strong&gt;allowances&lt;/strong&gt;: mapping of allowances/delegate spending. This is a nested mapping in which the primary key is the address of the token owner which maps to a spender address and amount delegated to spend.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>beginners</category>
      <category>web3</category>
      <category>solidity</category>
    </item>
    <item>
      <title>Smart Contract Inheritance.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Mon, 09 Jan 2023 14:28:35 +0000</pubDate>
      <link>https://dev.to/abhaypatel/smart-contract-inheritance-3k60</link>
      <guid>https://dev.to/abhaypatel/smart-contract-inheritance-3k60</guid>
      <description>&lt;p&gt;&lt;strong&gt;Inheritance Overview&lt;/strong&gt;&lt;br&gt;
As with many object-oriented languages, Solidity includes inheritance as a feature.&lt;/p&gt;

&lt;p&gt;Inheritance means that you can create an object with some values/methods and use it as a base for other objects.&lt;br&gt;
In Solidity, the objects we're referring to are contracts and interfaces. We can write a contract with state variables and functions. Then we can create contracts that inherit those variables and functions. These derived contracts can then choose to add behavior as necessary.&lt;/p&gt;

&lt;p&gt;Smart contracts can inherit other contract by using the is keyword. More specifically, a contract that inherits is the child and the inheritor is the parent. Using the is keyword in Solidity establishes a smart contract parent-to-child chain. So whenever you think of inheritance, just think of the father-son relations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---D7HgyN_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cggbblimmxc40w4032qr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---D7HgyN_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cggbblimmxc40w4032qr.jpg" alt="Image description" width="880" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inheritance allows programmers to create classes that are built upon existing classes, to specify a new implementation while maintaining the same behaviors.&lt;/p&gt;

&lt;p&gt;Contracts can inherit other contracts by using the &lt;strong&gt;is&lt;/strong&gt; keyword.&lt;/p&gt;

&lt;p&gt;Just as illustrated in the diagram above, the syntax to establish inheritance between smart contracts in Solidity is to simply us the is keyword in the child contract - which creates an explicit pointer to the parent contract:&lt;/p&gt;

&lt;p&gt;contract A {&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;contract B is A {&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;In this case Contract A is the parent contract, often times referred to as the base contract whereas Contract B is the child contract, often referred to as the derived contract. Let's break down the different types of smart contract inheritance in Solidity. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>blockchain</category>
      <category>programming</category>
      <category>web3</category>
    </item>
    <item>
      <title>Arrays &amp; Structs.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Tue, 03 Jan 2023 14:39:56 +0000</pubDate>
      <link>https://dev.to/abhaypatel/arrays-structs-1glk</link>
      <guid>https://dev.to/abhaypatel/arrays-structs-1glk</guid>
      <description>&lt;p&gt;&lt;strong&gt;Solidity Reference Types&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At this point, you are well on your way to becoming a Solidity master. We've looked at the primitive data types in Solidity, such as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;uint/int&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;boolean&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;address&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;enum&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;bytes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Primitive data types can also be referred to as "value types". A value type stores its data directly in the variable.&lt;/p&gt;

&lt;p&gt;Solidity, like most other object-oriented programming languages, has another type of data for reference-based data types, such as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;arrays&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;strings&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;structs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;mappings (also reference types, but we've already covered them quite heavily!)&lt;br&gt;
A reference type does not store values directly in a variable. Instead, reference types hold a pointer to the address of the data's location.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gj6faRWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfueldreqr62tg8m7z1f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gj6faRWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfueldreqr62tg8m7z1f.jpg" alt="Image description" width="880" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The two main reference types we will cover today are: arrays and structs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arrays&lt;/strong&gt;&lt;br&gt;
In computer science, an array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. In Solidity, an array can be both of fixed or dynamic size.&lt;/p&gt;

&lt;p&gt;What Are Dynamic &amp;amp; Fixed Arrays?&lt;br&gt;
The size of dynamic arrays are not predefined when they are declared. As elements are systematically added, the size of the dynamic array changes, and during runtime, the actual size of the array will be determined.&lt;/p&gt;

&lt;p&gt;In contrast, fixed arrays have a predefined size, and the quantity of elements present in the array should not exceed the size of the array.&lt;/p&gt;

&lt;p&gt;Storage Arrays&lt;br&gt;
Storage arrays are typically declared as state variables and can be either fixed or dynamic in size. Here's a Solidity code snipper declaring both a fixed and dynamic-sized array in a simple &lt;strong&gt;MyContract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G3yIKWAH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohgwyznlinfq8e6os0e5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G3yIKWAH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohgwyznlinfq8e6os0e5.jpg" alt="Image description" width="871" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both fixed and dynamic sized arrays have access to the .length array member:&lt;/p&gt;

&lt;p&gt;.length: returns how many values an array holds per index&lt;br&gt;
Dynamic storage arrays have the typical array methods available, such as:&lt;/p&gt;

&lt;p&gt;.push(): used to add an element to the array at the last position&lt;/p&gt;

&lt;p&gt;.pop(): used to remove an element of the array at the last position&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Introduction to Escrows.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Tue, 03 Jan 2023 07:08:16 +0000</pubDate>
      <link>https://dev.to/abhaypatel/introduction-to-escrows-44ij</link>
      <guid>https://dev.to/abhaypatel/introduction-to-escrows-44ij</guid>
      <description>&lt;p&gt;&lt;strong&gt;An escrow&lt;/strong&gt; is an agreement often used when transferring funds in exchange for a good or service. Funds can be held in escrow and a third party can be chosen to "arbitrate" or approve the transfer when the service or good is provided.&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%2F4c7o7w4s77paqrgqjl00.jpg" 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%2F4c7o7w4s77paqrgqjl00.jpg" alt="Image description" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll have three parties involved in the Escrow:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Depositor&lt;/strong&gt; - The payer of the Escrow, makes the initial deposit that will eventually go to the beneficiary.&lt;/p&gt;

&lt;p&gt;** Beneficiary** - The receiver of the funds. They will provide some service or good to the depositor before the funds are transferred by the arbiter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arbiter&lt;/strong&gt; - The approver of the transaction. They alone can move the funds when the goods/services have been provided.&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%2Fp4q1vvrxn3ndqhmlmzrr.jpg" 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%2Fp4q1vvrxn3ndqhmlmzrr.jpg" alt="Image description" width="619" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Events in Solidity.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Mon, 02 Jan 2023 06:43:10 +0000</pubDate>
      <link>https://dev.to/abhaypatel/events-in-solidity-4d5d</link>
      <guid>https://dev.to/abhaypatel/events-in-solidity-4d5d</guid>
      <description>&lt;p&gt;Events in Solidity.&lt;br&gt;
**Events are the way Solidity **and the EVM provides developers with logging functionality used to write information to a data structure on the blockchain that lives outside of smart contracts’ storage variables.&lt;/p&gt;

&lt;p&gt;Events are an abstraction on top of the EVM’s low-level logging functionality, opcodes LOG0 to LOG4. The specific opcode used will depend on the number of topics the event declares using the indexed keyword. A topic is just a variable that we want to be included in the event and tells Solidity we want to be able to filter on the variable as well.&lt;/p&gt;

&lt;p&gt;The low-level logs are stored in the transaction receipt of the transaction under the transaction receipts trie. Logs are written by the smart contract when the contract emits events, but these logs cannot be ready by the smart contract. The inaccessibility of the logs allows developers to store data on-chain that is more searchable and gas efficient than saving data to the smart contract’s storage variables.&lt;/p&gt;

&lt;p&gt;Events are defined in smart contracts using the event keyword. Here is the transfer event from the ERC20 smart contract. It is emitted whenever tokens are transferred from 1 account to another.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tDHadTHY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pkm8qi6d9ah6y9ik0go.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tDHadTHY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pkm8qi6d9ah6y9ik0go.jpg" alt="Image description" width="579" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here we can see the different components of an event:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;the event's name Transfer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;the event's topics from (sender's address), to (the receiver's address), value (the amount transferred).&lt;/p&gt;

&lt;p&gt;if a variable in the event is not marked as indexed it will be included when the event is emitted, but code listening on the event will not be ablel to filter on non-indexed varables (aka topics).&lt;/p&gt;

&lt;p&gt;Whenever a Transfer event is emitted, the from, to and value data will be contained in the event.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Emiting Events&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n-qJYH6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xiax04dm2a4wkasz5a1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n-qJYH6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xiax04dm2a4wkasz5a1.jpg" alt="Image description" width="529" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once an event has been defined we can emit the event from the smart contract. Continuing on from the ERC20 smart contract let's see where the Transfer event is emitted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Listening to Events&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you remember the definition of an Event from above, smart contracts can write events, but not read events. So how do we listen/read to data that smart contracts cannot read?&lt;/p&gt;

&lt;p&gt;We listen to and read events from code connected to a provider. From what we've learned so far in this course we could do this in JS code using an ethers provider to connect to a contract and listen to transfer events and do something with the event data.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>solidit</category>
    </item>
    <item>
      <title>Mappings in Solidity</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Fri, 30 Dec 2022 13:18:05 +0000</pubDate>
      <link>https://dev.to/abhaypatel/mappings-in-solidity-3335</link>
      <guid>https://dev.to/abhaypatel/mappings-in-solidity-3335</guid>
      <description>&lt;p&gt;&lt;strong&gt;Mappings in Solidity&lt;/strong&gt;&lt;br&gt;
Have you ever heard of a hash table? If you've taken one or two computer science courses, chances are you have! If not, don't worry, you're in the right place. Let's jump in… 🛩&lt;br&gt;
A hash table is a data structure that implements an associative array (also referred to as a "dictionary"). In an associative array, data is stored as a collection of key-value pairs. The position of the data within the array is determined by applying a hashing algorithm to the key.&lt;br&gt;
As seen above, a key represents some data to be stored in the hash table data structure. That key is fed into a hash function which produces a hash value. That hash value dictates the index where the data, pertaining to the key, will be stored in the hash table. 🧩&lt;br&gt;
Any time you "look up" (hence why hash tables are referred to as "dictionary" data structures!) a value by key, you will get whatever value is stored in the hash table back. Hash functions are deterministic, so you will always get the same value back as long as you provide the same key.&lt;br&gt;
Hash Table Data Structures Are Efficient 🏎&lt;br&gt;
Hash tables enable very efficient searching, in fact, they enable the "holy grail" O(1) search time. Hash tables do not require a brute force search or a for loop to look up a value thanks to the deterministic nature of hash functions! 🐐 You can just say, gimme whatever value is held at this key and the hash table data structure will comply. ⚡️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mappings&lt;/strong&gt;&lt;br&gt;
In Solidity, hash tables are called mappings. They function pretty much the exact same as hash tables. 🤷&lt;br&gt;
Mappings act as hash tables which consist of key types and corresponding value type pairs.&lt;br&gt;
They are defined like any other variable type in Solidity:&lt;br&gt;
**&lt;br&gt;
mapping(_KeyType =&amp;gt; _ValueType) public mappingName;**&lt;br&gt;
&lt;strong&gt;mapping(_KeyType =&amp;gt; _ValueType) public mappingName;&lt;/strong&gt;&lt;br&gt;
**&lt;br&gt;
Useful for address Association&lt;br&gt;
&lt;strong&gt;Solidity mappings are particularly useful for address association.&lt;/strong&gt;&lt;br&gt;
Thanks to mappings, you can associate an Ethereum address to a specific value. Here are a few examples we could use address association for:&lt;br&gt;
Keeping track of how many sodas a user has purchased from a vending machine smart contract:&lt;br&gt;
&lt;strong&gt;mapping(address =&amp;gt; uint) public sodasPurchased;.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>How to Unit Test a Smart Contract.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Fri, 30 Dec 2022 12:11:47 +0000</pubDate>
      <link>https://dev.to/abhaypatel/how-to-unit-test-a-smart-contract-5d03</link>
      <guid>https://dev.to/abhaypatel/how-to-unit-test-a-smart-contract-5d03</guid>
      <description>&lt;p&gt;&lt;strong&gt;Guide Requirements&lt;/strong&gt;&lt;br&gt;
Hardhat: Hardhat is an Ethereum development platform that provides all the tools needed to build, debug and deploy smart contracts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5XiiDIWk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3y10izxsepfs9y55pud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5XiiDIWk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3y10izxsepfs9y55pud.png" alt="Image description" width="880" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Useful JS + Solidity Testing Resources&lt;/strong&gt;&lt;br&gt;
We will use these resources throughout this guide but bookmark these for any other testing you do!&lt;br&gt;
**&lt;br&gt;
ChaiJS**&lt;br&gt;
&lt;strong&gt;Chai BDD Styled&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Chai Assert&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Mocha Hooks&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Solidity Chai Matchers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Hardhat Project Structure Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In a directory of your choice, run npm init -y&lt;br&gt;
Run npm install --save-dev hardhat&lt;br&gt;
Run npx hardhat and you will get the following UI on your terminal:&lt;/p&gt;

&lt;p&gt;*Select Create a JavaScript project&lt;br&gt;
*Select YES to all of these options!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your project should now contain the following:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Files: node_modules, package.json, hardhat.config.js, package-lock.json, README.md&lt;br&gt;
Folders: scripts, contracts, test&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Run npx hardhat test in your terminal &lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SCQhM1QR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rdpxjdyelh6gs2g8elnh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SCQhM1QR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rdpxjdyelh6gs2g8elnh.png" alt="Image description" width="880" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>testing</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>Ethereum Messages</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Wed, 28 Dec 2022 07:50:16 +0000</pubDate>
      <link>https://dev.to/abhaypatel/ethereum-messages-34ei</link>
      <guid>https://dev.to/abhaypatel/ethereum-messages-34ei</guid>
      <description>&lt;p&gt;&lt;strong&gt;When we have an Externally Owned Account and we want to communicate with the Ethereum Network we broadcast a transaction. Inside this transaction we can choose to send data which is bytecode intended to interact with the EVM.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If we don't send data then there's no intention to interact with the EVM. This is the case for simple ether transfers from one address to another.&lt;/p&gt;

&lt;p&gt;The data, often refered to as the calldata, is used to pass a message into the EVM. It will target a specific contract account (could be either a contract or library in Solidity terms) which may also make calls to another contract account. Every time a contract account calls into another contract account it forms a message. This message includes its sender address, the targeted function signature, and the amount of wei sent.&lt;/p&gt;

&lt;p&gt;In Solidity we have access to these message through global variables:&lt;br&gt;
**&lt;br&gt;
msg.data (bytes) - the complete calldata&lt;br&gt;
msg.sender (address) - the address sending the message&lt;br&gt;
msg.sig (bytes4) - the targeted function signature&lt;br&gt;
msg.value (uint) - the amount of wei sent&lt;br&gt;
**&lt;/p&gt;

&lt;p&gt;Wondering why the msg.sig is 4 bytes? This value is actually the first four bytes of the keccak256 hash of the function signature. It provides a way to uniquely identify (and target) the functions on a smart contract without worrying about how long the function signature is. Otherwise you could potentially store a reallyLongNameForAFunction and the calldata would need to store all of this information to invoke that function! &lt;/p&gt;

</description>
      <category>opensource</category>
      <category>ai</category>
    </item>
    <item>
      <title>EOAs - Externally owned Account.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Tue, 27 Dec 2022 17:13:02 +0000</pubDate>
      <link>https://dev.to/abhaypatel/eoas-externally-owned-account-cmo</link>
      <guid>https://dev.to/abhaypatel/eoas-externally-owned-account-cmo</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hfqeRMHZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5uhr5lg0x6fmapbxyawp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hfqeRMHZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5uhr5lg0x6fmapbxyawp.jpg" alt="Image description" width="880" height="614"&gt;&lt;/a&gt;**&lt;/p&gt;

&lt;p&gt;What are the two types of accounts in Solidity?**&lt;br&gt;
**&lt;br&gt;
Externally Owned Accounts** - All transactions originate from an EOA, they are controlled by a private key which signs off on the transaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Smart Contract&lt;/strong&gt; - This is code deployed to the blockchain. It is programmed to respond to different inputs sent by EOAs or other contracts.&lt;/p&gt;

&lt;p&gt;contract SpecialNumber {&lt;br&gt;
    address author1;&lt;br&gt;
    address author2;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;What's something we can do with EOAs? We can pay them! Let's do that. Any time this contract receives ether, let's send half to author1 and half to author2.&lt;/p&gt;

&lt;p&gt;A payable function is one that can receive ether. The receive function is a special function that will be invoked when a smart contract receives ether. We'll touch on this further later on.&lt;/p&gt;

&lt;p&gt;contract SpecialNumber {&lt;br&gt;
    address author1;&lt;br&gt;
    address author2;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;receive() external payable {
    // msg.value is passed to this contract
    uint totalValue = msg.value;

    // make a call to author1 sending half of the ether
    (bool success1, ) = author1.call{ value: totalValue / 2 }("");
    require(success1);

    // make a call to author2 sending half of the ether
    (bool success2, ) = author2.call{ value: totalValue / 2 }("");
    require(success2);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
**&lt;br&gt;
The .call method&lt;br&gt;
The curly brace {} syntax&lt;br&gt;
The empty string argument passed in ("")&lt;br&gt;
The return value (bool success1, )**&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Call&lt;/strong&gt;&lt;br&gt;
First let's talk about call. The call method is something you'll find on every address type when you want to send input data or ether to an address. When you do this, you'll be making something called a message call. You'll often hear this terminology used to describe a call to a smart contract. We differentiate this from a transaction, which is object signed by the EOA sent to the blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Curly Braces&lt;/strong&gt;&lt;br&gt;
The curly braces which comes after call {} provides an opportunity to override the value and gas parameters on the message call. The gas parameter will be relevant when we start calling smart contract addresses. When you leave it unspecified it will forward along all the gas remaining that the transaction sender designated (through the gasLimit parameter on the front-end, remember?).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Empty String Argument&lt;/strong&gt;&lt;br&gt;
You can see where passing in an empty string here. If you were trying to target a function on a smart contract this is where your calldata would go. The calldata will specify the function you're trying to call as well as the arguments you are sending. In this case, we're just trying to send ether to an EOA, so we pass an "" to indicate there is no calldata.&lt;br&gt;
**&lt;/p&gt;

&lt;p&gt;Return Value**&lt;br&gt;
The (bool success1, ) part probably looks a bit confusing! Remember how in the previous lesson we wrote a contract that can return multiple values? The call method returns multiple values. Solidity will warn you if you don't use the first value returned, which indicates if the message call was successful or not. In most cases, we will want the transaction to fail if a message call fails. The code require(success1) will do just that. We'll take about require further very shortly!&lt;/p&gt;

&lt;p&gt;THANKS!!!!&amp;gt;.......&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create your own private blockchain using Ethereum.</title>
      <dc:creator>AbhayPatel98</dc:creator>
      <pubDate>Tue, 27 Dec 2022 11:30:00 +0000</pubDate>
      <link>https://dev.to/abhaypatel/create-your-own-private-blockchain-using-ethereum-11m9</link>
      <guid>https://dev.to/abhaypatel/create-your-own-private-blockchain-using-ethereum-11m9</guid>
      <description>&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%2Fav3tz211miurshxjq3kx.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%2Fav3tz211miurshxjq3kx.png" alt="Image description" width="800" height="423"&gt;&lt;/a&gt;The Ethereum private blockchain is a blockchain like Ethereum, but the network used is not the Ethereum Main. When you use a private network all blockchain is totally apart from the Ethereum blockchain, it's possible to change the configurations like mining difficulty, access, and other aspects.&lt;/p&gt;

&lt;p&gt;😁 Follow the next steps to build your Private Blockchain.&lt;br&gt;
1-Install Geth&lt;br&gt;
2-Define Genesis Block&lt;br&gt;
3-Start the first blockchain node&lt;br&gt;
4-Start the second blockchain node&lt;br&gt;
5-Create the peer-to-peer connection&lt;br&gt;
6-Mining Blocks and Creating Transactions.&lt;/p&gt;

&lt;p&gt;Boot Node - The advantage of a boot node is it connects all the nodes, it would not mine blocks.&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
