<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fazal Mittu on Medium]]></title>
        <description><![CDATA[Stories by Fazal Mittu on Medium]]></description>
        <link>https://medium.com/@fazalmittu?source=rss-5f504abd96ed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*l10tPgzQs7rHlbgO1EAJyQ.jpeg</url>
            <title>Stories by Fazal Mittu on Medium</title>
            <link>https://medium.com/@fazalmittu?source=rss-5f504abd96ed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 21:33:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fazalmittu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Intro to Transformers for a Beginner]]></title>
            <link>https://fazalmittu.medium.com/intro-to-transformers-for-a-beginner-825185b36e75?source=rss-5f504abd96ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/825185b36e75</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Fazal Mittu]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 01:14:50 GMT</pubDate>
            <atom:updated>2024-01-16T01:14:50.239Z</atom:updated>
            <content:encoded><![CDATA[<h4>Ideal for the Non-Technical Background</h4><p><em>Hi my name is </em><a href="http://fazalmittu.com/"><em>Fazal</em></a><em> and I am a freshman at UC Berkeley. The following document is a collection of my learnings/understanding of transformer models. Follow along as I explain the novel architecture and build my own from scratch to really understand the inner workings. This document is meant for people of all levels of expertise, and should only require a curious, thoughtful mind.</em></p><h3>Introduction</h3><p>With the rise of AI like ChatGPT and Google’s Bard, the race to building the world’s first fully sentient AI is underway. We have to recognize that when trying to train a ChatGPT level chatbot, we have to teach a system how to go from zero knowledge of a language to a system that is “smart” enough to convey ideas thoughtfully. Several major companies are trying their luck at constructing and training their own models with unique datasets, parameters, frameworks, etc. While each of these models are constructed differently, they actually all have the same underlying architecture that allows them to work so well. This novel architecture is known as the transformer.</p><p>Transformers are a kind of machine learning model that are used for sequence to sequence modeling. The most simple explanation of a transformer is a model that can take an input sequence, and generate an output sequence. Some examples include language translation or summarization. In both cases, the model expects a collection of words (input sequence) and outputs a new collection of words (output sequence).</p><p>With so much innovation happening at this front, I found myself wondering how these transformers actually worked. How can I ask these systems a question about any random topic and get an instantaneous response that is not only accurate, but also given to me in a conversational manner as if I was talking to another person? Let’s dive in.</p><p><em>In the remainder of this document, I will be referring to a transformer used for text to text generation.</em></p><h3>What Makes Transformers Better Than Other Models?</h3><p>In our daily lives, whether we are talking to a friend, solving a math problem, or even microwaving something, we often use our past experiences or memories to help us make informed decisions in the present. We do this without even thinking for the most part; even in linear algebra, we still remember how to factor because we learned how to years ago. When we are deciding what to eat out for dinner, we take into consideration that just a week ago we already had Chinese food. While this idea of extracting relevant thoughts from the past and using them to make judgements is second nature for us, it is not so easy for an AI. How can we tell our model which “memories” it should be using as well as how relevant they even are? Transformers ultimately aim to solve this problem and it is why they are so good at tasks like question answering or summarization. It is the idea that they are able to actually understand and learn from context.</p><p>This idea I just described is what is known as attention. In essence, attention allows the model to focus on specific parts of its input sequence when generating the output sequence, which significantly enhances its ability to understand context and generate accurate results.</p><p>To understand, let’s use an example of a transformer whose job is to predict the next word in a sentence. Say the input sentence is “I love the colors red and ” and we would like the output sequence to be just “blue.” Attention basically allows the model to look at the sentence it was given and find links between different words. For example, our transformer may learn that “red” is what is known as a “color” and that “and” means the output should include another “color” to complete the thought. While the actual computations are a bit more complex, this simple explanation accurately represents how a transformer learns and logically deduces what the next word may be.</p><p>With this example, you may realize how the idea of attention can be powerful especially when given a much longer input sequence. If your transformer receives a paragraph as input, it is able to create more links between words, effectively increasing its understanding of the overall input. This concept is specifically known as self-attention as it involves the transformer looking solely at its input sequence.</p><h3>Transformer Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rleBlRHHPbWChFtS" /></figure><p>This image which shows the inner workings of a transformer is by far the most straightforward way to understand how the model works — that is, once you actually know what all the components actually do. At first glance we can see that this diagram contains 2 separate blocks. The one on the left is an <strong>encoder</strong> and the one on the right is the <strong>decoder</strong>.</p><p><em>In this document, I will focus more on the decoder and touch only slightly on the encoder. The reason for this is because transformers don’t always even need an encoder; in fact, decoder only transformers excel in generating coherent sequences based on contextual information. Many state of the art models such as OpenAI’s GPT4 happen to be decoder only transformers.</em></p><p>Let’s unpack this diagram and first understand each individual piece one at a time. Remember that all my examples and explanations are in the context of a transformer that is using sentences as input/output sequences. Oftentimes in other tutorials or transformer explanations, you may see them use the word “token.” Keep in mind that “tokens” or “words” are interchangeable and just the parts that make up the sequences that go in and out of the model.</p><h3>Parts of the Transformer</h3><h4><strong>Embeddings and Positional Encoding</strong></h4><p>Before we get started though there is a large problem that we haven’t addressed. A computer is really good at understanding numbers; however, it has no way of understanding human language. We need a way to represent letters and words as numbers so that a machine can actually read them. We also need to make sure that these numbers maintain the words’ meanings and can be changed back into words eventually. This is where embeddings come in.</p><p>An <strong>embedding</strong> is a way of representing words as vectors of real numbers. The goal is to create these vectors in such a way that words with similar meanings have vectors that are close together in this vector space. This way, we’re not only representing the words in a way that the model can understand, but we’re also preserving the semantic relationships between words. For example, the words ‘king’ and ‘queen’ might be represented by vectors that are close together in this space, reflecting their related meanings.</p><p>While the meanings of the words themselves are important, there’s another piece of information that’s crucial for understanding the meaning of a sentence: the order of the words.</p><p>Consider the sentences: “The cat chased the mouse” and “The mouse chased the cat.” The only difference between these sentences is the order of the words, but that difference changes the entire meaning of the sentence.</p><p>To ensure our model takes into account the order of the words, we use something called <strong>positional encoding</strong>. This is an additional vector that we add to the embedding for each word, and it represents the position of the word in the sentence. This way, the model has access to information about both the meaning of the word (from the embedding) and its position in the sentence (from the positional encoding).</p><p>With both the embeddings and positional encodings, we’re now ready to pass our sentence into the transformer, where it can begin the complex task of understanding and generating language.</p><h4>Multi-Head Attention</h4><p>We talked earlier about self-attention and why it is so powerful. If we implement self-attention with just one “head,” we just compare the final word of the sequence to all the preceding words. This means for a sentence like “I like to eat apples,” we are comparing “apples” to ”I”, “like”, “to”, and “eat.” The issue with this approach is there is a lot of lost context. For example we aren’t comparing the words “like” and “I” at all. Out of the many relationships of words, we would only be focusing on a few.</p><p>This is the problem that <strong>multi-head attention</strong> solves. If we used multi-head attention with 4 heads in the example above, we would compare each word of the sentence with “apples”, “eat”, “to”, and “like.” You can see that by increasing the number of comparisons we take into account, we increase the amount of context our model has.</p><h4>Masked Multi-Head Attention</h4><p>In the diagram above we see two kinds of attention: masked and regular.</p><p>To explain why this is helpful we need to delve further into how an input sentence actually gets processed. For the sentence “I like to eat apples” we actually get a total of 4 training samples for the model. Remember that the overall goal of a transformer is to predict the next word in a sentence. Therefore we can train the model to predict the next word 4 different times for a sentence with 5 words:</p><p>“I” → “like”</p><p>“I like” → “to”</p><p>“I like to” → “eat”</p><p>“I like to eat ” → “apples”</p><p>But the issue is that if we use traditional self attention, then we can only extract 1 training example instead of the 4 we see above. In general in machine learning, the more data the merrier. Getting rid of these examples significantly hinders our model’s ability to learn. In order to maximize the training examples we can get out of a single sentence, we have to implement a <strong>masked self attention</strong>.</p><p>When we use masked self-attention in the decoder, we prevent the model from seeing future words in the sequence. This is essential during training because we want the model to predict the next word based on the previous words only, not future ones. If we give it the entire sentence, it will obviously be able to guess the next word because it has already seen it. This means that for masked self-attention for the second example above: “I like” → “to,” the only words that we compare to each other are “I” and “like.” Intuitively, if we also compared “to” (next word in sequence) to “I” and “like,” then the model would already know that “to” is the next word in the sequence and no learning would actually occur. It’s as if we give a student a homework problem but they just copy the answer down and submit it; no learning occurs.</p><h4>Feed Forward</h4><p>After we pass through a multi-head attention layer, we add a feed forward layer which is essentially just a simple neural network with a few layers. But why do we even need this?</p><p>We can think of the attention layer as a way of gathering all the clues we need to solve the mystery; however, even if we have all the clues, we still need one final layer of logical reasoning to put them all together. In our case, this final layer of reasoning is the feed forward layer. The more technical explanation is that the attention step is a linear layer. In machine learning, we often use non-linear functions to add a level of depth to the system so that it can extrapolate patterns that may not be so obvious.</p><p>If we were to take out this layer, it may end up with a very basic understanding of the English language but it would certainly not be on par with a human’s understanding. This feed forward layer is what allows the transformer to learn when certain words should be emphasized, when to rearrange a sentence to make it more concise, or how to use pronouns/antecedents correctly.</p><h4>Layer Normalization</h4><p>We aren’t going to cover layer normalization in depth because it is difficult to understand why we actually need it. To get a tiny grasp of why it may be useful, just remember that we are trying to give our model the most optimal learning environment. Let’s use an example to understand.</p><p>Imagine you’re baking a cake. When you mix the ingredients together, you want each part of the batter to be consistent. You don’t want some parts to be too wet and others too dry. In a way, neural networks are like recipes for solving problems. Layer normalization is a technique we use to make sure each “ingredient” (or neuron) in the network is working well together.</p><p>Now, in the world of neural networks, we have these layers of neurons that process information. Sometimes, these layers can get a bit too excited or not excited enough. It’s like having some ingredients in your cake batter too hot and others too cold. This can make the network’s job harder because the information it’s working with is not consistent.</p><p>Layer normalization steps in like a chef checking the temperature of all ingredients. It makes sure that the values coming out of each neuron are just right, not too hot or too cold. This helps the neural network learn more efficiently and makes the whole process smoother, just like baking a perfect cake.</p><p>In simpler terms, layer normalization is like making sure all the cooking ingredients in your recipe are at the right temperature, so your neural network (or recipe) can work better and produce a more accurate result.</p><h3>How the Blocks Fit Together</h3><p>There are 2 ways we can build a transformer. The first includes the encoder and the second leaves it out. Let’s start with the encoder and decoder strategy.</p><h4>Encoder and Decoder</h4><p>The simplest way to think of the encoder and decoder framework is through the example of text translation. Let’s say we want to make a transformer that can translate text from French to English. In this case, it would be the encoder’s job to extrapolate meaning from the French sentence and then pass that in to the decoder. The decoder would then be tasked with actually translating the sentence word by word while maintaining a similar meaning to the original, French input.</p><p>We start by passing in a positionally encoded embedding (input sequence) into the <strong>encoder block</strong>. We can see above that the encoder block (left) contains 2 main pieces: the multi-head attention layer and a feed forward layer. Once the inputs are passed through this block a few times (denoted by N in the diagram), the output is a new sequence that is a much more meaningful representation of the input sequence. This representation has information about the relationships between different words and is the final output of the encoder that is eventually passed into the decoder.</p><p>Since the job of the encoder is done, let’s talk about the decoder. In the context of our example, the decoder starts by positionally encoding the output sequence (English sentence) and passes that into a masked self-attention layer. After going through this layer, the model essentially learns how each word in the English sentence makes sense with the preceding words. Remember that in masked attention, we want to maximize learning by using one input sequence to create multiple training samples for our model. So when we pass in our input sequence to this model, our model learns how different English words associate with each other similar to the encoder.</p><p>After the first masked multi-head self attention layer, is another multi-head attention layer where the encoder and decoder meet. The job of this layer is for the model to draw connections between French and English words. It compares words of the English sentence to words of the French sentence and learns how they relate to each other in an actual sentence. The final part of the decoder is a feed forward layer that allows the model to use what it has figured out about French/English words to draw deeper connections between the two languages. Remember that the feed forward layer is what gives the model the extra depth it needs to really figure out the intricacies of both languages and how they compare.</p><p>So, the transformer’s job is to act as a bridge between languages, taking a sentence in one language, encapsulating its meaning in a universal ‘machine language’, and then rendering that meaning in another language. It’s like the decoder is reading the decoder’s mind and translating its thoughts into English.</p><p>Now that we understand the encoder/decoder architecture, we can see how it can be useful for tasks such as text translation or text to code. Essentially any problem that involves converting a sequence into something new can take advantage of the encoder/decoder architecture.</p><h4>Decoder Only</h4><p>Now let’s talk about how the decoder only architecture works. In a decoder-only transformer architecture, the focus is solely on “transforming” an input sequence into an output sequence. This type of architecture is quite powerful and forms the basis for models like GPT, which generate human-like text.</p><p>Let’s understand this using an example. Suppose we’re training a transformer to generate a piece of news text based on a given headline. The input would be the headline, and the output would be the generated news text. The process starts a positionally encoded input sequence (the headline).</p><p>The encoded input then passes through a masked multi-head attention layer. Remember that the ‘attention’ mechanism allows the transformer to focus on different parts of the input sequence at different times, understanding the context and relationships between the words. Also recall that the ‘masking’ ensures that the model only considers the current and previous words, not the future ones, when predicting the next word. This way, the model learns to generate text that logically follows from the given input.</p><p>Next, the model goes through a feed-forward layer. This is a simple neural network that adds depth to the model’s understanding, allowing it to capture more complex patterns and relationships in the data.</p><p>The output of the feed-forward network is then used to predict the next word in the output sequence. The process repeats, with each new word being added to the input for the next prediction, until a full news text is generated from the given headline.</p><p>So, in summary, a decoder-only transformer architecture takes an input sequence, pays ‘attention’ to its context, learns from it using a feed-forward network, and generates a relevant output sequence based on what it’s learned. This makes it ideal for tasks like text generation, where the goal is to produce coherent and contextually relevant text based on a given input.</p><h3>Coding my Own Transformer</h3><p>After I had learned how the internals of the transformer worked, I sought out to build my own. I followed along Andrej Karpathy’s tutorials and annotated each line of code to make sure I understood the point behind each line, layer, and matrix operation. This implementation uses torch which is an excellent machine learning library that was very beginner friendly (this was my first time using it). The point of the transformer I trained be able to write in a style similar to Shakespeare. I had a file that contained all of Shakespeare’s works and randomly sampled input sequences from it for training data.</p><p>You can find the code here:</p><p><a href="https://github.com/fazalmittu/fazal_gpt">GitHub - fazalmittu/fazal_gpt</a></p><p>(Currently only the decoder implementation works; encoder still in the works)</p><p>While the explanation above is very beginner friendly, the code goes a little more in depth and explains the internals of the transformer. Specifically it implements the key, query, value method of self attention that we didn’t necessarily go over. It also implements layer normalization which we didn’t cover in depth.</p><p>I recommend going over the code and trying to understand how the structure of the code translates to the diagram we saw above. After coding the transformer, I have definitely gained a deeper understanding of the architecture and how intuitive operations like self attention really are.</p><h3>Conclusion</h3><p>And that’s it! You now have a solid understanding of how a transformer works and a good starting point for exploring this architecture further.</p><h3>Other Sources:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLAqhIrjkxbuWI23v9cThsA9GvCAUhRvKZ&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLAqhIrjkxbuWI23v9cThsA9GvCAUhRvKZ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FVMj-3S1tku0%2Fhqdefault.jpg%3Fsqp%3D-oaymwEXCOADEI4CSFryq4qpAwkIARUAAIhCGAE%3D%26rs%3DAOn4CLAsbch9qh_yKE5PEvVrJKLFzLfYYQ%26days_since_epoch%3D20593&amp;type=text%2Fhtml&amp;schema=youtube" width="853" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/38ffe4c8cb97f9a90ca241842fce9556/href">https://medium.com/media/38ffe4c8cb97f9a90ca241842fce9556/href</a></iframe><ul><li><a href="https://peterbloem.nl/blog/transformers">Transformers from scratch</a></li><li><a href="https://towardsdatascience.com/how-to-code-the-transformer-in-pytorch-24db27c8f9ec">How to code The Transformer in Pytorch</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=825185b36e75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Sport Betting DApp]]></title>
            <link>https://medium.com/visionary-hub/building-a-sport-betting-dapp-d5f1048ba524?source=rss-5f504abd96ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5f1048ba524</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[sports]]></category>
            <dc:creator><![CDATA[Fazal Mittu]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 22:50:23 GMT</pubDate>
            <atom:updated>2022-01-05T22:50:23.131Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I created my first DApp from scratch</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*gI5R4ITSHm3YXGy-" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.espn.com%2Fnba%2Fgame%2F_%2FgameId%2F401360034&amp;psig=AOvVaw3vUaoOrSoyRuK8BZKMuVvq&amp;ust=1641433793002000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCLjbiby_mfUCFQAAAAAdAAAAABAJ">GSW vs BKN</a></figcaption></figure><h3>Sports Betting</h3><p>Many avid sport fans enjoy placing bets on their favorite teams in an attempt to make profits. However, one problem is that many betting websites can be insecure and require a third party to handle and redistribute their money. But why place our <strong>trust </strong>in these intermediaries? This is where DApps come in.</p><h3>What is a DApp?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*a3RweVTvoxV1flK-.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.coindesk.com%2Flearn%2Fwhat-is-a-decentralized-application%2F&amp;psig=AOvVaw3O9PuTF_pgNQI6q8fws9rR&amp;ust=1641433879951000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCMjep-S_mfUCFQAAAAAdAAAAABAu">DApp</a></figcaption></figure><p>A decentralized application, or DApp, is an app that contains a smart contract and runs on a distributed network such as the blockchain. A smart contract is executable code on the blockchain that runs when certain conditions are met.</p><p>Smart contracts remove the need for intermediaries and allow for transactions to be governed and carried out solely by code. This means that all your money is handled by code rather than a potentially unreliable third party.</p><p>There are many protocols that can be used to build DApps but the main network and the one I used is Ethereum.</p><blockquote>In depth article I wrote on smart contracts:</blockquote><blockquote><a href="https://medium.com/visionary-hub/smart-contracts-are-the-future-962007fcb276">https://medium.com/visionary-hub/smart-contracts-are-the-future-962007fcb276</a></blockquote><h3>Contract Structure</h3><p>Before we breakdown the contract code, let’s list out functions/variables we may need and data we will need to store.</p><p><strong>Events</strong></p><ul><li>event NewBet: stores a new bet on the blockchain with address, amount bet, and team</li></ul><p><strong>Structs</strong></p><ul><li>struct Bet: contains name, address of user, amount they bet, and team they bet on</li><li>struct Team: contains name of the team and the total amount of ETH placed on their team</li></ul><p><strong>Variables/Mappings/Arrays</strong></p><ul><li>Bet[]: array containing all bets</li><li>Team[]: array containing all teams</li><li>address payable conOwner: address of the owner of the contract</li><li>uint totalBetMoney: total bets placed on both teams</li><li>mapping numBetsAddress: links address to a bet to ensure that each user only places one bet until a winner is chosen</li></ul><p><strong>Functions</strong></p><ul><li>createTeam(_name): can be called by owner to create a new team that bets can be placed on</li><li>getTotalBetAmount(_teamId): can be called to get total bet amount placed on a team</li><li>createBet(_name, _teamId): can be called by a user with msg.value to place a bet on a certain team (ETH transferrs to contract)</li><li>teamWinDistribution(_teamId): can be called by owner to make a team win and distribute ETH to winners accordingly</li></ul><p>Essentially, 2 teams that are preset (Warriors/Nets in this case) can be betted on. Each team has a unique ID (0/1) that a user can use to place a bet. Whenever a user places a bet, createBet is called and whenever the owner of the contract sets a team as a winner, teamWinDistribution is called.</p><p>My contract also utilized ownable.sol, ATM.sol, and console.sol. Ownable allows me to add function modifiers such as onlyOwner which only allows the contract owner to call a function. ATM is what I used to facilitate the transferring of ETH between accounts. Console is a library that helped with debugging and allowed me to view variables throughout the contract execution.</p><h3>Code Walkthrough</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7aceb034a8cb3db21fc22824056d010d/href">https://medium.com/media/7aceb034a8cb3db21fc22824056d010d/href</a></iframe><p>Line one is for the compiler and specifies what version of Solidity we aim to use. The import statements import all the external contracts/libaries we will use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7340fbd24553bae4bc39ac6964930ac/href">https://medium.com/media/e7340fbd24553bae4bc39ac6964930ac/href</a></iframe><p>In Solidity, an event is called whenever information needs to be stored on the blockchain. In this case, we wish to store all new bets on the blockchain with the user’s address, the amount of ether they bet, and the team that they placed a bet on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/281e50e88501581242ab309ce18b0c4b/href">https://medium.com/media/281e50e88501581242ab309ce18b0c4b/href</a></iframe><p>Structs are similar to objects in that they can store data and be used to create new instances. Each time a bet is placed, a new Bet is instantiated and placed into an array of Bets. The Team struct is mainly used to store the total bets that are placed on a team.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/612fdb0532d31b773f5312cf9f90279c/href">https://medium.com/media/612fdb0532d31b773f5312cf9f90279c/href</a></iframe><p>An array of Bets/Teams are kept to store all instances of the structs. The conOwner variable stores the address of the owner of the contract and is payable so that ETH can be transferred to the account. totalBetMoney starts off at 0 and is used to track total bets placed on both teams. It is updated whenever a new bet is created.</p><p>A mapping in Solidity stores key, value pairs. In this case, we link an address to a uint in order to keep track of how many bets a user makes. We want to ensure that each user can only make one bet at a time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a6e5ec6296c45eb99e2f338b9bc6ede/href">https://medium.com/media/6a6e5ec6296c45eb99e2f338b9bc6ede/href</a></iframe><p>The constructor is called whenever the contract is initialized. It sets conOwner to the msg.sender (or the person who calls the function). It also instantiates two teams that users can bet on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca293dc503d89c25486bed367e936330/href">https://medium.com/media/ca293dc503d89c25486bed367e936330/href</a></iframe><p>The first function is createTeam and it is a public function that takes one parameter called _name. This function pushes a new Team instance to the array of teams and is called inside the constructor.</p><p>The second function is getTotalBetAmount and it is a public view function meaning it retrieves data from the blockchain. This function takes in _teamId and returns the total bets placed on that team.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2f859f9f9f6ec4ec51164c00938e982/href">https://medium.com/media/b2f859f9f9f6ec4ec51164c00938e982/href</a></iframe><p>createBet is the first main function in the contract and takes in _name and _teamId as parameters. The function is external and payable meaning that it can be called by other contracts and also facilitate a transaction on the blockchain.</p><p>require statements are used to ensure certain preconditions are true before the code can execute. Firstly, the owner of the contract cannot place any bets. Second, a user can only place one bet. Lastly, the amount of Ether bet has to be greater than 0.01.</p><p>On line 8, a new Bet instance is created and pushed to the array of bets. If the _teamId parameter is 0, then the user is betting on team 0 and their totalBetAmount should be raised by msg.value. If the _teamId parameter is 1, then the other team’s totalBetAmount is raised by msg.value. The function then updates the numBetsAddress mapping to document that the user just created a bet and cannot make another.</p><p>Lines 19–20 use the call function to send the contract the amount of ETH that the user bets.</p><p>After the ETH is transferred, the totalBetMoney variable increases by msg.value and a new bet event is created on the blockchain.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d7f989fe0abb07983c81dcfc8af2f29/href">https://medium.com/media/8d7f989fe0abb07983c81dcfc8af2f29/href</a></iframe><p>teamWinDistribution is the second main function of this contract and it takes in one input _teamId. The function is public and payable meaning it can be called globally and also facilitate transactions. The function also has the onlyOwner modifier which means that only the owner of the contract can set a winner.</p><p>A variable named div is declared and will eventually hold the value that each user wins.</p><p>The function contains one large if/else allowing it to act differently based on which team wins. Each winner is distributed a different amount of ETH depending on how much ETH they originally entered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s6qIEww8tW0PrSni.png" /></figure><p>The equation above is used to determine how much ETH a winner gets and is translated to code in line 9. Because Solidity doesn’t support fixed or floating point numbers, we have to adjust this equation to accommodate. The final value in wei is stored in div.</p><p>Line 11/12 are used to send receiver (address of the current bet) the correct amount of ETH that they earned. After all transactions are complete, the totalBetMoney and totalBetAmount values for both teams are reset. Also, the numBetsAddress mapping is made empty so that each user is able to bet again.</p><h4>Testing Contract</h4><p>To test the contract, I used Remix primarily and also used truffle for basic checking. Furthermore, I used ganache to test transactions.</p><h3>Setting up Front-End Interaction</h3><p>After creating the contract, I decided to develop a small UI using React that runs on a local server. The most difficult part was integrating the functions and variables of the smart contract into the front end. Though it’s not the cleanest UI, it is fully functional and allows users to place bets and for only the owner to make a team win.</p><p>I purposely won’t be going very in depth on how the front-end was created as the main focus is the contract and back-end functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*CrgUb_3H0iJzm3D5VtQdKg.png" /></figure><h3>Conclusion/Takeaways</h3><ul><li>Smart contracts are very powerful and have a lot of authority in that they can control transactions and mutate the blockchain.</li><li>Gas prices are extremely volatile and can actually make or break your DApp — in my case, MetaMask’s gas limit was too low causing my transactions to fail at times.</li><li>Frontend Development is difficult and tedious but necessary; building out the UI allows anyone to utilize my contract with ease</li><li>Though this DApp probably won’t be used very widely, I had a great time building this project out and learned so much more about contracts/Ethereum transactions.</li></ul><h3>Github</h3><p><a href="https://github.com/fazalmittu/FazeBetting">GitHub - fazalmittu/FazeBetting</a></p><p><em>Hi my name is Fazal. I am a 16 year old based in the Bay Area of California. Connect with me on </em><a href="https://www.linkedin.com/in/fazal-mittu-b0b3491bb/"><em>Linkedin</em></a><em> and check out my </em><a href="https://github.com/fazalmittu"><em>Github</em></a><em> to see what other projects I am working on! Subscribe to my </em><a href="https://landing.mailerlite.com/webforms/landing/x2h3u1"><em>Newsletter</em></a><em> for monthly updates on what I am working on. If you would like to schedule a meeting, use my </em><a href="https://calendly.com/fazalmittu/30min"><em>Calendly</em></a><em>. Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5f1048ba524" width="1" height="1" alt=""><hr><p><a href="https://medium.com/visionary-hub/building-a-sport-betting-dapp-d5f1048ba524">Building a Sport Betting DApp</a> was originally published in <a href="https://medium.com/visionary-hub">Visionary Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Smart Contracts are the Future]]></title>
            <link>https://medium.com/visionary-hub/smart-contracts-are-the-future-962007fcb276?source=rss-5f504abd96ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/962007fcb276</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Fazal Mittu]]></dc:creator>
            <pubDate>Tue, 30 Nov 2021 14:42:18 GMT</pubDate>
            <atom:updated>2021-11-30T14:42:18.898Z</atom:updated>
            <content:encoded><![CDATA[<h4>A walkthrough and demonstration of smart contracts</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ipCe-PJbBODRNlu_.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.leewayhertz.com%2Fethereum-smart-contract-tutorial%2F&amp;psig=AOvVaw2qoECTPV6pLoFClngB3HXn&amp;ust=1638247827473000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCPiBt_HivPQCFQAAAAAdAAAAABAb">Smart Contract</a></figcaption></figure><p>In the 2020 US Presidential Election, there were a number of voting controversies which stemmed from a disorganized and somewhat chaotic voting system. From long lines to submit a ballot to votes being allegedly miscounted, the current voting system is ineffective and needs change. On a large scale, keeping track of votes and making sure everyone’s choice is counted becomes an exponentially harder task, especially when humans are in charge. It begs the question: why is such an important task that can potentially sway a nation designated to humans who can err and stir controversy as we saw in this election?</p><p>Rather than a procedure reliant on human judgement or decision, voting requires an unbiased management system that ensures privacy, accuracy, security, and fairness. This system comes in the form of a smart contract.</p><h3>What is a Smart Contract?</h3><blockquote>A smart contract is a mechanism involving digital assets and two or more parties, where some or all of the parties put assets in, and assets are automatically redistributed among those parties according to a formula based on certain data that is not known at the time the contract is initiated. — Vitalik Buterin, Co-Founder of Ethereum</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9miq1btbO9EDTQ3U.jpg" /><figcaption><a href="https://www.google.com/imgres?imgurl=https%3A%2F%2Fdcxlearn.com%2Fwp-content%2Fuploads%2F2020%2F06%2Finfo-03-scaled-1.jpg&amp;imgrefurl=https%3A%2F%2Fdcxlearn.com%2Fguide%2Fsmart-contracts%2F&amp;tbnid=06DOUmujco4F3M&amp;vet=12ahUKEwi7ksTM5Lz0AhXpATQIHbAJDPMQMygOegUIARDLAQ..i&amp;docid=wyyGnq9_brmFdM&amp;w=2560&amp;h=1140&amp;q=how%20does%20smart%20contract%20work&amp;ved=2ahUKEwi7ksTM5Lz0AhXpATQIHbAJDPMQMygOegUIARDLAQ">Smart Contract Diagram</a></figcaption></figure><p>Simply put, a smart contract is an <em>if/when … then</em> that is written into code. Two parties agree on certain terms that are translated to code and then added to the blockchain. Smart contracts automatically execute whenever a certain condition is met making them efficient.</p><p>Because it is on the blockchain, a smart contract is immutable and can never be changed once published.</p><h4><strong>Why Blockchain</strong></h4><p>It is important to recognize a few distinct features that set blockchain apart from traditional systems.</p><ul><li>Blockchain is decentralized meaning that no central authority controls transactions that take place over the network.</li><li>All transactions that take place on the blockchain are secured by cryptography and verified by every user on the network. This makes it difficult to tamper with the network and corrupt transactions for personal gain.</li><li>Every transaction that takes place on the blockchain is public record and can be viewed by anyone on the network.</li></ul><p>To break this information down, let’s go back to our voter example.</p><ul><li>Blockchain’s decentralized nature ensures that there are no third parties present in transactions. This means that when a user casts their vote, it is directly submitted without any intermediaries having to “count” or potentially tamper the vote. Furthermore, the exchange is more efficient and ensures the privacy of your vote as it is only code that is “reading” your ballot.</li><li>When you vote, you want to ensure that no singular entity is somehow rigging the election and winning unfairly. On the blockchain, “votes,” or transactions, are secured by cryptography and validated by each user on the network.</li><li>Casting a vote is useless if a mail-in ballot is lost or shipped to the wrong place. Using smart contracts and the blockchain allows for accurate data to be safely collected and stored. This ensures that the election will take everyone’s vote into account and reduces possible human error.</li></ul><h3>What Makes Smart Contracts Special?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iHnM0IZICeCJAbNX.png" /><figcaption><a href="https://www.google.com/imgres?imgurl=https%3A%2F%2Flvivity.com%2Fwp-content%2Fuploads%2F2018%2F06%2Fsc3.jpg&amp;imgrefurl=https%3A%2F%2Flvivity.com%2Fwhat-are-smart-contracts&amp;tbnid=LbJAmqqsJZjjHM&amp;vet=12ahUKEwiP343r5Lz0AhUEOn0KHVN3BzcQMygBegUIARCoAQ..i&amp;docid=nGyMItkN1GscKM&amp;w=750&amp;h=507&amp;q=smart%20contract%20pros%20and%20cons&amp;ved=2ahUKEwiP343r5Lz0AhUEOn0KHVN3BzcQMygBegUIARCoAQ">Comparison Table</a></figcaption></figure><p>There are two main benefits that smart contracts have over traditional contracts or agreements.</p><ul><li>They are written in code and immutable meaning that there is no third party managing the agreement.</li><li>Smart Contracts allow for an efficient, seamless transaction. Rather than requiring hours of negotiation and paperwork, smart contracts are digital and automated.</li></ul><h3>Where are Smart Contracts Used?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*gAREcfBOfOtNym5u.png" /></figure><h4>Voting System</h4><p>Smart contracts can make elections less susceptible to fraud or manipulation as votes would be kept secure on the blockchain. Because voting would be digital and easier, more people will be able to vote and participate in the election.</p><h4>Healthcare</h4><p>Blockchain and smart contracts can be used to ensure safety of a patient’s medical records. Smart contracts can also be used to administer proper medication and appropriate tests on patients.</p><h4>Supply Chain</h4><p>Supply chains can be made digital which will greatly improve their overall effectiveness and usability. Smart contracts can make inventory easier to manage and can automate payments.</p><h4>Financial Services</h4><p>Smart contracts can help with insurance claims by error checking and transferring payments once it is deemed appropriate. They also provide security for accounting records that need to be kept private.</p><h3>Pros and Cons of Smart Contracts</h3><p>While smart contracts do seem to solve many problems, there are a few downsides and areas in which they lack.</p><h4><strong>Pros</strong></h4><ul><li>Because smart contracts are immutable, an entity cannot change the agreement for personal gain.</li><li>Smart contracts automate transactions and remove the need for an intermediary to carry out an action. Rather than a bank transferring a user money which may take time, the smart contract automatically transfers a user the correct sum.</li></ul><h4><strong>Cons</strong></h4><ul><li>It is important to recognize that with smart contracts, there is no central authority that is managing the exchange. While this is beneficial for several reasons, it means that if a person is conned, there is little that can be done to reverse the action.</li><li>Furthermore, there is little government regulation for smart contracts and it is difficult for them to intervene in case of a scam or fraudulent activity. To a small degree, this limits smart contracts’ ability to be widely accepted and used for large scale agreements.</li><li>Because smart contracts rely heavily on code, their creation and reliability is dependent on developers. The issue is that there may be a slight disconnect between what the two parties agree upon and what the developer actually codes into the contract.</li></ul><h3>Smart Contract Creation/Walk-Through</h3><p>On the Ethereum blockchain, where smart contracts are most prevalent, smart contracts are coded in Solidity — a language that closely resembles JavaScript. The most common IDE for smart contracts is Remix, a browser text editor that allows for the creation and testing of smart contracts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BbTVBT3k4_1eW27v3Ellg.png" /><figcaption>Remix IDE</figcaption></figure><p>Remix gives a user account addresses already filled with ether that can be used for testing smart contracts.</p><p>To better demonstrate how smart contracts are instantiated, I will do a line by line overview of a simple smart contract I created. In the example below, the goal is to create a smart contract that allows for a parent to transfer their child a certain sum of money once they reach a certain age.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qT5611AHrWERIAhYdW0nQ.png" /><figcaption>Entire Program</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/292d126bab330299009d32e9af662ee7/href">https://medium.com/media/292d126bab330299009d32e9af662ee7/href</a></iframe><p>In any Solidity file, a pragma directive is always the first line as it specifies which compiler version should be used. In this smart contract I use version 0.8.1 which is not the latest version.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83cba0ff977d850a3b46023a76bfc785/href">https://medium.com/media/83cba0ff977d850a3b46023a76bfc785/href</a></iframe><p>This code block creates a “struct” which is similar to an object in that it can have multiple instances each with unique attributes. In this case, we create a struct called Kidthat houses three main variables: amount(how much money they get), maturity(how old they currently are), and paid(Boolean for if they have already been transferred the money).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c083b52f30a4b862fdd372063960c3b/href">https://medium.com/media/3c083b52f30a4b862fdd372063960c3b/href</a></iframe><p>This code block introduces two important variables. The first is a “mapping” which is a reference type that contains key, value pairs. In this case, we want each Kid to be mapped to their Ethereum address which allows us to access their specific attributes using their address.</p><p>The second line creates an variable of type “address” which in Solidity is a 20-byte value that has built in functions like transfer and balance. The variable admin stores the Ethereum address of the parent from whom the child will receive money.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dd6a3b61ff252202ff6611a9258170b/href">https://medium.com/media/1dd6a3b61ff252202ff6611a9258170b/href</a></iframe><p>This function is called a constructor and is used to initialize the instance variables of a contract. In our case, adminis initialized to msg.sender, or the person currently connecting with the contract.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/daf3d446a17383eafe378f1cce242333/href">https://medium.com/media/daf3d446a17383eafe378f1cce242333/href</a></iframe><p>In this code block, we create a function called addKidthat allows the parent to choose which accounts their money gets transferred to. The purpose of this is to ensure that the money being transferred reaches the right accounts.</p><p>In line 2 and 3 we have “require” statements that must be true in order for the function to execute. Line 2 checks if the person calling the function (msg.sender) is the admin because we want only the admin to be able to add a kid. Line 3 checks if the kid has already been added because there should be no duplicate children.</p><p>Line 4 finally adds the kid to the kids mapping and initializes amount, maturity, and paid.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1324aaa459e7dcf1443f34c3520734a2/href">https://medium.com/media/1324aaa459e7dcf1443f34c3520734a2/href</a></iframe><p>This final function called withdraw allows a kid to withdraw the money that their parents left for them. Notice that in line 1 we have the keyword payable which means that this function is capable of receiving Ether.</p><p>In line 3, we define a pointer to our kid using the storage keyword meaning that we are using data currently stored on the blockchain. Line 3 essentially allows us to access the information of the kid that is currently using the withdraw function.</p><p>Lines 5–7 use this information to ensure that the user calling the withdraw function is actually allowed to. Line 5 checks if the kid is old enough to withdraw the money, line 6 checks if the kid was added as a kid by the parent, and line 7 checks if the kid has already been paid or not.</p><p>After checking all these conditions, in lines 8–9, the function finally transfers the ether to the kid’s account and sets the paid Boolean value to true.</p><h3>Testing Your Smart Contract</h3><p>And that’s it! In just 30 lines of code we were able to create a simple smart contract. Now it’s time to test it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3riWSt2IjyYRqqL3R43AiQ.png" /><figcaption>Compile</figcaption></figure><p><strong>Step 1 (Blue)</strong>: Firstly, we need to compile our code to ensure that there are no errors. On the right tab, click the button boxed in blue to access the compiler.</p><p><strong>Step 2 (Green): </strong>Next we need to make sure we are compiling the right version of Solidity so that our code is accurately checked. In this example, we use Solidity version 0.8.1. The version in the green box should match the first line of your actual code.</p><p><strong>Step 3 (Purple):</strong> Finally once we ensure that all our settings are correct, we can click the compile button boxed in purple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hGFH4YRiaBAMHJtOMsfONg.png" /><figcaption>Deploy</figcaption></figure><p>When testing, Remix gives you 15 account addresses to test with each filled with 100 ether.</p><p><strong>Step 4 (Red): </strong>Make sure that the environment is set to JavaScript VM.</p><p><strong>Step 5 (Orange):</strong> Make sure that you select Ether as the currency being used.</p><p><strong>Step 6 (White):</strong> We need to select the correct contract that we are testing. Make sure you select the correct file name.</p><p><strong>Step 7 (Yellow)</strong>: Click the orange deploy button to deploy the contract and make it ready for testing. Notice that once you deploy the contract, the 100 ether in the first account changes to 99.99999. This is because in order to deploy a smart contract, a user must pay a small gas fee in ether.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBJ9ShrIj7O-KGnvlRKaxA.png" /><figcaption>addKid</figcaption></figure><p>Next we want to use the addKid function to add an address capable of receiving money.</p><p><strong>Step 8 (Blue): </strong>Click the Account dropdown boxed in blue and select the second address. Once it is selected, click the button highlighted in pink to copy the address. <strong>After copying, make sure you switch the selected address back to the first one as this is the admin.</strong></p><p><strong>Step 9 (Green): </strong>Change the value in the green box from 0 to 10. This means that when the child withdraws, they will receive 10 ether from the parent’s address.</p><p><strong>Step 10 (Purple): </strong>To call the addKid function, we are going to use the red button boxed in purple. Inside the textbox next to the button, paste in the address you just copied. After the address, we need to add a comma and then the number ten signifying that the user needs to ten seconds before withdrawing money.</p><p>It should look like: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, 10</p><p>After all this, you can click the red addKid button. You’ll notice that now your admin account should have 89.99999 ether as ten ether was given to the contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PhoO7ywmIICFhpyYm0TC_Q.png" /></figure><p><strong>Step 11 (Red): </strong>Click the Account dropdown boxed in red and select the second address which is the kid’s.</p><p><strong>Step 12 (Orange):</strong> After waiting 10 seconds (the value we entered when we used addKid), we can click the red withdraw button boxed in orange and you’ll notice that the account now has 109.99999 ether.</p><p>That is the end of the walk-through! As you can see, it is not difficult to create smart contracts and there is so much customization available to a developer. Furthermore, testing is easy and seamless with the Remix IDE.</p><h3>TL;DR</h3><ul><li>Smart Contract: code based contract between two entities that lives on the blockchain and executes when a certain condition is met</li><li>Smart Contracts are better than traditional contracts because they live on the blockchain and remove intermediaries from the process.</li><li>Smart Contracts also make transactions efficient, seamless, and cheaper.</li><li>A few applications of smart contracts are voting, healthcare, supply chain, and financial services.</li><li>While smart contracts seem great, they are heavily dependent on developers and cannot be managed by any central authority to settle possible disputes.</li></ul><h3>Sources</h3><ul><li><a href="https://www.tutorialspoint.com/solidity/solidity_mappings.htm">Solidity - Mapping</a></li><li><a href="https://corporatefinanceinstitute.com/resources/knowledge/deals/smart-contracts/">Smart Contracts</a></li><li><a href="https://www.ibm.com/topics/smart-contracts">What Are Smart Contracts on Blockchain? | IBM</a></li><li><a href="https://www.investopedia.com/terms/s/smart-contracts.asp">What Are Smart Contracts on the Blockchain and How Do They Work?</a></li><li><a href="https://ethereum.org/en/developers/docs/smart-contracts/">Introduction to smart contracts</a></li><li><a href="https://corpgov.law.harvard.edu/2018/05/26/an-introduction-to-smart-contracts-and-their-potential-and-inherent-limitations/">An Introduction to Smart Contracts and Their Potential and Inherent Limitations</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMTC8BHrmrJA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMTC8BHrmrJA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMTC8BHrmrJA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd511f4e336cd74a882c60629d8ac027/href">https://medium.com/media/dd511f4e336cd74a882c60629d8ac027/href</a></iframe><p><em>Hi my name is Fazal. I am a 16 year old based in the Bay Area of California. Connect with me on </em><a href="https://www.linkedin.com/in/fazal-mittu-b0b3491bb/"><em>Linkedin</em></a><em> and check out my </em><a href="https://github.com/fazalmittu"><em>Github</em></a><em> to see what other projects I am working on! Subscribe to my </em><a href="https://landing.mailerlite.com/webforms/landing/x2h3u1"><em>Newsletter</em></a><em> for monthly updates on what I am working on. Check out the </em><a href="https://sfhsmlclub.medium.com/"><em>Machine Learning Club</em></a><em> I founded and what projects we have completed so far. If you would like to schedule a meeting, use my </em><a href="https://calendly.com/fazalmittu/30min"><em>Calendly</em></a><em>. Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=962007fcb276" width="1" height="1" alt=""><hr><p><a href="https://medium.com/visionary-hub/smart-contracts-are-the-future-962007fcb276">Smart Contracts are the Future</a> was originally published in <a href="https://medium.com/visionary-hub">Visionary Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ethereum 2.0 - The Much Needed Upgrade]]></title>
            <link>https://medium.com/visionary-hub/ethereum-2-0-the-much-needed-upgrade-5bee3e4ffadc?source=rss-5f504abd96ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bee3e4ffadc</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Fazal Mittu]]></dc:creator>
            <pubDate>Tue, 02 Nov 2021 19:06:50 GMT</pubDate>
            <atom:updated>2021-11-03T02:06:17.003Z</atom:updated>
            <content:encoded><![CDATA[<h4>Exploring the Scalability Issues of Ethereum and What the Upgrade Brings</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*va4X0dqZ-4n-AAHJYttNHw.jpeg" /><figcaption><a href="https://unsplash.com/photos/uNXmhzcQjxg">Ethereum</a></figcaption></figure><h3>What is Ethereum?</h3><p>Ethereum is a <a href="https://medium.com/visionary-hub/a-guide-to-blockchain-4a61847ecbf7">blockchain</a> that houses a cryptographic currency called Ether and a programming language called Solidity. This article’s main focus is the <strong>cryptocurrency</strong> and overall structure of the blockchain.</p><blockquote>A cryptocurrency is a digital currency kept secure through cryptography eliminating the possibility of double spending and fraud.</blockquote><h4>Bitcoin/Cryptocurrency</h4><ul><li>Ever since the emergence of blockchain, one of the main applications and use cases has been digital currency and the idea of decentralized finance. Decentralized finance is the idea that transactions and exchanges can take place on the blockchain without the use of intermediaries such as banks.</li><li>Leading this pack is Bitcoin, the world’s first cryptographic currency and the most popular application of the blockchain.</li><li>Bitcoin is often compared to “digital gold” as there is a finite amount that can exist (~21 million BTC), it is very stable, and it cannot be counterfeited.</li></ul><blockquote>“Bitcoin is a scarce digital currency and store of value. While still volatile, it tends to be one of the most stable cryptocurrencies, with the longest history, and has been the most consistent and best performing investment asset year after year for the last 10 years.”</blockquote><blockquote>— Steve Ehrlich, CEO and co-founder at Voyager Digital, a crypto asset broker.</blockquote><h4>What Sets Ethereum Apart?</h4><p>Since Bitcoin’s conception, many other currencies and blockchains have been created, each unique in their own ways. One such blockchain is Ethereum which is often regarded by many as one of the most prominent and practical blockchains. But with thousands of such systems now available, what sets Ethereum apart?</p><blockquote>“When people compare Bitcoin and Ethereum, it’s a bit like comparing gold with electricity. They are both valuable but have very different uses.”</blockquote><blockquote>— Alex Adelman, CEO of Lolli</blockquote><p>Put simply, Ethereum is a platform on top of which other applications can exist. Ethereum is the first blockchain to feature <strong>smart contracts</strong> which allow for agreements or transactions to take place without the need of an intermediary. These smart contracts are essential for <a href="https://ethereum.org/en/developers/docs/dapps/">dapps</a>, or decentralized applications, which are apps that utilize a smart contract to execute some financial function on the blockchain. These apps are decentralized because their backend is controlled by smart contracts, meaning the app is controlled by the state of the network rather than a single entity.</p><h3>The Scalability Trilemma and Why Ethereum Needs Change</h3><p>As Ethereum and Bitcoin grow, many question their ability to sustain themselves and support the growing audience they attract. Ethereum founder Vitalik Buterin coined the term <strong>Scalability Trilemma</strong> to break this problem down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*fiE7ybFk9JGCDX3luabwdQ.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fcvj.ch%2Fen%2Ffocus%2Fbackground%2Fthe-blockchain-trilemma%2F&amp;psig=AOvVaw3b-FFNnsiBhpFJNiW6cAZX&amp;ust=1635965566205000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCNChxees-vMCFQAAAAAdAAAAABAJ">Scalability Trilemma</a></figcaption></figure><h4>Breaking Down the Scalability Trilemma</h4><p>The Scalability Trilemma builds off the idea that we can’t have everything. Essentially, as a cryptocurrency grows and upscales, it has to decide what properties and characteristics it wishes to improve on at the cost of efficiency in other areas. To explain this let’s look at the three main categories in this dynamic.</p><p><strong>Decentralization:</strong> Decentralization is the idea that no central authority is in control; rather, the system is controlled by a network of users paired with the system’s built-in <strong>trust</strong>. Blockchain’s decentralized and distributed nature is what makes it unique and such an appealing technology to many.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*kLSmSmOj9N99ly1AKDTJvg.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.askcody.com%2Fblog%2Fdecentralized-workplace-for-better-technology-adoption&amp;psig=AOvVaw3gtJHbG5KYlBtKyNoAGw52&amp;ust=1635965715881000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCOjNr66t-vMCFQAAAAAdAAAAABAJ">Decentralization</a></figcaption></figure><ul><li>Decentralization is not a black or white term; different systems can be more or less decentralized than others; for example, social media platforms such as Instagram are not decentralized at all while blockchains like Ethereum are very decentralized.</li><li>The main idea behind decentralized networks is that the power returns to the hands of the users, rather than a central authority or intermediary that holds a large percentage of the network’s value.</li><li>As cryptocurrencies scale, it becomes increasingly difficult to maintain their degree of decentralization. In cases such as Bitcoin, many are worried that mining (users compete to solve cryptographic puzzles first and are rewarded with responsibility of validating a transaction) is taking away from decentralization, as only users who have access to high powered mining rigs can validate blocks. This takes away from decentralization as the network benefits and rewards those with more money and resources.</li></ul><p><strong>Security: </strong>Decentralization and Security go hand in hand as the more decentralized a network is, the more secure it becomes. Regardless of size, blockchains are susceptible to a plethora of attacks as well as potential network limitations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXC2C4Jy-8zh05p7ZD-JkA.jpeg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.esa.int%2FSafety_Security%2FESA_practices_cybersecurity&amp;psig=AOvVaw2epf2R9jv8oszNqMDNZGby&amp;ust=1635965795265000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCIDeqdet-vMCFQAAAAAdAAAAABAD">Security</a></figcaption></figure><ul><li><strong>51% Attack</strong>: when an entity controls 50%&gt; of a network, it can validate fraudulent transactions for personal gain</li><li><strong>Sybil Attack</strong>: an entity can create fake users on a blockchain to gain majority control of the network. <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwi2xLHhivrzAhVDHzQIHfhqCL4QFnoECAcQAw&amp;url=https%3A%2F%2Fwww.sciencedirect.com%2Ftopics%2Fcomputer-science%2Fsybil-attack&amp;usg=AOvVaw1W4jHDaFZD1oM_BfUFhaUw">The Sybil attack is named after the book <em>Sybil,</em> a case study of a woman with multiple personality disorder.</a></li><li><strong>Penny Spending Attack</strong>: an attacker intentionally sends a large number of minute transactions to use up a node’s storage capacity disallowing it from approving any other transactions.</li><li>These are just a few examples of potential dangers that a blockchain faces. Thankfully, due to their decentralized nature and architecture, blockchains are already quite secure. For example, networks with proof of work consensus mechanisms utilize mining in order to securely validate and space out transactions for the network to process. This improves security as the likelihood of a malicious transaction being approved is lower. <strong>However, as the network upscales, transaction times become even slower and environmental damage increases in parallel.</strong></li></ul><p><strong>Scalability:</strong> Scalability is the number of users the network can support before it becomes too insecure or slow to process transactions effectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*QFuhMprlJPwARV4HilHRIw.jpeg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.logicata.com%2Fblog%2Fscalability-in-cloud-computing%2F&amp;psig=AOvVaw0VfOw0lQB3gP7QBYRDyqDS&amp;ust=1635965850413000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCOi2x-6t-vMCFQAAAAAdAAAAABAJ">Scalability</a></figcaption></figure><ul><li>The main concern when increasing scalability comes with security; as a network grows, it becomes more susceptible to certain attacks and infiltration.</li><li>Furthermore, as a network grows, consensus mechanisms such as Proof of Work become too slow and are unable to process transactions at a speed comparable to most centralized applications. Bitcoin can process 7 transactions per second which is the slowest of all cryptocurrencies due to its massive size. In comparison, Visa handles about 1700 transactions per second allowing it to support a larger audience and scale more efficiently.</li></ul><p>These three characteristics of blockchains go hand in hand and it is difficult for most to find a balance that works. Ethereum 2.0 is an attempt to find that balance and make upgrades that will improve the speed of transactions and allow for scalability.</p><h3>Ethereum 2.0 and What it Brings</h3><p>Now that we’ve identified the scalability trilemma and what prevents Ethereum from reaching its full potential, what does Ethereum 2.0 bring to the table and how can it help? Let’s delve into the main parts of this upgrade.</p><h4>Beacon Chain</h4><ul><li>The beacon chain’s main function is to change the <strong>consensus mechanism</strong> of Ethereum from <strong>Proof of Work (PoW)</strong> to <strong>Proof of Stake (PoS)</strong>. It will also facilitate the entry of shard chains into the network which we will discuss shortly.</li><li>The change in consensus mechanisms is one of the most important changes coming with Ethereum 2.0. Let’s explore PoW mechanisms and why many think PoS is the better choice.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*scKn9V_EsNoE9W3SYg6E2w.jpeg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fblockgeeks.com%2Fguides%2Fproof-of-work-vs-proof-of-stake%2F&amp;psig=AOvVaw2V7At4m738iqrWThWqDulb&amp;ust=1635964902000000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCND-9amq-vMCFQAAAAAdAAAAABAD">PoW vs PoS</a></figcaption></figure><p><strong>Proof of Work: </strong>In PoW systems, miners compete to solve complex cryptographic puzzles first to gain the privilege of validating a certain block. In return for their work, miners have a small amount of cryptocurrency deposited into their account.</p><p>The main problem with PoW systems is the damage they do to the environment since the rigs used by miners use a lot of electricity and energy.</p><blockquote>A report published in August 2018 by the U.S Senate Committee on Energy and Natural Resources claims that Bitcoin mining efforts consume roughly <strong>1 percent</strong> of the total global electricity consumption.</blockquote><ul><li>If Ethereum wishes to upscale, it has to adopt a more efficient and environmentally friendly consensus mechanism known as proof of stake.</li></ul><p><strong>Proof of Stake:</strong> PoS systems use a concept called <strong>staking</strong> to determine who gains the responsibility of validating a new transaction. Users can stake their own coins and the higher the stake, the higher the likelihood of them being chosen to validate a block becomes.</p><ul><li>This system is far more environmentally friendly as it does not require every user on the blockchain to own large, energy wasting rigs.</li><li>PoS also eradicates the <strong>51% attack</strong> because in order for it to be carried out, the user would have to carry 51% of the coins of a certain network. At that point it becomes detrimental to approve fraudulent transactions as they will be damaging a network they own the majority of.</li></ul><h4>Shard Chains</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*45eYoqykqDxoBFyXQXqF3g.jpeg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fvitalik.ca%2Fgeneral%2F2021%2F04%2F07%2Fsharding.html&amp;psig=AOvVaw2D9bWsCyhCsYXVtoZfnpR8&amp;ust=1635964405696000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCIifxr6o-vMCFQAAAAAdAAAAABAD">Shard Chain Structure</a></figcaption></figure><ul><li>To understand sharding let’s start with a small example: let’s say a class of 500 students just took a test. Rather than having one professor grade all the tests himself, it is more efficient to have a group of professors each responsible for grading certain sections of the class.</li><li>Though simple, this concept can be applied to decentralized networks and large blockchains as they grow. Instead of all transactions being reliant on the same chain, it would make more sense to have multiple chains to <strong>split the load of the network</strong>.</li><li>In Ethereum’s case, these new chains are known as <strong>shard chains</strong>. Shard chains help with <strong>scalability</strong> as they significantly decrease the load of the network which increases transactions per second.</li><li>Another important feature of shard chains is that they make it so that users do not need to access the whole network; rather, they only need data specific to the shard they have been assigned which is less computationally expensive. This means that users with simpler hardware can become transaction validators which improves <strong>decentralization</strong> as the more users in a decentralized network, the more secure it becomes.</li><li>At first release, these shard chains will not possess full functionality of the Ethereum Mainnet as they will be unable to run smart contracts, the main function of Ethereum. Researchers are still deciding whether it is necessary for these shard chains to be able to run code as they will already boost the network’s performance so greatly.</li></ul><h4>The Merge</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*24x5x9JvIrgqMlcx7rQkSA.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fethmerge.com%2F&amp;psig=AOvVaw0OQ_q7keFAjibEmG7CPwTL&amp;ust=1635964691401000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCNjQ8MWp-vMCFQAAAAAdAAAAABAV">The Merge</a></figcaption></figure><p>The merge is what will bring the Beacon Chain and the Ethereum Mainnet together. With the merge, Ethereum will fully shift to the PoS consensus mechanism and the Mainnet will become a shard chain connected to the Beacon chain.</p><h3>Time Frame: When Will We See Ethereum 2.0?</h3><p>Ethereum 2.0 is being released in 3 main phases.</p><p><strong>Phase 0|Beacon Chain: </strong>The beacon chain serves as the “main” chain in the Ethereum network and will be the structure on top of which shard chains can be built and maintained. <strong>Launched in 2020.</strong></p><p><strong>Phase 1|Shard Chains: </strong>Shard chains will be introduced with limited functionality to distribute the load of the network to multiple smaller chains. These chains will use the proof of stake consensus mechanism rather than the initial proof of work system the original Ethereum uses. <strong>Expected in 2022.</strong></p><p><strong>Phase 1.5 | The Merge:</strong> The current Ethereum Mainnet will join with the beacon chain, becoming a single shard on the new network. <strong>Expected in 2022.</strong></p><p><strong>Phase 2 | Fully Functional Shards/Network:</strong> In this stage, shard chains will be in full use and gain support for smart contracts and dapps. <strong>Expected in 2022.</strong></p><h3>TL;DR</h3><ul><li>Ethereum is a blockchain that supports smart contracts and the creation of decentralized applications.</li><li>When trying to upscale, blockchains encounter the Scalability Trilemma that consists of <strong>Decentralization, Security, and Scalability</strong></li><li>ETH 2.0 is Ethereum’s response to the problems the growing network may face as it brings upgrades that improve scalability, structure, and speed.</li><li>ETH 2.0 brings the <strong>Beacon Chain</strong>, <strong>Shard Chains</strong>, and conversion to a <strong>Proof of Stake</strong> consensus system.</li><li>The upgrades will be live some time in 2022.</li></ul><h3>Sources</h3><ul><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwiyq5P7rvrzAhXMFjQIHVOlC88QFnoECAkQAQ&amp;url=https%3A%2F%2Faakash-111.medium.com%2Fthe-scalability-trilemma-in-blockchain-75fb57f646df&amp;usg=AOvVaw3-MMo3OHjwj8TrfLyitHd_">The Scalability Trilemma in Blockchain</a></li><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwiW6dv0rvrzAhWxGDQIHX1zDKIQFnoECAMQAQ&amp;url=https%3A%2F%2Fethereum.org%2Fen%2Feth2%2Fbeacon-chain%2F&amp;usg=AOvVaw25yjygI8Z-hF2wmBttFctx">The Beacon Chain | ethereum.org</a></li><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwiau67trvrzAhWyOH0KHQ2XD0YQFnoECAYQAQ&amp;url=https%3A%2F%2Fethereum.org%2Fen%2Feth2%2Fshard-chains%2F&amp;usg=AOvVaw0EFgHi1nnIZU_pt-Q_zDHE">Shard chains | ethereum.org</a></li><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwj6qrWbr_rzAhUVOH0KHXX2A0wQFnoECAIQAQ&amp;url=https%3A%2F%2Fmoney.usnews.com%2Finvesting%2Fcryptocurrency%2Farticles%2Fbitcoin-vs-ethereum-which-is-a-better-buy&amp;usg=AOvVaw3nb1PFJvkzPskH6c8T-yhN">Bitcoin vs. Ethereum: Which Is a Better Buy?</a></li><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwjRy_u0r_rzAhWXJTQIHan6D8MQFnoECA8QAw&amp;url=https%3A%2F%2Fwww.investopedia.com%2Fterms%2Fp%2Fproof-stake-pos.asp&amp;usg=AOvVaw2dQYFYN02CvkkwIVUY-bN5">Proof of Stake (PoS)</a></li></ul><p><em>Hi my name is Fazal. I am a 16 year old based in the Bay Area of California. Connect with me on </em><a href="https://www.linkedin.com/in/fazal-mittu-b0b3491bb/"><em>Linkedin</em></a><em> and check out my </em><a href="https://github.com/fazalmittu"><em>Github</em></a><em> to see what other projects I am working on! Subscribe to my </em><a href="https://landing.mailerlite.com/webforms/landing/x2h3u1"><em>Newsletter</em></a><em> for monthly updates on what I am working on. Check out the </em><a href="https://sfhsmlclub.medium.com/"><em>Machine Learning Club</em></a><em> I founded and what projects we have completed so far. If you would like to schedule a meeting, use my </em><a href="https://calendly.com/fazalmittu/30min"><em>Calendly</em></a><em>. Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bee3e4ffadc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/visionary-hub/ethereum-2-0-the-much-needed-upgrade-5bee3e4ffadc">Ethereum 2.0 - The Much Needed Upgrade</a> was originally published in <a href="https://medium.com/visionary-hub">Visionary Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Blockchain ⛓]]></title>
            <link>https://medium.com/visionary-hub/a-guide-to-blockchain-4a61847ecbf7?source=rss-5f504abd96ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a61847ecbf7</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[market]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Fazal Mittu]]></dc:creator>
            <pubDate>Sun, 10 Oct 2021 06:54:50 GMT</pubDate>
            <atom:updated>2021-10-10T06:54:50.064Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RunzcgXHdUjdnLb2Wd6Lfw.jpeg" /><figcaption><a href="https://unsplash.com/photos/JrjhtBJ-pGU">Bitcoin</a></figcaption></figure><h3>Why Blockchain?</h3><p>My parents recently bought a car and for the first time, I got to sit through the entire process and see how it works. My first thought was why are we constantly going back to the dealership for hours on end? Why is the process so complex and involve so many contracts and signatures? Why can’t we just select a car we want, give them the money, and walk out with the car? This long, tedious process not only applies to buying a car but also to so many other tasks such as taking out a loan or transferring money globally.</p><p>All the examples listed above have one thing in common: the use of an intermediary to handle the transfer and exchange of money. When buying a car, the bank acts as a middleman that both the dealership and buyer <strong>trust</strong>. The problem is that this intermediary is what makes the process lengthy, costly, and at times risky.</p><p>What if there was a system that allowed us to remove the intermediary and allow transactions to involve only the two entities? This hypothetical exists in the form of the blockchain.</p><blockquote>Blockchain is a public ledger which cannot be tampered with because of its core decentralized nature and design.</blockquote><p><strong>Blockchain</strong> is a fairly recent technology with a variety of applications ranging from banking and financial services to healthcare. However, not many people are aware of this technology and exactly what separates it from traditional systems that we use today. Let’s delve deeper into this technology and explore how it works.</p><h3>Defining Blockchain and Its Functionality</h3><p>Put simply, blockchain is a publicly available, continuous record of who holds what. Anyone who has a copy can view and add records to the database but cannot alter or remove records that already exist.</p><p>The blockchain is comprised of interconnected “blocks” that have 3 parts</p><ul><li><strong>Data:</strong> any information relevant to the transaction. For example, Bitcoin details the sender, receiver, and amount of coins.</li><li><strong>Hash: </strong>the “fingerprint” or unique identifier for a block. Every time a change is made to a block, its hash changes</li><li><strong>Previous block’s hash:</strong> this is what creates the “chain” and keeps all blocks interconnected.</li></ul><h4>Hashing</h4><p>Each “block” in the blockchain points to the next one (except the genesis block). Remember that if the contents of a block change, then the hash changes as well. This means that if someone tampers with a block, its hash will change and will no longer be the same as the value stored in the block after it. While this property keeps the blockchain secure, it isn’t enough.</p><p>The issue is computers are very fast at calculating hashes and can calculate what the individual hashes of thousands of future blocks. With this information, they can change the hashes in all proceeding blocks allowing them to tamper with the blockchain. To avoid this, blockchain implemented a solution called proof of work.</p><h4>Proof of Work</h4><p>Proof of work essentially slows down the creation of new blocks and makes it so that new blocks aren’t immediately added to the ledger. Bitcoin for example, takes 10 minutes to calculate the proof of work and add a new block to the chain.</p><h4>Distributed Network</h4><p>The last piece of security the blockchain offers is the fact that it is a “peer-to-peer” network. This means that there is no central authority controlling the addition or alteration of blocks on the blockchain. When a new block wishes to be added, it must be verified by all the other users in the system. Once this block is approved, it can then be added to everyone’s copy of the blockchain. Let’s expand on this idea.</p><h3>What Makes Blockchain Different?</h3><p>One of blockchain’s most appealing qualities is its decentralized architecture. Let’s draw a comparison between a centralized and decentralized ledger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rll1BcY7W2eXQbfh.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.cbinsights.com%2Fresearch%2Fwhat-is-blockchain-technology%2F&amp;psig=AOvVaw2JiNAL5MM58GJXotBLRoUL&amp;ust=1633934575610000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCJiY4OCev_MCFQAAAAAdAAAAABAD">Decentralized Exchange</a></figcaption></figure><h4>Centralized Ledger</h4><p>A common example of centralized ledgers can be seen in banking. A bank often has two ledgers, one for its private use and one that it reveals to the public. In this case, the bank has the ability to tamper with the ledger and modify it with false values. This was one of the contributing factors to the financial crisis as it was difficult to determine whether the numbers being publicly shown were actually accurate.</p><p>In this example, it is clear that the central authority has too much power since it can tweak the numbers for self-benefit.</p><h4>Decentralized Ledger</h4><p>What makes blockchain different and such an appealing technology is the fact that it is <strong>decentralized</strong>. Rather than one central authority managing the ledger, transactions on the blockchain are validated by other nodes in the system. Furthermore, each transaction is available for all users on the system to see, increasing transparency and making sure that the true numbers cannot be hidden.</p><blockquote><strong>In order to tamper with just one block on the chain, a user must modify all existing blocks on the chain, calculate their proof of works, and take control of the peer-to-peer network.</strong></blockquote><h3>What Uses Does Blockchain Have?</h3><p>Now that we’ve talked about how this technology works, where can it be applied? Although many think cryptocurrencies are the only use of blockchain, it’s a diverse technology that can be applied to a plethora of spaces. Let’s list a few uses to get started.</p><ul><li>Banking/payments</li><li>Global money transfer instantly</li><li>Cybersecurity</li><li>Supply chain management</li><li>Forecasting</li><li>Networking/IoT</li><li>Insurance</li><li>Private transport</li><li>Cloud storage</li><li>Charity</li><li>Voter Verification</li><li>Healthcare</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*vOEsPDfFbQd0e4D4.jpg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.finsmes.com%2F2018%2F01%2Fmoney-transfer-companies-going-the-venture-capital-way.html&amp;psig=AOvVaw11gmj4zCFwdmUt409JB3ic&amp;ust=1633934648639000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCPicisyfv_MCFQAAAAAdAAAAABAJ">Global Exchange</a></figcaption></figure><h4>Money Transfer</h4><p>One of the main uses of blockchain and especially Bitcoin is the ability to <strong>transfer money</strong> quickly and easily. By eliminating the need for an intermediary, money transfer is instant and cheap. One example can be seen in El Salvador where Bitcoin was recently declared an accepted currency. <strong>20% of El Salvador’s GDP</strong> is comprised of international money transfers and the adoption of Bitcoin makes these exchanges more efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*TRBfC4xkGRo2bsLJ" /><figcaption><a href="https://unsplash.com/photos/T9CXBZLUvic">Voter</a></figcaption></figure><h4>Voter Verification</h4><p>A public ledger of immutable votes can make online voting a streamlined and viable option, since it can make an election harder to rig. Voters can also record their vote on the blockchain without the risk of releasing their identity or political ideas. Votes can even be counted accurately by the system itself (<a href="https://www.ibm.com/topics/smart-contracts">smart contracts</a>), removing any human error or bias.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*v1fIX6TGDhoafG6-" /><figcaption><a href="https://unsplash.com/photos/K0E6E0a0R3A">Charity</a></figcaption></figure><h4>Charity</h4><p>Common issues in charity and donations are inefficiency and corruption. How do we know our donations are going to the right place? Blockchain can make donating a safer and quicker task as each donation becomes publicly recorded. This way, the donator can track his or her money and make sure it ends up in the right hands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*kYTWKJo4VrRurmKc" /><figcaption><a href="https://unsplash.com/photos/NFvdKIhxYlU">Data in Healthcare</a></figcaption></figure><h4>Healthcare</h4><p>Blockchain can help hospitals keep track of patient data and prevent this data from falling into the wrong hands. In the medical industry, data is very private and current systems are at <a href="https://medium.com/visionary-hub/cybersecurity-in-healthcare-b93c92f803c3">risk of being hacked</a> which can lead to potential disaster. This makes the handling of data safer and can even make treatment and diagnosis faster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*GWjGnwYsmHGQLTSq" /><figcaption><a href="https://unsplash.com/photos/I0TDRP0fj6Y">Bitcoin</a></figcaption></figure><h4>Digital Currency</h4><p>Of course one of the biggest names tied to blockchain that we have all heard is Bitcoin, a cryptocurrency. But what is Bitcoin? Let’s dive a bit deeper.</p><h3>What is a Cryptocurrency?</h3><p>In 2008, Satoshi Nakamoto released a white paper titled <em>Bitcoin: A Peer-to-Peer Electronic Cash System </em>with the goal of creating a peer-to-peer network for transactions and exchanges. His goal was to eliminate the need for an intermediary — like a bank — to exist in transactions between two people. As of now, thousands of cryptocurrencies similar to Bitcoin now exist each with unique traits.</p><p>You may be thinking, if it’s a digital currency, why can’t I just make copies of this money? This problem is called “double spending” and is one of the issues that bitcoin set out to solve. Essentially, since a digital currency does not physically exist, using it doesn’t necessarily take it away from that person. Traditional solutions to this problem involved the use for third person intermediaries; however, Satoshi Nakamoto wanted to create a decentralized network leading to the birth of the blockchain and cryptocurrencies.</p><h4>Your next question may be what gives these currencies value?</h4><ul><li><strong>Digital Scarcity:</strong> Idea that there is a finite amount of coins available making certain currencies like Bitcoin similar to “digital gold”</li><li><strong>Supply and Demand: </strong>Some currencies have a fixed amount of coins while others don’t. Demand can increase as a project’s utility becomes more known or valuable.</li><li><strong>Cost of Production: </strong>Certain currencies such as Bitcoin and Ethereum require participants to verify transactions on the blockchain. This is a computationally expensive task requiring electricity and costly equipment.</li><li><strong>Competition:</strong> Currently there are thousands of different crypto projects in existence each unique in their own way. Certain coins offer utilities that are more appealing than others giving them an edge in the market.</li></ul><h3>What are Some Negatives About Blockchain?</h3><p>Up till now I’ve only been pointing out all the positives of this new technology but there are a few disadvantages that are important to recognize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*atgckZR1nbPI0iI2.jpg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.nicehash.com%2Fblog%2Fpost%2Fthe-most-profitable-mining-rig-in-2021&amp;psig=AOvVaw2JR0ZaCZByYscCWkr98R-s&amp;ust=1633934993292000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCLCho6egv_MCFQAAAAAdAAAAABAE">Bitcoin Mining Rig</a></figcaption></figure><ul><li><strong>Slower Process:</strong> As blockchain becomes more widely known and more users are on the network, it makes the entire system slower and more backed up as adding a new block is an expensive process.</li><li><strong>Energy Consumption:</strong> Bitcoin’s energy consumption can be calculated by taking its hashrate (total computational power to mine bitcoin) and estimating energy requirements miners are using to meet that rate. Mining is very computationally expensive and requires large rigs that use a lot of electricity to constantly run.</li><li><strong>Not Available to All:</strong> One of the main issues is that this technology is not accessible to everyone. For example, in El Salvador where Bitcoin was made a national currency, many protested that they did not have internet access and therefore could not use Bitcoin at all.</li><li><strong>Young Technology: </strong>Because blockchain is such a new technology and its implications are unknown, many are apprehensive to accept it as the “future.” While it seems appealing, it is very complex and hard to tell if it will be a successful project.</li></ul><h3>My Thoughts</h3><p>While there are many more disadvantages that we can discuss, I believe that this technology is truly revolutionary. Of course as a 16 year old, my opinion may not be the most developed and is definitely not going to influence anyone, but I am interested in the space and in broadening my knowledge.</p><p>Because it is such a current technology, there are many pioneers in the space who are dedicated to expanding knowledge of this technology. One such person is Naval Ravikant, an investor and thinker who claimed that those who criticize the technology either don’t fully understand the space or are unwilling to accept change.</p><blockquote>Bitcoin is a tool for freeing humanity from oligarchs and tyrants, dressed up as a get-rich-quick scheme.</blockquote><blockquote>— Naval Ravikant</blockquote><p>This quote addresses how though many see bitcoin and blockchain as a scam, it is a revolutionary idea that will have large scale impact over time.</p><h3>TL;DR</h3><ul><li>Blockchain is a public ledger which cannot be tampered with because of its core <strong>decentralized</strong> nature and design</li><li>Blockchain is a distributed (peer to peer) network that removes the need for intermediaries in transactions</li><li>Each block has 3 parts: <strong>data, a hash, and the previous block’s hash</strong></li><li>The hash is a unique identifier for each block and is what keeps each block interconnected on the chain</li><li>Proof of work is used for cryptocurrency mining to validate new transactions on the blockchain</li><li>Blockchain has a variety of applications: <strong>banking/payments, voting, charity, and healthcare </strong>to name a few</li><li>Cryptocurrencies solve the double spending problem using the blockchain to publicly record when exchanges are made</li><li>Some disadvantages of blockchain are the fact that it is <strong>not easily scalable, it consumes a lot of electricity, and is a very young technology making it difficult to trust</strong></li></ul><h3>Sources</h3><ul><li><a href="https://www.investopedia.com/terms/s/satoshi-nakamoto.asp">Who Is Satoshi Nakamoto?</a></li><li><a href="https://www.fool.com/investing/stock-market/market-sectors/financials/cryptocurrency-stocks/value-of-crypto/">What Makes Cryptocurrency Go Up or Down? | The Motley Fool</a></li><li><a href="https://www.investopedia.com/terms/p/proof-work.asp#:~:text=Proof%20of%20work%20(PoW)%20is,transactions%20and%20mining%20new%20tokens.">Proof of Work (PoW)</a></li><li><a href="https://builtin.com/blockchain">Blockchain: What It Is, How It Works, Why It Matters | Built In</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FG3psxs3gyf8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DG3psxs3gyf8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FG3psxs3gyf8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f66bc60ea049dc8173cc458c351ae7db/href">https://medium.com/media/f66bc60ea049dc8173cc458c351ae7db/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FNUBtK4HUcO4&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DNUBtK4HUcO4&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FNUBtK4HUcO4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2c7d5e8ca3ec09e3b367cbc3f51587a/href">https://medium.com/media/b2c7d5e8ca3ec09e3b367cbc3f51587a/href</a></iframe><p><em>Hi my name is Fazal. I am a 16 year old based in the Bay Area of California. Connect with me on </em><a href="https://www.linkedin.com/in/fazal-mittu-b0b3491bb/"><em>Linkedin</em></a><em> and check out my </em><a href="https://github.com/fazalmittu"><em>Github</em></a><em> to see what other projects I am working on! Subscribe to my </em><a href="https://landing.mailerlite.com/webforms/landing/x2h3u1"><em>Newsletter</em></a><em> for monthly updates on what I am working on. Check out the </em><a href="https://sfhsmlclub.medium.com/"><em>Machine Learning Club</em></a><em> I founded and what projects we have completed so far. If you would like to schedule a meeting, use my </em><a href="https://calendly.com/fazalmittu/30min"><em>Calendly</em></a><em>. Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a61847ecbf7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/visionary-hub/a-guide-to-blockchain-4a61847ecbf7">A Guide to Blockchain ⛓</a> was originally published in <a href="https://medium.com/visionary-hub">Visionary Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where are Self-Driving Cars??]]></title>
            <link>https://medium.com/visionary-hub/where-are-self-driving-cars-2af9b74de418?source=rss-5f504abd96ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/2af9b74de418</guid>
            <category><![CDATA[autonomous-cars]]></category>
            <category><![CDATA[tesla]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Fazal Mittu]]></dc:creator>
            <pubDate>Sat, 25 Sep 2021 02:10:36 GMT</pubDate>
            <atom:updated>2021-09-25T02:10:36.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vumuL7RsadckND_3.jpeg" /><figcaption><a href="https://unsplash.com/photos/4xM5cytsdMo">Inside of a Tesla</a></figcaption></figure><blockquote>“10 million self-driving cars will be on the road by 2020” — Business Insider 2016</blockquote><p>Above is one of many similar quotes and headlines predicting self driving cars would become a norm everywhere by 2020. Now we’re in 2021 and autonomous vehicles (AV’s) still seem like just a distant dream. But why? Advancements in AI seemed to be the lone missing piece of the puzzle; however, there are still many more questions to answer and problems to address when it comes to self-driving cars.</p><h3>Levels of Autonomy</h3><p>The development of self-driving cars is categorized into 6 different levels that each determine the capability and true “self-driving” nature of a vehicle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*54Tg4UJWxeTvJqFy" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fboingboing.net%2F2017%2F03%2F03%2Fthe-six-official-levels-of-au.html&amp;psig=AOvVaw1MZDjy882yWKvuYL0A9BHq&amp;ust=1632078060340000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCMCboN-aifMCFQAAAAAdAAAAABAD">Levels of Autonomy</a></figcaption></figure><h4>Level 0: No Automation</h4><p>In this case, the driver is completely in charge of the vehicle and no driver assist systems are present.</p><h4>Level 1: Driver Assistance</h4><p>At level 1, the car has some systems that allow the driver to delegate single tasks like steering or acceleration to the car.</p><h4>Level 2: Partial Automation</h4><p>At level 2, autonomous systems in the car such as automated braking or steering can work in parallel, but the driver must still be attentive and in control.</p><h4>Level 3: Conditional Automation</h4><p>At level 3, a vehicle can navigate itself through select routes in specified conditions. The human driver is still on standby and needs to be ready to take over control at any time.</p><h4>Level 4: High Automation</h4><p>At level 4, the car can fully drive itself in most conditions with a driver still present in order to take control if needed.</p><h4>Level 5: Full Automation</h4><p>At level 5, the car is independent and does not need a driver to be present in any condition. This is the ultimate goal for all self-driving cars.</p><p>Now that we’ve established these 6 categories, where do cars today lie? Most cars that we see on the road today are level 1 on this scale and utilize simple driver assist features such as automated braking. Level 2 cars are much more advanced and have features such as cruise control and parking line detection. <strong>Tesla Autopilot is an example of level 2 autonomy. </strong>Though many believe Tesla Autopilot is very advanced and leading the development of AV’s, these cars are not at the forefront of this technology. Companies like Waymo and General Motors Cruise are examples of level 4 autonomy and are currently leading AV innovation. They are the closest so far to reaching the distant goal of Level 5 autonomy.</p><p>But why is level 5 so distant? Let’s look at some of the road-blocks that prevent AV’s from reaching their full potential.</p><h3>Lack of Data</h3><p>Like any machine learning or AI application, data plays a huge role in self-driving cars and in developing their autonomous capabilities. Machine learning models learn through experience and access to quality data. For a car, that means hours of footage of human driven vehicles showing the computer proper driving technique. But how do we train a car to avoid a collision? How do we teach it to get out of the way of an obstacle? These instances don’t happen very often and data for instances like this is even rarer. The car cannot be expected to act appropriately when it is not given sufficient data to learn.</p><p>To eliminate this issue, companies like Waymo use <strong>simulations</strong> to train their cars, and even create scenarios themselves to give cars more experience in otherwise rarer cases. However, even with this extra data, it is unclear whether these cars will make the right decision in the real world within a split second. This leads us into our next point: <strong>who is at risk</strong> if these cars make a mistake?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d9qlrspwBW2N_DaY.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fblog.waymo.com%2F2020%2F04%2Foff-road-but-not-offline--simulation27.html&amp;psig=AOvVaw3qS1KFms0Y1v_dq-wHRW5Q&amp;ust=1632095697427000&amp;source=images&amp;cd=vfe&amp;ved=0CAsQjRxqFwoTCPD6krjcifMCFQAAAAAdAAAAABAD">Waymo Simulation</a></figcaption></figure><h3>Safety Concerns</h3><p>The answer to the question above is humans of course! The passengers are at risk if the car can’t avoid an obstacle in the road, and the bicyclist is in danger if the car cannot detect them. One of the many questions surrounding AV’s is are they safer than human controlled vehicles? It is true that because self-driving cars can’t text while driving, drive drunk, or get tired, they will drastically improve vehicle safety. However, it is important to recognize that amongst all the positives, there are still some key points of concern; the main one being that computers are far different from people.</p><p>As humans, we have the ability to look at any new scenario and recognize what course of action to take. A computer however, if not trained to recognize a scenario, may not make the right decision. This is an issue because there is an infinite number of special cases that these cars must be able to recognize and they cannot always be trained for each one. For example, if a car has to react to a tree falling, it may not even recognize it and cannot logically reason to stop. A human will hear and see the tree falling and be able to stop to avoid collision.</p><p>There are billions of potential cases such as the one above and engineers have to make sure the car is ready for them.</p><h3>Ethics in Self-Driving Cars</h3><p>Besides just safety however, there are also ethical concerns when it comes to self-driving cars.</p><p>Let’s start with an example: what if your car, in a split second, has to decide between crashing into a motorcycle or an SUV. When a human has to instantly react to a scenario such as the one above on the road, their decision is not a calculated one; it is <strong>instinctive</strong>. However, a computer in that split second has the capability of scanning the environment and making a <strong>calculated decision</strong>. So that begs the question: which of the 2 evils does the car choose to commit? To make it even more unclear, it is a human and the creators of the software who must program the computer’s decision.</p><p>Scenarios like these are what make AV’s controversial, potentially leading to lawsuits or long scrutinous investigations.</p><h3>TL;DR</h3><ul><li>AV’s are still far from becoming mainstream.</li><li>Waymo and GM Cruise are the main leaders in AV development; They are developing Level 4 cars compared to Tesla’s Level 2 cars.</li><li>Lack of data is an obstacle for self-driving cars because the cars need to be trained to handle as many scenarios as possible. Data for these situations is scarce and hard to obtain.</li><li>It is still unclear whether self-driving cars will be safer than human controlled vehicles.</li><li>Ethical concerns are a big reason many are hesitant to accept AV’s. When a human is put in a position to take action in a split second, it is classified as an <strong>instinct</strong>; however, when a computer is put in that same position, it can calculate faster than the human and make a <strong>decision</strong>.</li></ul><p><em>Hi my name is Fazal. I am a 16 year old based in the Bay Area of California. Connect with me on </em><a href="https://www.linkedin.com/in/fazal-mittu-b0b3491bb/"><em>Linkedin</em></a><em> and check out my </em><a href="https://github.com/fazalmittu"><em>Github</em></a><em> to see what other projects I am working on! Check out the </em><a href="https://sfhsmlclub.medium.com/"><em>Machine Learning Club</em></a><em> I founded and what projects we have completed so far. If you would like to schedule a meeting, use my </em><a href="https://calendly.com/fazalmittu/30min"><em>Calendly</em></a><em>. Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2af9b74de418" width="1" height="1" alt=""><hr><p><a href="https://medium.com/visionary-hub/where-are-self-driving-cars-2af9b74de418">Where are Self-Driving Cars??</a> was originally published in <a href="https://medium.com/visionary-hub">Visionary Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Smart Sprinkler]]></title>
            <link>https://medium.com/visionary-hub/smart-sprinkler-adab0a1fbfb6?source=rss-5f504abd96ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/adab0a1fbfb6</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[lawn-care]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Fazal Mittu]]></dc:creator>
            <pubDate>Mon, 26 Apr 2021 03:44:12 GMT</pubDate>
            <atom:updated>2023-02-24T06:28:07.332Z</atom:updated>
            <content:encoded><![CDATA[<h3>Smart Sprinkler — More Accurate Lawn Watering Using an Object Detection Model Paired with an Arduino Based Sprinkler System</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThOAZOLN2IIiyJU370dvpQ.jpeg" /><figcaption>Source: Dvaires on Flickr</figcaption></figure><h3>The Problem</h3><p>Imagine you are strolling through your neighborhood past beautiful green lawns. You step in between the puddles of water collecting near your feet. On your left, a large lawn is being showered in water from a dozen sprinklers in the ground. Despite the miniature water park soaking up the grass, it is still covered with small patches. Many of us don’t see a problem with this, and will happily walk over these puddles and move on with our day. However, the issue is that even though so much water is being used, the lawn is still unhealthy and unable to thrive. This problem is more severe than you may think. In America, 30–60% of urban fresh water is used to water lawns and the sad fact, is that about 50% of this water is wasted due to inefficient and inaccurate watering.</p><p><strong>Lawns are wasteful.</strong> They are heavily resource dependent on commodities like fertilizers, composts, and most importantly, water. This article will list a detailed version of my developed solution as well as the steps that I took to plan, prototype, and deploy it.</p><h3><strong>The Goal</strong></h3><p>The engineering goal for this experiment was to develop a 3-part system including an image segmentation model, a motor value script, and an Arduino controlled sprinkler with the intent of accurately watering patches in a grass lawn, saving significant amounts of water and time.</p><h3>First Thoughts</h3><p>At the beginning of this project, I lacked the experience with computer vision, and also any formal plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*JzY2CFlWCs4-V0Ar.jpg" /><figcaption><a href="https://www.gardenseeker.com/lawn-care/pests-diseases/dry-patch/">Dry Patch</a></figcaption></figure><p>At first glance, there is a noticeable color difference between the lighter brown patches of grass and the green of the healthy grass. My first approach to this project was to look at the RGB values of different areas of the image. If I could determine areas that are “less green” and find a way to threshold it, I could pinpoint the patches. However, it wasn’t as simple as anticipated. The main issue was the numerous external factors that could affect my results. For example, lighting can change the RGB value of a patch in an image. With so many extraneous factors, it would lack the consistency of a practical system.</p><p>I definitely needed a better solution.</p><h3>Image Segmentation</h3><p>The new solution came in the form of a concept called image segmentation. <strong>Image Segmentation</strong> is a computer vision process that divides images into “segments” based on the similarity of pixels. It is mainly used to detect objects within images (object detection) and is used in autonomous vehicles, medical image processing, and satellite imaging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JRTMF60BcDDmFEGU.jpeg" /><figcaption><a href="https://medium.com/nanonets/how-to-do-image-segmentation-using-deep-learning-c673cc5862ef">Image Segmentation</a></figcaption></figure><p>Using image segmentation, I could detect the patches in the lawn. I began to research creating image segmentation models using Tensorflow.</p><p>During my research, I found a wonderful library called<a href="https://imageai.readthedocs.io/en/latest/"> ImageAI</a> written by<a href="https://github.com/OlafenwaMoses"> Olafenwa Moses</a>. ImageAI gives users the option for custom object detection: the ability to use a custom, user created dataset. ImageAI would allow me to assemble a curated dataset, best suited for my model.</p><h3>First Dataset/Test</h3><p>Data enables machine learning and without accurate, meaningful, and plentiful data, it isn’t possible to effectively train practical models to make predictions about the world around us. If we wish to teach a student well, we must provide them the right resources to learn efficiently.</p><p>Many websites and applications contain free to use, public datasets that engineers can use for their own projects. However, there were no existing datasets for this project, meaning I would have to make my own. As it would turn out, building the dataset proved to be a big challenge over the course of this project.</p><p>An image segmentation dataset has two parts to it: images and annotations. There are many ways to annotate images, or mark where the object is located in the image. I used the Pascal VOC format which saves the annotations in .xml files. Essentially, if my dataset contained 50 images, I would have to annotate each individual image to create 50 .xml files annotating their corresponding images.</p><p>Initially, I had many questions about the dataset: how many images I needed, how do I annotate an image, how do I use it in code, how do I know if an image is good, and so on. Thanks to Olafenwa Moses, who luckily wrote an informative<a href="https://medium.com/deepquestai/object-detection-training-preparing-your-custom-dataset-6248679f0d1d"> article</a> detailing how to create a custom dataset and use it with his library ImageAI.</p><p>The first step was acquiring images, which proved to be significantly more difficult than anticipated. There weren’t many high quality images that I could find online. I googled “patchy grass” and manually downloaded<em> just 65 images</em> for my first dataset. To put this in perspective, most image datasets contain thousands of images to train on.</p><p>After collecting the images, I annotated them using a software called Label IMG. I identified the directory to get images from, and the directory to save the annotations in. Then, I annotated each image by boxing any patches. Below is a screenshot of the Label IMG software I used to annotate the images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qc_fhbkChWW-6RPtatW6AQ.png" /><figcaption>Label IMG Software</figcaption></figure><p>I finally had a complete dataset of annotations and images and was ready to train my model. I faced many difficulties with my dataset and downloaded libraries and after troubleshooting, I trained my first model over 15 epochs with a batch size of 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7DVSy3AXeUh7fSdy4ngcQg.png" /><figcaption>Dataset 1 Results</figcaption></figure><p>After testing the model on an image of my front yard, this was the result. It had taken me so long to get a clean run without an error that I was ecstatic to even get a box to show up. It hardly crossed my mind that this result was horrible and useless for my overall system. The model vaguely marks the general area of the bad grass. However, it’s very inaccurate and practically useless.</p><h3><strong>Datasets 2–4/Further Testing</strong></h3><p>After evaluating my results, it was obvious that I lacked enough images to properly develop my model. I decided that I needed a much larger dataset, and manually downloading my images was inefficient.</p><p>After some research I discovered <strong>web scrapers</strong>. A web scraper is a tool that can extract data and content from websites, and download those files locally to your computer. This was just what I needed, and after following a short tutorial, I had a small web scraper downloading images with the keywords “patchy grass”, “bad grass”, and “bad lawn”. Using this web scraper, I accumulated a folder of 180 images, my second dataset.</p><p>After removing any unusable images, I had a third dataset of 160 images. After training the model with the third dataset, the results remained inconsistent and inaccurate. Again, I suspected the main issue was a lack of images in the dataset.</p><p>After reaching out for some help and doing some research, I discovered <strong>image augmentation</strong>, a process through which a dataset can be expanded by modifying existing images. This includes changing the orientation of the image and the RGB values of pixels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*rdYPlFGgxHY--Qhb.png" /><figcaption><a href="https://medium.com/secure-and-private-ai-writing-challenge/data-augmentation-increases-accuracy-of-your-model-but-how-aa1913468722">Data Augmentation Example</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*-HFUIde9Io19JqcOhhc8Xw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*KPWkb3JQNXQu2pnkWtVCGQ.png" /><figcaption>Sample of Augmented vs Real Data</figcaption></figure><p>To us, the images above are all the same, just with minor tweaks; however, to a computer that looks at images as arrays of pixel values, these are all very different images. We can use this idea to our advantage to generate more training data. With a lack of images, image augmentation was perfect for improving my dataset. I used the Keras library to augment an entire directory of images using specific parameters and bounds. My 4th dataset contained 300 images and I was confident that this model would be the one to work. However, a major problem quickly arose.</p><h3>Library Compatibility Problem</h3><p>Most programming projects, especially data science projects, require a number of libraries and dependencies for certain functions and tools. For this project specifically, ImageAI required certain versions of different libraries to be installed including tensorflow-gpu 1.13 and keras 2.4.</p><p>Each version of a library is different and using different versions can affect the interactions between libraries. In my case this was especially true because only certain versions of libraries allowed the model to train/work.</p><p>ImageAI had a January update making it incompatible with versions of libraries used in this project. Suddenly, my training time which was usually about 5 minutes per epoch had become 14+ hours for just one epoch. Furthermore, the model was constantly overfitting to the data meaning that it was unable to generalize to the new data.</p><p>Initially, I thought the extended duration of the training time was a result of the larger amount of images in my dataset, but it was apparent that there was a larger problem at hand. I did some research but could not find much. I had tried so many different solutions to fix my problem including how I extracted my dataset, changing my hardware accelerator, and changing batch size. None of these were improving my training time.</p><p>During some more research, I encountered a very recent<a href="https://github.com/OlafenwaMoses/ImageAI/issues/621"> forum post</a> on Github where someone detailed the same issue I was experiencing. Olafenwa Moses, the creator of the library, replied and explained the problem while providing a solution. The solution detailed which versions to use of the three main libraries, Tensorflow, Keras, and ImageAI.</p><h3>Final Dataset/Model</h3><p>After resolving the previous issue, I first tested a dataset of 300 images. Though the results had improved, they lacked consistency. On certain images of different angles of my lawn, my model was unable to find any patches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*NqI2pmW-P_TEqVkmCLn0Uw.png" /><figcaption>Dataset 4 Results</figcaption></figure><p>I decided to augment my data more, eventually ending up with a dataset of 1738 images. To train my model, I had to annotate each image, by identifying the patches in each image manually. Rather than doing it alone, my friends and I annotated every image in less than 2 hours.</p><p>This final dataset had a 1400–338 train/test split. After training the model over 5 epochs, I ran validation and got an impressive result of 0.7204, by far my best.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsLeFZCWyTFZT8k2NFd6YQ.png" /><figcaption>Dataset 5 Results</figcaption></figure><p>In the end, this was my final model’s output and I was satisfied with the results. After training the model, I set out to develop a prototype of my system, which could accurately water the patches in the lawn.</p><h3>Creating the Sprinkler</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*s-MfzkufuoQJ0QJooYQDhQ.png" /><figcaption>System Design</figcaption></figure><p>To control where the water landed, I needed 2-axis rotation which could control the distance and direction the water travelled. I used two NEMA stepper motors of varying power and torque. The bottom motor was a NEMA-23 used to control the <strong>direction the water travelled</strong>. The top motor was a NEMA 14 and turned a rod on which the sprinkler was placed inside a PVC pipe to control the <strong>distance the water travelled</strong>. To control these motors, I used an Arduino, two A4988 Motor Controllers, and two 12V supply power adapters for power.</p><p>If I could figure out how far the water travelled and what angle it faced at a certain number of steps, I could find the conversion rates for steps/angle and steps/distance. Before I could use these conversion rates however, I required a script that could determine the actual distance to a patch and the angle needed to water it.</p><p>I calculated the angle necessary to turn from where my sprinkler was initially facing, to the center of the patch, and determined the rough amount of pixels/feet in my image to find the rough distance to the center of the patch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*rkfRXKbJwvq--ouwGLm0hw.png" /><figcaption>Output of motor values script</figcaption></figure><p>The image above shows the results of the motor values script, indicating that the sprinkler must turn <strong>42 degrees</strong> and the distance to the patch is approximately <strong>12.76 feet, or about 12 feet 9 inches</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*AnPoUcIzaWBZfwjvBZbMRg.png" /><figcaption>Here we can see the angle to the patch is 42 degrees as the script determined.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*nwTapJzO5hkKWOBlm5abdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*gmK9l1PaJb1KMdGc-fXfAQ.png" /><figcaption>The measuring tape is 10 ft. long; From the center of the patch to the sprinkler is roughly 12 ft. 9 inches just as the script predicted.</figcaption></figure><p>I had done some tests to determine the conversion rates for steps/angle and steps/feet which allowed me to write an Arduino script to face the patch using the metrics that my motor values script outputted.</p><h3>Ready for Final Test</h3><p>Unfortunately, I was unable to test the whole system in the end.</p><p>Before the final test, I had tested the actual build out to see if it was able to support the sprinkler and turn it. In doing so, it turned out that I had, besides taking precautions, gotten water in my motors and fried them. The motors I had used were fairly expensive, so it wasn’t practical to buy new ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wHIcvMuPgEyauYyIDe73BQ.png" /></figure><h3>Code Analysis/Walkthrough</h3><ul><li><a href="https://github.com/fazalmittu/PatchDetection">fazalmittu/PatchDetection</a></li><li><a href="https://colab.research.google.com/drive/1cgWmZAutFLvGULPMirMPse34xWSKXrDX?usp=sharing">Google Colaboratory</a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d2350fe1b7a0f0174e24f165cd4b822/href">https://medium.com/media/9d2350fe1b7a0f0174e24f165cd4b822/href</a></iframe><p>This code is used to import the model and images (for testing) I had stored in Github to make them easy to extract with Google Colab. The final line is used to import the pretrained YOLO-v3 model that was used to train the model (transfer learning).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8212df8df035d4dd1ae6b7d17f814578/href">https://medium.com/media/8212df8df035d4dd1ae6b7d17f814578/href</a></iframe><p>This code is used to import the specific versions of the libraries needed for the project. The libraries used are tensorflow-gpu, keras, imageai, and numpy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cee9a75f5cb68dbc8573c87ddc5d2f4/href">https://medium.com/media/4cee9a75f5cb68dbc8573c87ddc5d2f4/href</a></iframe><p>This code is used to get the dataset from where it is stored in my google drive. The dataset was too large to be saved in Github so I had to use an alternative source.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cffb9f46bea22e461fa9f5c6549b2492/href">https://medium.com/media/cffb9f46bea22e461fa9f5c6549b2492/href</a></iframe><p>This code is where the model is trained. It details the object to look for (“patch”), the number of epochs (5), the batch size (4), and to use transfer learning.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77eeca9472fd27b67938712923d9e361/href">https://medium.com/media/77eeca9472fd27b67938712923d9e361/href</a></iframe><p>This code is used to run validation on the model. For my final model, I received a score of 72.04%. This score is quite exceptional considering that the objects I am trying to find are patches that have no defined shape, color, or size.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/429932cb0bbdfe69d740eac8eb0b0403/href">https://medium.com/media/429932cb0bbdfe69d740eac8eb0b0403/href</a></iframe><p>This code is where I test the model on a new image to see if it will be able to find a patch. Afterwards, if it finds a patch, it saves its pixel coordinates in an array to be used by the motor value script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57d289d1fbde4404ea338c02a9909962/href">https://medium.com/media/57d289d1fbde4404ea338c02a9909962/href</a></iframe><p>This code is where the motor values script starts. It imports an image that has a measuring tape laid out on the grass. I used this to find the estimated amount of pixels in a foot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5a3pLnhiTHAxV1OcBypNRQ.png" /><figcaption>Pixels/Feet</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d66d1d6d23ada53a2ec9ce4b7e80055/href">https://medium.com/media/9d66d1d6d23ada53a2ec9ce4b7e80055/href</a></iframe><p>This code is used to find the angle to the patch. I drew a triangle from the center of the patch to where the sprinkler was. I then used trig and the coordinates of each of the points to determine the angle to the center of the patch. I also used trig and the pixels/feet rate to find the distance to the center of the patch in feet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4e2919719251976e7b5a631889f3a47/href">https://medium.com/media/a4e2919719251976e7b5a631889f3a47/href</a></iframe><p>This was all the code used to control the two motors. Before any of this, I had to determine the rate of steps/degrees and steps/feet which I did through testing and measurement. After all this, I had a working script that could turn my motors according to the metrics the motor value script provided it.</p><h3>Final Thoughts/What I Learned</h3><p>Even with a very anticlimactic ending, I had a great time over the course of this project. I learned how to capture data, augmentation, building models, inference, control systems, mechanicals, and also how to persevere through daunting obstacles.</p><h3>Acknowledgements</h3><p>Big thanks to <a href="https://medium.com/u/c932ffa87061">Achal Prabhakar</a> for being there for me throughout the project and giving great advice whenever I was confused. He also encouraged me to write about this project. Thanks to <a href="https://medium.com/u/7a29a5c269ec">Rahul Tewari</a> for always being there when I needed help or an extra set of eyes. I’m especially grateful that these two actively responded to me whenever I had questions, and even got on calls with me to walk me through whatever I had trouble understanding.</p><p>Big thanks to Dad for helping me build the sprinkler controller and taking me to Dale’s a total of 7 times (sometimes multiple times in the same day).</p><p>Of course, a big thanks to the boys <a href="https://medium.com/u/b3491693af2d">Raj Dhillon</a>, <a href="https://medium.com/u/288e574e865">Pranav Gopal</a>, <a href="https://medium.com/u/cec9680ac5f0">Michael Puell</a>, and Daniel Ren for helping me annotate the dataset.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adab0a1fbfb6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/visionary-hub/smart-sprinkler-adab0a1fbfb6">Smart Sprinkler</a> was originally published in <a href="https://medium.com/visionary-hub">Visionary Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>