<?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 Akshay Pilankar on Medium]]></title>
        <description><![CDATA[Stories by Akshay Pilankar on Medium]]></description>
        <link>https://medium.com/@pilankar-akshay3?source=rss-5d38dc028d5e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*28TKZ5E_Nfhx-qZyE4b_-g.png</url>
            <title>Stories by Akshay Pilankar on Medium</title>
            <link>https://medium.com/@pilankar-akshay3?source=rss-5d38dc028d5e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:52:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pilankar-akshay3/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[LeetCode 150: Evaluate Reverse Polish Notation with stack data structure]]></title>
            <link>https://pilankar-akshay3.medium.com/leetcode-150-evaluate-reverse-polish-notation-with-stack-data-structure-7ae563712d8a?source=rss-5d38dc028d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ae563712d8a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Akshay Pilankar]]></dc:creator>
            <pubDate>Fri, 02 Jun 2023 04:36:40 GMT</pubDate>
            <atom:updated>2023-06-02T04:37:00.876Z</atom:updated>
            <content:encoded><![CDATA[<p>Question: You are given an array of strings tokens that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation">Reverse Polish Notation</a>.</p><p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p><p><strong>Note</strong> that:</p><ul><li>The valid operators are &#39;+&#39;, &#39;-&#39;, &#39;*&#39;, and &#39;/&#39;.</li><li>Each operand may be an integer or another expression.</li><li>The division between two integers always <strong>truncates toward zero</strong>.</li><li>There will not be any division by zero.</li><li>The input represents a valid arithmetic expression in a reverse Polish notation.</li><li>The answer and all the intermediate calculations can be represented in a <strong>32-bit</strong> integer.</li></ul><p><strong>Example 1:</strong></p><pre>Input: tokens = [&quot;2&quot;,&quot;1&quot;,&quot;+&quot;,&quot;3&quot;,&quot;*&quot;]<br>Output: 9<br>Explanation: ((2 + 1) * 3) = 9</pre><p><strong>Example 2:</strong></p><pre>Input: tokens = [&quot;4&quot;,&quot;13&quot;,&quot;5&quot;,&quot;/&quot;,&quot;+&quot;]<br>Output: 6<br>Explanation: (4 + (13 / 5)) = 6</pre><p><strong>Example 3:</strong></p><pre>Input: tokens = [&quot;10&quot;,&quot;6&quot;,&quot;9&quot;,&quot;3&quot;,&quot;+&quot;,&quot;-11&quot;,&quot;*&quot;,&quot;/&quot;,&quot;*&quot;,&quot;17&quot;,&quot;+&quot;,&quot;5&quot;,&quot;+&quot;]<br>Output: 22<br>Explanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5<br>= ((10 * (6 / (12 * -11))) + 17) + 5<br>= ((10 * (6 / -132)) + 17) + 5<br>= ((10 * 0) + 17) + 5<br>= (0 + 17) + 5<br>= 17 + 5<br>= 22</pre><p><strong>Example 4:</strong></p><pre>Input: tokens = [&quot;3&quot;,&quot;4&quot;,&quot;+&quot;]<br>Output: 7<br>Explanation: 3 + 4<br>= 7</pre><p><strong>What is Reverse Polish Notation:</strong> The operators follow their operands. For example, to add 3 and 4 together, the expression is 3 4 + rather than 3 + 4. The expression 3 − 4 + 5 in conventional notation is 3 4 − 5 + in reverse Polish notation: 4 is first subtracted from 3, then 5 is added to it.</p><p><strong>Why Stack: </strong>The concept of a <em>stack</em>, a last-in/first-out construct, is integral to the left-to-right evaluation of RPN. In example 3 4 -, first the 3 is put onto the stack, then the 4; the 4 is now on top and the 3 below it. The subtraction operator removes the top two items from the stack, performs 3–4, and puts the result of -1 onto the stack.</p><p><strong># Intuition</strong></p><p>Using stack is the best way since we know we have to run operations on previous values</p><p><strong># Approach</strong></p><p>1. We have to iterate through the list once hence O(N) time complexity and we will be using stack data structure only hence O(N) space complexity.</p><p>2. Next add the `if` or `switch` condition on every char.</p><p>3. Check if char is a number and add numbers to the stack. before adding them just convert them into numbers with `Number(tokens[i])`.</p><p>4. If char is an operator then run the operation with the previous 2 values from stack by popping the values out.</p><p>5. When running Divide or Subtract, we have to run `b-a`.</p><p><strong># Complexity</strong></p><p>- Time complexity:</p><p>O(n)</p><p>- Space complexity:</p><p>O(n)</p><p><strong># Code</strong></p><pre>/**<br> * @param {string[]} tokens<br> * @return {number}<br> */<br>var evalRPN = function (tokens) {<br>    let stack = [];<br>    for (let i = 0; i &lt; tokens.length; i++) {<br>        let char = tokens[i];<br><br>        if (char === &#39;+&#39;) {<br>            stack.push(stack.pop() + stack.pop())<br>        }<br>        else if (char === &#39;-&#39;) {<br>            const [a, b] = [stack.pop(), stack.pop()]<br>            stack.push(b - a)<br>        }<br>        else if (char === &#39;*&#39;) {<br>            stack.push(stack.pop() * stack.pop())<br>        }<br>        else if (char === &#39;/&#39;) {<br>            const [a, b] = [stack.pop(), stack.pop()]<br>            stack.push(b / a | 0)<br>        }<br>        else {<br>            stack.push(Number(char))<br>        }<br>    }<br>    <br>    return stack.pop()<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ae563712d8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React.js rendering explained!]]></title>
            <link>https://pilankar-akshay3.medium.com/react-js-rendering-explained-6532acd7f65e?source=rss-5d38dc028d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6532acd7f65e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-render]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Akshay Pilankar]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 15:00:58 GMT</pubDate>
            <atom:updated>2023-01-02T15:00:58.016Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Hello fellas,</strong></p><p><strong>React.js is</strong> a popular JavaScript library for building user interfaces. In this blog, We will learn how React.js rendering works. One of the key features of React is its efficient rendering process, which allows it to update the DOM (Document Object Model) in a fast and efficient manner.</p><p>The rendering process in React begins when a component’s state or props (properties) change. When this happens, React will call the component’s render method, which returns a description of the component’s UI. This description, called the virtual DOM (VDOM), is a lightweight representation of the actual DOM.</p><p>Next, React compares the VDOM to the actual DOM and determines which parts of the UI need to be updated. It does this by calculating the difference between the two, using a process called reconciliation.</p><p>If any changes are detected, React will update the actual DOM with the new VDOM. However, instead of updating the DOM directly, React uses a technique called DOM diffing to minimize the number of actual DOM updates that need to be made. This is done by identifying the minimum number of DOM nodes that need to be added, removed, or modified in order to bring the actual DOM in line with the VDOM.</p><p>One of the main benefits of this rendering process is that it allows React to update the UI in a performant manner, even when the state or props of a component change frequently. This makes it an ideal choice for building high-performance, interactive applications.</p><p>In addition to its efficient rendering process, React also provides a declarative syntax for building UI, which makes it easy for developers to understand and maintain their code. This, combined with its powerful tooling and community support, makes React a popular choice for building modern web applications.</p><p>Another important aspect of the React rendering process is the concept of the component lifecycle. Components in React go through a series of lifecycle methods, which are called at different stages of the component’s lifetime.</p><p>These methods include:</p><ul><li>componentWillMount: called just before the component is mounted to the DOM</li><li>componentDidMount: called immediately after the component is mounted to the DOM</li><li>shouldComponentUpdate: called before the component is re-rendered, allowing the developer to determine whether or not to update the component based on its props or state</li><li>componentWillUpdate: called just before the component is re-rendered</li><li>componentDidUpdate: called immediately after the component is re-rendered</li><li>componentWillUnmount: called just before the component is unmounted from the DOM</li></ul><p>These lifecycle methods provide developers with the ability to perform certain actions at specific points in a component’s lifetime, such as fetching data from an API or updating the component’s state.</p><p>In summary, the rendering process in React is an efficient and powerful way to update the UI of an application. Its declarative syntax and component lifecycle methods make it easy for developers to build and maintain complex UI, making it a popular choice for building modern web applications.</p><p>I hope you found this tutorial on React.js rendering helpful. If you have any questions or comments, feel free to leave them in the comments section below. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6532acd7f65e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Oriented Programming in JavaScript]]></title>
            <link>https://pilankar-akshay3.medium.com/object-oriented-programming-in-javascript-973fac3e2fbd?source=rss-5d38dc028d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/973fac3e2fbd</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Akshay Pilankar]]></dc:creator>
            <pubDate>Sat, 31 Dec 2022 06:14:33 GMT</pubDate>
            <atom:updated>2022-12-31T06:14:33.869Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Hello fellas,</strong></h3><p><strong>Object orientation</strong> is a programming paradigm that is based on the idea of organizing code in terms of objects and their interactions. This allows for a more organized and reusable code structure, as well as a better understanding of how different parts of a program work together.</p><p>So, what exactly is an object in JavaScript? An object is a collection of properties and methods that are used to represent a real-world entity. For example, you could create an object called “car” that has properties like make, model, and year, as well as methods like start and stop.</p><p>One way to create an object in JavaScript is through the use of a constructor function. A constructor function is a special type of function that is used to create and initialize objects. Here’s an example of a constructor function for a car object:</p><pre>function Car(make, model, year) {<br> this.make = make;<br> this.model = model;<br> this.year = year;<br> this.start = function() {<br>  console.log(&quot;The car has started.&quot;);<br> }<br> this.stop = function() {<br>  console.log(&quot;The car has stopped.&quot;);<br> }<br>}</pre><p>To create a new car object using this constructor function, we can use the “new” keyword like this:</p><pre>let myCar = new Car(&quot;Ford&quot;, &quot;Mustang&quot;, 2018);</pre><p>Now, we have a new car object with the properties make, model, and year, as well as the methods start and stop. We can access and modify these properties and methods like this:</p><pre>console.log(myCar.make); // Outputs &quot;Ford&quot;<br>myCar.year = 2020;<br>console.log(myCar.year); // Outputs 2020<br>myCar.start(); // Outputs &quot;The car has started.&quot;</pre><p>Another way to create objects in JavaScript is through the use of object literals. An object literal is a way to create an object by simply listing its properties and values in curly braces. Here’s an example of an object literal for a car:</p><pre>let myCar = {<br> make: &quot;Ford&quot;,<br> model: &quot;Mustang&quot;,<br> year: 2018,<br> start: function() {<br>  console.log(&quot;The car has started.&quot;);<br> },<br> stop: function() {<br>  console.log(&quot;The car has stopped.&quot;);<br> }<br>}</pre><p>We can access and modify the properties and methods of this object in the same way as we did with the constructor function.</p><p>In addition to creating individual objects, we can also create object prototypes. A prototype is a blueprint for creating objects. It contains all of the properties and methods that will be shared by all objects created from it. This allows us to create multiple objects with the same structure and functionality, without having to rewrite the same code over and over again.</p><p>Here’s an example of a prototype for a car object:</p><pre>function Car() {}<br><br>Car.prototype.make = &quot;Ford&quot;;<br>Car.prototype.model = &quot;Mustang&quot;;<br>Car.prototype.year = 2018;<br>Car.prototype.start = function() {<br> console.log(&quot;The car has started.&quot;);<br>}<br>Car.prototype.stop = function() {<br> console.log(&quot;The car has stopped.&quot;);<br>}</pre><p>To create a new car object using this prototype, we can use the “new” keyword like this:</p><pre>let myCar = new Car();</pre><p>We can access and modify the properties and methods of this object in the same way as we did with the constructor function and object literal.</p><p>Object orientation in JavaScript allows us to create organized, reusable code structures that represent real-world entities. It is an important concept to understand if you want to create complex and efficient programs in JavaScript.</p><p>I hope you found this tutorial on object orientation in JavaScript helpful. If you have any questions or comments, feel free to leave them in the comments section below. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=973fac3e2fbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blind 75| Group Anagrams javascript solution (string sorting approach)]]></title>
            <link>https://pilankar-akshay3.medium.com/blind-75-group-anagrams-javascript-solution-string-sorting-approach-79c8483c81dd?source=rss-5d38dc028d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/79c8483c81dd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[group-anagrams]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[anagram]]></category>
            <category><![CDATA[blind75]]></category>
            <dc:creator><![CDATA[Akshay Pilankar]]></dc:creator>
            <pubDate>Wed, 27 Apr 2022 08:58:30 GMT</pubDate>
            <atom:updated>2022-04-28T03:43:20.383Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello fellow developers ✋! In this article, we will cover how to solve <strong>Group Anagrams </strong>with two approaches.</p><p>Question — In this question, we have an array of strings. and we want to return an output where strings are groups by anagrams.</p><pre><strong>Input:</strong> strs = [&quot;eat&quot;,&quot;tea&quot;,&quot;tan&quot;,&quot;ate&quot;,&quot;nat&quot;,&quot;bat&quot;]<br><strong>Output:</strong> [[&quot;bat&quot;],[&quot;nat&quot;,&quot;tan&quot;],[&quot;ate&quot;,&quot;eat&quot;,&quot;tea&quot;]]</pre><p>What is <strong>Anagram? —</strong> a word, phrase, or name formed by rearranging the letters of another. for eg “eat” can be rearranged to create “ate” or “tea”.</p><p>Approach — This can be done by sorting strings right? Yes, we can sort every string for eg 👇</p><pre>let str = &quot;eat&quot;<br>let sortedStr = [...str] <em>//</em><strong><em>string</em></strong><em> to </em><strong><em>array</em></strong><em> [&quot;e&quot;,&quot;a&quot;,&quot;t&quot;]</em><br>                   .sort() <em>//</em><strong><em>sorting</em></strong><em> it to look like [&quot;a&quot;,&quot;e&quot;,&quot;t&quot;]</em><br>                   .join(&quot;&quot;) <em>// will get &quot;</em><strong><em>aet</em></strong><em>&quot; as </em><strong><em>sortedStr</em></strong><em> value</em></pre><p>Now that we have sorted the string of every input string, we need something to store that string so that we can add or retrieve data effectively. Here we can use simple <strong>Object </strong>or<strong> Map </strong>datatype. <strong>Map</strong> datatype comes with predefined <strong>getters</strong> and <strong>setters</strong> which we can leverage easily but for now, we will use <strong>Object</strong> type for simplicity.</p><p>Also, we will use for loop to iterate over the given array of strings</p><pre>function groupAnagrams(strs) {<br>   const map = {}; <em>// Object to </em><strong><em>store</em></strong><em> data for eg. </em><strong><em>{&quot;aet&quot;:[&quot;eat&quot;,&quot;ate&quot;]}</em></strong></pre><pre>    for(let i=0;i&lt;strs.length;i++){<br>      let sortedStr = [...strs[i]].sort().join(&quot;&quot;);</pre><pre><em>// Now that we have </em><strong><em>sorted string</em></strong><em> we can check if the </em><strong><em>string</em></strong><em> is already present in </em><strong><em>map object or not </em></strong><em>in below lines of code</em><strong><em>.</em></strong></pre><pre><strong>      </strong>if(map[sortedStr]){<br>           map[sortedStr] = [...map[sortedStr],strs[i]];<br>       }else{<em><br>           </em>map[sortedStr] = [strs[i]];<br>       }</pre><pre>    }</pre><pre>}</pre><p>Here we are treating <strong>sortedStr </strong>as a key in <strong>map</strong> object and every key corresponds to an array of strings. for eg. <strong><em>{“aet”:[“eat”,”ate”]}</em></strong></p><pre>if(map[sortedStr]){<br>      // if key exists then add current string to the map</pre><pre>      map[sortedStr] = [...map[sortedStr],strs[i]];<br> }else{</pre><pre>     // if key doesn’t exists then create an array and add first entry as string to the map.</pre><pre>     map[sortedStr] = [strs[i]];<br> }</pre><p>Now we are pretty much done with the solution! One last thing we have to do is to return the values we stored in the <strong>map Object</strong> as <strong>key-value</strong> pair to the <strong>array of grouped strings. </strong>We can easily do this with the <strong>Object’s</strong> <strong>values()</strong> function with the <strong>object spread operator</strong>.</p><pre>return [...Object.values(map)]</pre><p>Finally, our code looks like this</p><pre>function groupAnagrams(strs){<br>  const map = {}; <br>  for(let i=0;i&lt;strs.length;i++){<br>      let sortedStr = [...strs[i]].sort().join(&quot;&quot;) <br>                             <br>         if( map[sortedStr]){<br>           map[sortedStr] = [...map[sortedStr],strs[i]]<br>         } else{<br>           map[sortedStr] = [strs[i]]<br>         }                <br>    }<br>    return [...Object.values(map)]<br>}</pre><h4>Now let’s discuss the Elephant in the room! Yes, the complexity of this solution —</h4><p>Since we are sorting every string. let’s consider this as a <strong>nlogn, </strong>where n denotes the average length of the string.</p><p>Also, we are iterating over a given array of strings. let’s consider this as <strong>m.</strong></p><p>So we can consider time complexity as <strong>m*nlogn </strong>and space complexity as <strong>m*n</strong></p><pre> m - length of strs;<br> n - average length of the string<br> Time: O(m * nlog n)<br> Space: O(m * n)</pre><p>Yes, we can do better than this in terms of <strong>time complexity </strong>and I will cover that in the next part of this blog. If you have any questions regarding this or anything I should update in the above solution, feel free to comment or DM me.</p><p>👏 Clap if you like this article!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79c8483c81dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The One where we started using State machines (XState) part 1]]></title>
            <link>https://pilankar-akshay3.medium.com/the-one-where-we-started-using-state-machines-xstate-part-1-5d693f973385?source=rss-5d38dc028d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d693f973385</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[xstate]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[finite-state-machine]]></category>
            <dc:creator><![CDATA[Akshay Pilankar]]></dc:creator>
            <pubDate>Fri, 22 Apr 2022 07:06:35 GMT</pubDate>
            <atom:updated>2022-04-25T13:56:02.432Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>React</strong> applications are built using <strong>components</strong> and their <strong>states</strong>. Let’s think of the state as a representation of the part of an application that changes.</p><p>When the application is small, components <strong>manage</strong> their <strong>state</strong> internally and it works well for applications with few components, but as we scale and our application becomes more complex, the complexity of <strong>managing</strong> states shared across components becomes daunting for code readability, testing, and future enhancements.</p><blockquote><strong><em>“First, solve the problem. Then, write the code.” — John Johnson</em></strong></blockquote><p>Let’s start with an example of an <strong>Authentication service </strong>(<em>yes just Authentication service because in a world full of monolithic applications, we can be a service-driven application</em>) in which we have a few prerequisite functions e.g. (<em>Login, Signup, Forgot password, etc.</em>). Let’s analyze various use-cases and the types of states we will encounter in our application</p><p>signup/login -</p><ol><li>user will enter user details and hit submit</li><li>Call to <em>/{signup or login}</em> API, which will return a success or error.</li><li>In case of success, the user will proceed to the next screen.</li><li>In case of an error, we will show the user an error screen.</li></ol><p>Now that we are clear with the requirements; let’s talk about state management libraries</p><blockquote>Why not Redux?</blockquote><p><strong>React</strong> has many Third-party libraries such as Redux, Flux, and MobX. Here we will consider and compare <strong>Redux</strong> <strong>for</strong> <strong>the above example</strong> as it is famous out of all.</p><ul><li>Redux is an infinite state machine (<em>which means that it can have countless states</em>).</li><li>Redux is essentially a state container where events (<em>called actions in Redux</em>) are sent to a reducer (<em>plain functions that return the next state given the current state</em>) that updates states.</li><li>Redux does <em>not</em> have a built-in way to handle side effects. There are many community options e.g.( <em>redux-thunk, redux-saga, etc.</em>)</li><li>Redux currently has no way to visualize transitions between states, since it does not discern between finite and infinite state.</li><li>Redux encourages the use of a single, “global” atomic store.</li></ul><p>We still use Redux in most of our projects, and I’m quite happy with it. However Redux adds complexity even in a very straightforward project like we are considering in this example where we know we have a finite number of states.</p><blockquote>Finite State Machine way —</blockquote><p>A Finite State Machine is a mathematical model of computation. It’s an abstract concept whereby the machine can have different states, but at a given time fulfills only one of them. Here we will use the XState library for creating, interpreting, and executing finite state machines.</p><p>Now that we know why we choose <strong>XState</strong> and how our state will work in applications we can proceed with development, and the first thing to do is to define application logic. Here we will use the <a href="https://xstate.js.org/viz/?gist=ed095d53038851250f997d98d398a335">XState visualizer</a> to plan it visually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NxTBf6dzNmLrLgxCZMsyKw.png" /><figcaption>Visual representation of application logic in XState visualizer (<a href="https://xstate.js.org/viz/?gist=1e567cff699c55a1ce366eec721b5cd9">https://xstate.js.org/viz/?gist=1e567cff699c55a1ce366eec721b5cd9</a>)</figcaption></figure><p>As you can see in the above image, it’s an abstract representation of finite state machine of our <strong>Auth</strong> application. A finite state machine can be in only one of a finite number of states at any given time and events cause it to change state. Let’s see these states one by one:</p><ol><li>init — application’s initial state to determine if a user is logged in or not.</li><li>auth — auth state will handle all the user authentication-related states that we will cover later in the blog and on successfully login or signup, the state will transit to profile state.</li><li>profile — as the name suggests it will contain all the profile-related states ie. update profile, etc.</li><li>logout — as the name suggests it will clear the user-related objects and the state will transit to auth state</li></ol><blockquote>XState library —</blockquote><pre>npm install xstate <a href="http://twitter.com/xstate/react">@xstate/react</a> --save<br># or:<br>yarn add xstate <a href="http://twitter.com/xstate/react">@xstate/react</a> --save</pre><p>And this is the basic XState code snippet for our Auth application. Don’t worry we will cover everything in detail 🐵</p><pre>//machine.ts</pre><pre>import { createMachine } from &quot;xstate&quot;;</pre><pre>const appMachine = Machine({<br>    id: &#39;app&#39;, // Name<br>    initial: &#39;init&#39;, // Initial state<br>    context: {<br>      user:{}, // Store like redux store<br>    },<br>    states: {<br>      // Business logic<br>    }<br>  });</pre><p>State machines are defined using the createMachine() function which can be imported from XState library. It takes above machine config as a first argument and Implementations for <a href="https://xstate.js.org/docs/guides/actions.html">actions</a>, <a href="https://xstate.js.org/docs/guides/activities.html">activities</a>, <a href="https://xstate.js.org/docs/guides/delays.html">delays</a>, <a href="https://xstate.js.org/docs/guides/guards.html">guards</a>, and <a href="https://xstate.js.org/docs/guides/communication.html">services</a> can be referenced in the machine config as a string, and then specified as an object in the 2nd argument.</p><p>Machine config has the following properties:</p><ol><li><strong>Id</strong> — unique identifier of the machine</li><li><strong>initial</strong> — initial state of the machine</li><li><strong>context — </strong>context is like redux data store(but less complicated 😆)</li><li><strong>states—</strong>list of<strong> </strong>possible states and their underlying logic.</li></ol><h3>Now let’s write(***understand) some code</h3><p>Now that we know the basics of Xstate machine config. Let’s Create machine.ts file in the root folder and add the above code. now that we have basic setup ready we can start working on the application’s individual state which we will add inside states object:</p><p>A State definitions is an abstract representation of a system (such as an application) at a specific point in time. As an application is interacted with, events cause it to change state. A finite state machine can be in only one of a finite number of states at any given time. The current state of a machine is represented by a State instance</p><ol><li>init state —</li></ol><p>this state will be used to check if the user is already logged in or not by determining the user’s authentication token in cookies. if we find an authentication token that is not expired then we can transit the user to the profile state as a logged user and if not then we will transit the user to auth state.</p><blockquote><strong>Event</strong> is what causes a state machine to transition from its current state to its next state. in case of <strong>init</strong>, depending on the auth token availability in the cookie we will fire an event which will help trasit machine from init to <strong>auth</strong> or <strong>profile</strong> state conditionally.</blockquote><pre>// inside states object in machine.ts</pre><pre>   &quot;init&quot;:{<br>      &quot;on&quot;:[<br>         {<br>            &quot;cond&quot;:&quot;isLoggedIn&quot;,<br>            &quot;target&quot;:&quot;profile&quot;<br>         },<br>         {<br>            &quot;cond&quot;:&quot;!isLoggedIn&quot;,<br>            &quot;target&quot;:&quot;auth&quot;<br>         }<br>      ]<br>   }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*y4NiAQoxxE6N7YPNVfA3tg.png" /><figcaption>Init state visualizer</figcaption></figure><p>As we can see in the above snippet, We have an attribute that will indicate the initial state of the application; and in our case, it will be <strong>Init </strong>state as we want to redirect the user to the appropriate page depending on his auth status(Yes we will write rendering logic based on user cookie detection but we will cover it later in the blog). here from <strong>Init </strong>it can only trasit to <strong>auth</strong> or <strong>Profile</strong> state depending on user’s auth token present in cookie.</p><p>2.auth state —</p><p>When the user’s auth token is not present in the cookie, machine will transit from initstate to authstate. this will render the login page by default and this page will have login form and buttons for signup and forgot password. The below image is visual representation of auth state. Inside <strong>auth</strong> state we have few child state which will handle the auth operations like login, signup and forgot password. by-default login state will be active as we have mentioned initial:&quot;login&quot; in the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*G1bP9QFjrdXR-Ncc6ZWJZQ.png" /><figcaption><a href="https://xstate.js.org/viz/?gist=1e567cff699c55a1ce366eec721b5cd9">https://xstate.js.org/viz/?gist=1e567cff699c55a1ce366eec721b5cd9</a></figcaption></figure><pre>// inside states object in machine.ts below init object</pre><pre>   &quot;auth&quot;:{<br>      &quot;initial&quot;:&quot;login&quot;,<br>      &quot;states&quot;:{<br>         &quot;login&quot;:{<br>            &quot;on&quot;:{<br>               &quot;ENTER_EMAIL&quot;:{<br>                  &quot;actions&quot;:&quot;cacheEmail&quot;<br>               },<br>               &quot;ENTER_PASSWORD&quot;:{<br>                  &quot;actions&quot;:&quot;cachePassword&quot;<br>               },<br>               &quot;SUBMIT&quot;:[<br>                  {<br>                     &quot;cond&quot;:&quot;isLoggedIn&quot;,<br>                     &quot;target&quot;:&quot;#app.profile&quot;<br>                  }<br>               ],<br>               &quot;SIGNUP&quot;:&quot;signup&quot;<br>            }<br>         },<br>         &quot;signup&quot;:{<br>            &quot;on&quot;:{<br>               &quot;ENTER_FULL_NAME&quot;:{<br>                  &quot;actions&quot;:&quot;cacheFullName&quot;<br>               },<br>               &quot;ENTER_EMAIL&quot;:{<br>                  &quot;actions&quot;:&quot;cacheEmail&quot;<br>               },<br>               &quot;ENTER_PASSWORD&quot;:{<br>                  &quot;actions&quot;:&quot;cachePassword&quot;<br>               },<br>               &quot;REENTER_PASSWORD&quot;:{<br>                  &quot;actions&quot;:&quot;cacheReenterPassword&quot;<br>               },<br>               &quot;SUBMIT&quot;:[<br>                  {<br>                     &quot;cond&quot;:&quot;isLoggedIn&quot;,<br>                     &quot;target&quot;:&quot;#app.profile&quot;<br>                  }<br>               ],<br>               &quot;LOGIN&quot;:&quot;login&quot;<br>            }<br>         }<br>      }<br>   }</pre><p>Copy the above code inside below init object inside machine.ts. Now let’s understand auth’s child states one by one.</p><p>Login — As name suggests this will handle login related events (Don’t worry, we will cover how to handle events in Front-end integration 🤓).</p><p>ENTER_EMAIL event will handle user’s email input from login page form. here we can run various validation on the input if required</p><p>ENTER_PASSWORD event will handle user’s password input from login page form.</p><p>SIGNUP event will trasit machine from login state to signup state and signup page will render.</p><p>SUBMIT event will handle login form submission. this will make login API call to the server and upon response it will update isLoggedIn object state in context. in case of success machine will trasit from <strong>auth</strong> to <strong>profile </strong>state and in case of failure we can display error on form.</p><p>Signup — As name suggests this will handle Signup related events. Just like login state events, here ENTER_FULL_NAME will handle User name input, ENTER_EMAIL will handle email input and LOGIN event will trasit machine form signup to login state and will also render login page.</p><p>ENTER_PASSWORD ,REENTER_PASSWORD will handle password input and on top of that we will write logic to check if both the strings are same or not.</p><p>Just like <strong>Login </strong>state SUBMIT event, this SUBMIT event will handle signup logic.</p><p>🥳 Finally now we know basics of <strong>XState </strong>and how a basic authentication state machine will work. But <strong>hold on</strong> you must be thinking 🤔 where is the code to the front-end code!!!!!!!!!! Excuse me i wanna copy paste everything…☝️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mI8hpUKx01CyQmevYja4Mg.png" /><figcaption>WE DON’T DO THAT HERE IN UpGrad!!!!</figcaption></figure><p>Here in UpGrad we make sure while you are learning from UpGrad, you are understanding everything so that next time even though you’ll copy paste the code(let’s accept we all do that 🙈) but you’ll have all the understanding that you need to write XState code.</p><p>Although people say <strong>God Speed, </strong>I have divided this tutorial into <strong>TWO</strong> parts. In 2nd part I will cover <strong>React</strong> integration and various concepts like <strong>Interpreter</strong>, <strong>useService, action, invoke, </strong>etc. so stay tuned because we’ll be back in no time!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d693f973385" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup a Ethereum POA (private-proof-of-authority-ethereum-network) network on Amazon AWS…]]></title>
            <link>https://pilankar-akshay3.medium.com/how-to-setup-a-ethereum-poa-private-proof-of-authority-ethereum-network-network-on-amazon-aws-21420e9cf7b9?source=rss-5d38dc028d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/21420e9cf7b9</guid>
            <category><![CDATA[geth]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ethereum-blockchain]]></category>
            <category><![CDATA[certbot]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Akshay Pilankar]]></dc:creator>
            <pubDate>Thu, 10 Oct 2019 03:47:28 GMT</pubDate>
            <atom:updated>2021-05-28T06:19:41.588Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to setup a Ethereum POA (private-proof-of-authority-ethereum-network) network on Amazon AWS (2nd Part)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQmVaD6IEUuy8dPcEJNNKA.png" /></figure><p>Hello, as promised I am back with 2nd part of this tutorial where I will cover Url wrapper &amp; SSL support with NGINX and Certbot.</p><blockquote><a href="https://medium.com/echttech/how-to-setup-a-ethereum-poa-private-proof-of-authority-ethereum-network-network-on-amazon-aws-5fdf56d2ad93">if you&#39;re new here then check out last part of this tutorial by clicking here!</a></blockquote><p>Let&#39;s begin with revising what we have done till now in the last tutorial</p><ol><li>EC2 instance (server) setup.</li><li>Geth installation and private network setup.</li><li>Nginx and Certbot installation.</li></ol><p>In case you have missed, here are the commands to install and setup Nginx and Certbot</p><pre>sudo apt-get update<br>sudo apt install nginx<br>sudo ufw enable<br>sudo ufw allow &#39;Nginx Full&#39;<br>sudo ufw allow &#39;OpenSSH&#39;<br>sudo add-apt-repository ppa:certbot/certbot<br>sudo apt install python-certbot-nginx<br>sudo ufw status</pre><p>now check the status</p><pre>OutputStatus: activeTo                         Action      From<br>--                         ------      ----<br>OpenSSH                    ALLOW       Anywhere                  <br>Nginx Full                 ALLOW       Anywhere                  <br>OpenSSH (v6)               ALLOW       Anywhere (v6)             <br>Nginx Full (v6)            ALLOW       Anywhere (v6)</pre><p>then check for Nginx service — <strong>systemctl status Nginx</strong></p><pre>Output● nginx.service - A high performance web server and a reverse proxy server<br>   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)<br>   Active: active (running) since Fri 2018-04-20 16:08:19 UTC; 3 days ago<br>     Docs: man:nginx(8)<br> Main PID: 2369 (nginx)<br>    Tasks: 2 (limit: 1153)<br>   CGroup: /system.slice/nginx.service<br>           ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;<br>           └─2380 nginx: worker process</pre><p>Now we have everything installed let’s concentrate on how to do port forwarding with <strong>NGINX</strong>. open <strong>default file</strong> using nano or your favorite editor.</p><pre>sudo nano /etc/nginx/sites-available/default</pre><p>As per the previous tutorial we are using <strong>rpcport</strong> 8501 and <strong>wsport</strong> 8601 in private network. so here will forward port 80 (server IP) to 8501 and 8601. add the following command Inside the default file. copy-paste it to the last line of the file.</p><pre>server {<br>    server_name  blockchain.echttech.co.in;  #your domain name        #remove any http://<br><br>    location /ws {<br>        proxy_pass http://localhost:8601;<br>        proxy_http_version  1.1;<br>        proxy_set_header    Upgrade $http_upgrade;<br>        proxy_set_header    Connection &quot;upgrade&quot;;<br>        proxy_set_header    Host $http_host;<br>        proxy_set_header    X-Real-IP $remote_addr;<br>    }<br><br>    location / {   <br>        proxy_set_header   X-Forwarded-For $remote_addr;<br>        proxy_set_header   Host $http_host;        <br>        proxy_pass http://localhost:8501;<br>    }<br>}</pre><p>Save and close the file when you are finished. Now restart Nginx to enable your changes.</p><pre>sudo systemctl restart nginx</pre><p>Nginx should now be serving your domain name. You can test this by opening new CMD in local machine and connecting to ethereum geth console with geth attach <strong>http://</strong>blockchain.echttech.co.in, where you should see geth console for private network.</p><p>To check WS provider use geth attach <strong>ws://</strong>blockchain.echttech.co.in<strong>/ws</strong></p><blockquote>Note — you have to open port 80 and 443 in order for this to work from AWS console.</blockquote><p>The next step is to<strong> Obtaining an SSL Certificate</strong>. The Nginx plugin will take care of reconfiguring Nginx. To use this plugin, type the following:</p><pre>sudo certbot-nginx -d blockchain.echttech.co.in</pre><p>If this is your first time running certbot, you will be prompted to enter an email address and agree to the terms of service. After doing so, certbot will communicate with the Let’s Encrypt server, then run a challenge to verify that you control the domain you’re requesting a certificate for. If that’s successful, certbot will ask how you’d like to configure your HTTPS settings.</p><pre>Output</pre><pre>Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.<br>-------------------------------------------------------------------------------<br>1: No redirect - Make no further changes to the webserver configuration.<br>2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for<br>new sites, or if you&#39;re confident your site works on HTTPS. You can undo this<br>change by editing your web server&#39;s configuration.<br>-------------------------------------------------------------------------------<br>Select the appropriate number [1-2] then [enter] (press &#39;c&#39; to cancel): </pre><p>Select your choice then hit enter. this will reload the Nginx. Again you can test this by opening new CMD in local machine and connecting to ethereum geth console with following commands</p><blockquote>To check HTTPS provider geth attach <a href="https://blockchain.echttech.co.in/"><strong>https</strong></a><a href="https://blockchain.echttech.co.in/">://blockchain.echttech.co.in</a></blockquote><blockquote>To check WS provider use geth attach <strong>wss</strong>://blockchain.echttech.co.in/ws</blockquote><p>Let’s Encrypt’s certificates are only valid for ninety days. use this command to renew certificates.</p><pre>sudo certbot renew <strong>--</strong>pre<strong>-</strong>hook &quot;systemctl nginx stop&quot; <strong>--</strong>post<strong>-</strong>hook &quot;systemctl nginx start&quot;</pre><p>Good work!!!!</p><p>So far we have successfully set up Nginx and Certbot.</p><p>In next part will setup blockchain explorer. Stay tuned!</p><p>smash like button and share!!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21420e9cf7b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup a Ethereum POA (private-proof-of-authority-ethereum-network) network on Amazon AWS…]]></title>
            <link>https://pilankar-akshay3.medium.com/how-to-setup-a-ethereum-poa-private-proof-of-authority-ethereum-network-network-on-amazon-aws-5fdf56d2ad93?source=rss-5d38dc028d5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fdf56d2ad93</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[poa]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[geth]]></category>
            <category><![CDATA[ethereum-poa]]></category>
            <dc:creator><![CDATA[Akshay Pilankar]]></dc:creator>
            <pubDate>Fri, 04 Oct 2019 05:42:07 GMT</pubDate>
            <atom:updated>2019-10-04T05:42:32.776Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to setup a Ethereum POA (private-proof-of-authority-ethereum-network) network on Amazon AWS (1st Part)</h3><p>Hello,</p><p>I came across a lot of online tutorials and blogs to setup private proof of authority ethereum network on aws but none of them showed the bells and whistles to make to more like ethereum mainnet standards with WebSocket setup, network monitor, URL wrapped, SSL support, etc. So in this blog will cover all the necessary steps to set up a production-ready POA setup on ethereum.</p><p>PS: this is my first blog… I believe I will be good at this eventually. :)</p><p>The tutorial is divided into sections mentioned below —</p><ol><li>AWS EC2 instance setup and private network setup.</li><li>Url wrapper &amp; SSL support.</li><li>network monitor and basic explorer.</li></ol><h3>Section 1 —</h3><p>This is a link to setup Amazon AWS account. <a href="https://aws.amazon.com/">https://aws.amazon.com</a>. there are few other options available like digital ocean, google cloud, Microsoft azure with almost year worth of free subscription on the server. this provides basic server and can be easily upgraded for scaling. I prefer AWS cause I am using it for almost year and a half now.</p><p>Once you are registered on AWS, the next step is to start EC2 server</p><p>Click on <strong>EC2</strong> tab in All services. and click on <strong>Launch</strong> <strong>Instance </strong>inside<strong> </strong>Create Instance tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8R5K9rH68wO9E5zvZV1Uwg.png" /><figcaption>AWS dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*4-AZIJmwsYZbICXW-mU6KQ.png" /></figure><p>2. This will take you to Launch Instance Wizard. In which we can select the type of OS, storage, ports and PEM file for instance or server we can say.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzh9oq22SrhfiED0UM1mdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*621na-BU4lgjD91d_Ag6Tw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajv-2_1pcexc-2d2u0F45g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-VyC-1a20TBIHpTAY33TA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2_NgXLq_940j2zHGzFSHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6lA0A_wdAktalaBkKgAVKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*49A7fp6YqkQOWBqReWlBTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M6MO2fLZnipUaEtWHmY7vQ.png" /></figure><p>It takes at least 5 to 10 min to complete build once it’s done you can check the new instance in. I believe so far you have created an EC2 instance successfully. Congratulations! you can find all instances in EC2 dashboard under Instances tab. it will show all the servers. In our case, there will be only one server so click on that server and then click on connect.</p><p>this will show one modal which will have the command for our command prompt to connect to the server. any ubuntu /mac cmd will work in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mn1UQ1okUru15y9ti6JjqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fi2V74w45e4kbT6vgfZ4jQ.png" /></figure><p>open CMd and go to the directory in which the key pair file is saved. the .pem key. copy this command and paste it to cmd and hit enter to connect to the server. it will ask you <em>Are you sure you want to continue connecting (yes/no)? </em>type yes and hit enter.</p><p>Upon a successful connection, you will see this screen where ubuntu@yourIp will be mentioned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6TWeDSRLfcliwoxl25v1Zw.png" /></figure><p>Now will start with ethereum geth and few other tools installations and it is same as we do it on our regular desktop and laptop(just for Mac and Ubuntu).. just copy the commands to cmd one at a time…</p><pre>sudo apt-get install software-properties-common<br>sudo add-apt-repository -y ppa:ethereum/ethereum<br>sudo apt-get update<br>sudo apt-get install ethereum<br>sudo apt install nginx<br>sudo ufw enable<br>sudo ufw allow &#39;Nginx Full&#39;<br>sudo ufw allow &#39;OpenSSH&#39;<br>sudo add-apt-repository ppa:certbot/certbot<br>sudo apt install python-certbot-nginx<br>sudo ufw status</pre><p>now check the status of ufw by typing — <strong>sudo ufw status</strong></p><pre>Output</pre><pre>Status: active</pre><pre>To                         Action      From<br>--                         ------      ----<br>OpenSSH                    ALLOW       Anywhere                  <br>Nginx HTTP                 ALLOW       Anywhere                  <br>OpenSSH (v6)               ALLOW       Anywhere (v6)             <br>Nginx HTTP (v6)            ALLOW       Anywhere (v6)</pre><p>then check for Nginx service — <strong>systemctl status Nginx</strong></p><pre>Output</pre><pre>● nginx.service - A high performance web server and a reverse proxy server<br>   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)<br>   Active: active (running) since Fri 2018-04-20 16:08:19 UTC; 3 days ago<br>     Docs: man:nginx(8)<br> Main PID: 2369 (nginx)<br>    Tasks: 2 (limit: 1153)<br>   CGroup: /system.slice/nginx.service<br>           ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;<br>           └─2380 nginx: worker process</pre><p>Till now we have installed ethereum geth on the sever and few tools for port forwarding(Nginx) and SSL encryption(certbot).</p><p>Next up is Private network setup</p><p>go to root folder by typing</p><pre>cd ~</pre><p>In this case, we are going to create a network of two signer nodes. make a folder for network files.</p><pre>mkdir testnet<br>cd testnet<br>mkdir node1 node2<br>geth --datadir node1/ account new</pre><p>This command will ask you to enter the password and uppon show some output like this. please copy-paste the Public address of the key given in this output to some notepad.</p><blockquote>INFO [09–29|14:30:30.866] Maximum peer count ETH=50 LES=0 total=50</blockquote><blockquote>INFO [09–29|14:30:30.867] Smartcard socket not found, disabling err=”stat /run/pcscd/pcscd.comm: no such file or directory”</blockquote><blockquote>Your new account is locked with a password. Please give a password. Do not forget this password.</blockquote><blockquote>Password:</blockquote><blockquote>Repeat password:</blockquote><blockquote>Your new key was generated</blockquote><blockquote>Public address of the key: 0x518Ba9843d9a9c351B3c3B8719408583246c9241</blockquote><blockquote>Path of the secret key file: node3/keystore/UTC — 20129–09–29T14–30–36.547646701Z — 518ba9843d9a9c351b3c3b8719408583246c9241</blockquote><blockquote>- You can share your public address with anyone. Others need it to interact with you.</blockquote><blockquote>- You must NEVER share the secret key with anyone! The key controls access to your funds!</blockquote><blockquote>- You must BACKUP your key file! Without the key, it’s impossible to access account funds!</blockquote><blockquote>- You must REMEMBER your password! Without the password, it’s impossible to decrypt the key!</blockquote><p>Now let’s create an account for node 2</p><pre>geth --datadir node2/ account new</pre><p>again it will ask for the password and same message with a different public key. again copy-paste the Public address of the key given in this output to some notepad.</p><p>Next is creating genesis.json. for that, we can use puppeth command directly on cmd.</p><pre>Please specify a network name to administer (no spaces, please)<br>&gt; devnet<br>What would you like to do? (default = stats)<br> 1. Show network stats<br> 2. Configure new genesis<br> 3. Track new remote server<br> 4. Deploy network components<br>&gt; 2</pre><pre>Which consensus engine to use? (default = clique)<br> 1. Ethash - proof-of-work<br> 2. Clique - proof-of-authority<br>&gt; 2</pre><pre>How many seconds should blocks take? (default = 15)<br>&gt; 3 // in case you want to mine on demand then make it 0</pre><pre>Which accounts are allowed to seal? (mandatory at least one)<br>&gt; 0x518Ba9843d9a9c351B3c3B8719408583246c9241 // remove 0x from the address and copy paste it here.<br>&gt; 0x6a9c3c4d6e60c2c47d21ef607a00ccbb7ca3a581</pre><pre>Which accounts should be pre-funded? (advisable at least one)<br>&gt; 0x518Ba9843d9a9c351B3c3B8719408583246c9241 // again same step for ethers.<br>&gt; 0x6a9c3c4d6e60c2c47d21ef607a00ccbb7ca3a581</pre><pre>Specify your chain/network ID if you want an explicit one (default = random)<br>&gt; 48333442 // for example. Do not use anything from 1 to 10</pre><pre>What would you like to do? (default = stats)</pre><pre>1. Show network stats</pre><pre>2. Manage existing genesis</pre><pre>3. Track new remote server</pre><pre>4. Deploy network components</pre><pre>&gt; 2</pre><pre>1. Modify existing configurations</pre><pre>2. Export genesis configurations</pre><pre>3. Remove genesis configuration</pre><pre>&gt; 2</pre><pre>Which folder to save the genesis specs into? (default = current)<br>Will create genesis.json, genesis-aleth.json, genesis-harmony.json, genesis-parity.json<br>&gt;INFO [09-29|14:47:47.760] Saved native genesis chain spec          path=genesis.json<br>ERROR[09-29|14:47:47.760] Failed to create Aleth chain spec        err=&quot;unsupported consensus engine&quot;<br>ERROR[09-29|14:47:47.761] Failed to create Parity chain spec       err=&quot;unsupported consensus engine&quot;<br>INFO [09-29|14:47:47.762] Saved genesis chain spec                 client=harmony path=genesis-harmony.json</pre><pre>What would you like to do? (default = stats)</pre><pre>1. Show network stats<br>2. Manage existing genesis<br>3. Track new remote server<br>4. Deploy network components<br>&gt; ^C // ctrl+C to quit puppeth</pre><p>Good job!!!!! Few things to keep in mind. POA has no mining rewards but there is a catch to it. whenever transaction is mined the gas used to mine the transaction is sent to the singer as a reward so ether will always flow back to start.</p><p>Now you have genesis file and accounts so you can <strong>initialize the nodes.</strong></p><pre>geth --datadir node1/ init genesis.json<br>geth --datadir node2/ init genesis.json</pre><p>Perfect!!!!!!!</p><p>Next, now we have two accounts and we are good to go but when we need to set up a <strong>bootnode</strong> to help nodes discover for other peers since its gonna be peer to peer network shortly.</p><pre>bootnode -genkey boot.key<br>bootnode -nodekey boot.key -verbosity 9 -addr :30310</pre><p>now we have the bootnode key. to start the bootnode service first we need to understand that we are using the ubuntu command line to interact with the server. so there gona be cases when you want to check the logs in real-time so here I use a pre-installed program called <strong>screen.</strong></p><p>to test screen program write this command in cmd. ls is to basically check the existing screens. keep in mind that if you restart will kill all the screens running in the background. will cover that in-depth in another tutorial. for now, will use <strong>screens</strong> program</p><pre>screen -ls</pre><pre> No Sockets found in /run/screen/S-ubuntu.</pre><p>now will start screen and assign name to it</p><pre>screen -S bootnode</pre><p>Hit enter… once you will hit enter, it will take you to clean new same console</p><p>now will start bootnode service</p><pre>bootnode -nodekey boot.key -verbosity 9 -addr :30310</pre><pre>output &gt;&gt;<br><strong>enode://613ebdf4fd061cdd6eec54c596f7748e3866c4ce2109ef02812cf57b0e18b2e3b0ba95e5d1bc7b4a1781b347bce85cd318523c65459092871cfd6ab569c3e02a@127.0.0.1:0?discport=30310</strong></pre><pre>Note: you&#39;re using cmd/bootnode, a developer tool.</pre><pre>We recommend using a regular node as bootstrap node for production deployments.</pre><pre>INFO [09-29|15:00:36.497] New local node record                    seq=1 id=91ee0f8f428623a3 ip=&lt;nil&gt; udp=0 tcp=0</pre><p>copy paste that full enode to notepad and most important to remove “<strong>0?discport=” </strong>from the enode, then to minimize screen again use</p><pre>ctrl+A+D //to minimize screen</pre><pre>screen -ls // to check all screen <br>There is a screen on:<br><strong>2556.bootnode</strong> (09/29/19 15:00:32) (Detached)<br>1 Socket in /run/screen/S-ubuntu.</pre><p>if you want to again maximize that screen then use -r flag</p><pre>screen -r 2556 // -r to resume and <strong>screennumber</strong> in this case 2556.bootnode</pre><p>now to minimize again use <strong>ctrl+A+D</strong></p><p>To start node 1 -</p><p>again will create screen to make it more accessible</p><pre>&gt;&gt; screen -S node1</pre><pre>&gt;&gt; geth --datadir node1/ --syncmode &#39;full&#39; --port 30311 --rpc --rpcaddr &#39;0.0.0.0&#39; --rpcport 8501 --rpcapi &#39;personal,db,eth,net,web3,txpool,miner&#39;   --ws  --wsaddr &#39;0.0.0.0&#39;  --wsport 8601  --wsapi &#39;personal,db,eth,net,web3,txpool,miner&#39;  --wsorigins * --rpccorsdomain * --bootnodes &#39;enode://613ebdf4fd061cdd6eec54c596f7748e3866c4ce2109ef02812cf57b0e18b2e3b0ba95e5d1bc7b4a1781b347bce85cd318523c65459092871cfd6ab569c3e02a@127.0.0.1:30310&#39; --networkid 48333442 --gasprice &#39;1&#39;</pre><p>it will start the node and to minimize again use ctrl+A+D //to minimize screen</p><p>To start node 2 -</p><p>again will create screen to make it more accessible</p><pre>&gt;&gt; screen -S node2</pre><pre>&gt;&gt; geth --datadir node2/ --syncmode &#39;full&#39; --port 30311 --rpc --rpcaddr &#39;0.0.0.0&#39; --rpcport 8502 --rpcapi &#39;personal,db,eth,net,web3,txpool,miner&#39;   --ws  --wsaddr &#39;0.0.0.0&#39;  --wsport 8602  --wsapi &#39;personal,db,eth,net,web3,txpool,miner&#39;  --wsorigins * --rpccorsdomain * --bootnodes &#39;enode://613ebdf4fd061cdd6eec54c596f7748e3866c4ce2109ef02812cf57b0e18b2e3b0ba95e5d1bc7b4a1781b347bce85cd318523c65459092871cfd6ab569c3e02a@127.0.0.1:30310&#39; --networkid 48333442 --gasprice &#39;1&#39;</pre><p>it will start node 2. 🥰</p><p>now we have to manually connect to each node geth console and start mining in order to mine transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Twnia_95eVhNtgd-xHg2Pw.png" /></figure><pre>&gt;&gt; personal.unlockAccount(eth.coinbase,”passme”,0)</pre><pre>&gt;&gt; miner.start()</pre><pre>&gt;&gt;eth.sendTransaction({from:eth.coinbase,value:3045345435435,to:’0x3592eb9861E427C4b9d7894E910690d58d7b340F’})</pre><p>Good work!!!!</p><p>So far we have successfully set up a private POA network.</p><p>In next part will cover Url wrapper &amp; SSL support. Stay tuned!</p><p>smash like button and share!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fdf56d2ad93" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>