<?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 Parth Sharma on Medium]]></title>
        <description><![CDATA[Stories by Parth Sharma on Medium]]></description>
        <link>https://medium.com/@parth-sharma?source=rss-a4bac16dac4d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*J-9bGNZct7q_fzRZn-ahxw.jpeg</url>
            <title>Stories by Parth Sharma on Medium</title>
            <link>https://medium.com/@parth-sharma?source=rss-a4bac16dac4d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 07:25:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@parth-sharma/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[Enabling payments in cryptocurrency]]></title>
            <link>https://parth-sharma.medium.com/enabling-payments-in-cryptocurrency-547344638ffb?source=rss-a4bac16dac4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/547344638ffb</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[erc20]]></category>
            <dc:creator><![CDATA[Parth Sharma]]></dc:creator>
            <pubDate>Sat, 19 Jun 2021 13:06:29 GMT</pubDate>
            <atom:updated>2021-06-19T13:07:45.757Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*AXxkQEJRGKMa0r38ujEy1Q.jpeg" /></figure><p>Cryptocurrency is a new type of digital asset that is housed in a network in which it is distributed throughout a vast number of computers. As a result, it has a decentralized structure which enables them to thrive outside government and central authority control.</p><p>As the demand for trading grows, along with the facilitation of cross-border transactions, so does the acceptance and use of cryptocurrency.</p><p>The major economies that are stimulating the growing use of cryptocurrency include the emerging economies which include Brazil, China, and India. For the developed countries, Japan, Germany, and the US lead the way in the growth of cryptocurrency use.</p><p>So why not enable payments in cryptocurrency in e-commerce websites?</p><p>In this article, we will be exploring various blockchain technologies and writing code to create our own e-commerce website to buy e-books/movies which will accept payments in <em>ERC-20 tokens</em>.</p><p>The entire project consists of 3 parts, the smart contracts, frontend, and backend. We will use <strong>Solidity</strong> to code our <strong>smart contracts </strong>with<strong> Truffle framework </strong>and the project will be deployed on <strong>Ganache </strong>local blockchain<strong> </strong>, <strong>Reactjs</strong> for the <strong>frontend</strong>, and <strong>Node.js</strong> for the <strong>backend</strong> with <strong>MongoDB</strong> as the <strong>database</strong>.</p><p><strong>— Building smart contracts</strong></p><p>A smart contract is simply a program that runs on the Ethereum blockchain. It’s a collection of code and data that resides at a specific address on the Ethereum blockchain. Smart contracts are a type of Ethereum account. This means they have a balance and they can send transactions over the network.</p><p>We will use ERC 20 tokens here. ERC 20 tokens are assets that live on the ethereum blockchain. For each ERC 20 token we have a smart contract that manages token transfer and a ledger of who owns how many tokens. Although a big problem with ERC 20 tokens is that their value fluctuates a lot. So if we accept any ERC 20 tokens we will be supposed to sell the tokens right away, so that we aren’t exposed to the price fluctuations, which will make things very complicated. So instead, we are accepting only a specific kind of ERC 20 tokens called Stablecoin. Stablecoins are tokens whose value always stay the same. Now there are different Stablecoin variables like DAI, USDC,USDT etc. Here we used DAI because it’s the most popular Stablecoin and its the most decentralized Stablecoin of all.</p><p>For designing and coding the smart contracts in our application we will use Solidity, OpenZeppelin and Truffle. OpenZepplin being a library for solidity smart contracts.</p><p>We will be building 2 smart contracts for this project, “Dai.sol”, and “PaymentProcessor.sol”</p><p>The first step is to install Truffle and initiate a project in truffle. It can be simply done using the commads: “<strong>npm install truffle</strong>” and then “<strong>truffle init</strong>”.</p><p>Next we need to initiate an npm project to manage our dependencies. Using the command “npm init -y” will do the work for us.</p><p>Next we will install OpenZeppilin using “<strong>npm install @openzeppelin/contracts</strong>”.</p><p>So now with everything installed and initialized, lets start coding our smart contracts!</p><ul><li><strong>PaymentProcessor.sol</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*MK-IXkNXlpCt8P3fKoxdUg.png" /></figure><p>PaymentProcessor.sol is the smart contract which has functions defined such as Pay() which is triggered each time we make a payment, which takes in two arguments that is the amount of DAI tokens transferred and the paymentID. It listens to the payment events sent by the backend, which further saves the payment events in our Database, and delivers the item link to the frontend.</p><ul><li><strong>Dai.sol</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*tMu4Upm7GUakRHYqt1pDzg.png" /></figure><p>The Dai.sol smart contract approves the transaction done by PaymentProcessor.sol. DAI token is already deployed on the Ethereum mainNet, but the reason why we still need to create a smart contract for DAI is becaause we want to be able to use public testnet and local development blockchain in order to develop our system. Thus, for that we need to deploy our own version of DAI token.</p><p>Next we need to code a <strong>migration file</strong> to tell truffle how to <strong>deploy our smart contracts</strong>.</p><ul><li><strong>2_deploy_contracts.js</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*kv3sjv5OpXCfEQb6yBd6bg.png" /></figure><p>Here we use web3, which is a Javascript library that is used to interact with the ethereum blockchain, and its automatically injected in our deployment script by the truffle framework. In addition to that we use a utility function to specify how many tokens we want to send. We did not deploy Dai,sol here since it is already deployed on the mainNet and public testnet.</p><p>Now, its time to deploy all this to our local blockchain!</p><p>We need to type the command “<strong>truffle develop</strong>” in the root of our project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jb_p_dcj7A9MSj9F3CY6Kg.png" /></figure><p>Thus, we have launched <strong>Ganache, </strong>a local development blockchain that is already installed with truffle. We get 10 addresses generated by ganache with their private keys. For each of these addresses we have 100 ether (which are obviously fake :)) and also, we get a console we can use to interact with our local blockchain. So now we need to type the command “<strong>migrate --reset</strong>” in this console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2iptN7ZO0ZSdY8uJD5KGOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9QRmzHDE7oDVLvCbfJB7fg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mnv0Ywqmiyp2AuGU2th8Fw.png" /></figure><p>Great! Our deployment was successful. We can clearly see the deployment of our DAI token, and PaymentProcessor with their respective addresses. Hence we are done with the smart contracts and their deployment.</p><p>Now, a problem arises, that React cannot access/import anything which is outside the src folder of the react-app. So we will need to change the location where truffle stores PaymentProcessor in JSON format.</p><p>For that, we will open the <strong>truffle-config.js</strong> file in our root folder and specify the new configuration by writing:</p><p>“<strong>contracts_build_directory: ‘./frontend/src/contracts’,</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*WXi6RxpMX1xe3sMmyM8OyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*rw3-eHQOoBwQsGoc4lIXsQ.png" /></figure><p>Now we will need to re-deploy our contracts so that the JSON artifacts can be stored in the proper location, using the same command : migrate --reset , in the ganache console. Hence we get a contracts folder in src directory consisting of all the required JSON files.</p><p>We need to write code to configure connection of our React app with the blockchain, so we will create a file “<strong>ethereum.js</strong>” inside the src directory of our React-app.</p><ul><li><strong>ethereum.js</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*sB9YVTNRjvqlsLBCmWgjXg.png" /></figure><p>The function getBlockchain() establishes a connection with ethereum. It returns a promise. We will wait till all the elements in the window have loaded in the browser, including the Javascript and Metamask, thus used “window.addEventListener” with “load” parameter. If metamask is present then its going to inject an object called “ethereum” in the window. Thus the user receives a pop up asking them to grant permission of metamask for this application. Next we create a provider with ether, establishing connection with the blockchain. The provider is of type “Web3Provider”. Thus we will be able to send transactions after an object is instantiated which can interact with our PaymentProcessor smart contract. We then do the same thing with Dai.</p><p>In this article, I have mentioned the parts where a significant use of blockchain technologies is used. The rest of frontend and backend code can be accessed through the link given below :)</p><p><strong>The entire source code to this project can be accessed on my github:</strong></p><p><a href="https://github.com/parthsharma1410/Blockchain-Ecommerce">parthsharma1410/Blockchain-Ecommerce</a></p><p>You can clone it and run “<strong>npm install</strong>” by navigating to the frontend and backend folders respectively, to install all the dependencies which are needed to run the project.</p><p>Install metamask chrome extension, which is a software cryptocurrency wallet used to interact with the Ethereum blockchain. It allows users to access their Ethereum wallet through a browser extension or mobile app, which can then be used to interact with decentralized applications. While logging into metamask, you must enter the <strong>seed-phrase mnemonic</strong> we got after running <strong>truffle develop</strong>.</p><p>With our local blockchain running, you need to open 2 more terminals<strong>, </strong>navigate to the frontend and backend folders respectively, and type the commands “<strong>npm start</strong>” in the frontend terminal, and “<strong>node server.js</strong>” in the backend terminal.</p><p>Soon your browser will open localhost:3000, and there it is! Our website is running and you can try buying items from the catalogue ✌🏼</p><blockquote>Final product screenshots</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FViyRY70wOrgz4Dw6jFQQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFfitj5KtOZHRm_c3Ugj0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Sd2zPc2QWnlP5AmsXtY6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPGPOgAVK23FLRR7b3JS0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wJQHjJQxHB5empyRH745vw.png" /></figure><ul><li><a href="https://www.linkedin.com/in/parth-sharma-59a585100000000aa/">Parth Sharma - Director of Technical and Finance - Matrix VIT | LinkedIn</a></li><li><a href="https://github.com/parthsharma1410">parthsharma1410 - Overview</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=547344638ffb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 ReactJS tips and tricks you need to know as a frontend developer.]]></title>
            <link>https://parth-sharma.medium.com/10-reactjs-tips-and-tricks-you-need-to-know-as-a-frontend-developer-68089ff663a6?source=rss-a4bac16dac4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/68089ff663a6</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Parth Sharma]]></dc:creator>
            <pubDate>Thu, 08 Apr 2021 05:53:52 GMT</pubDate>
            <atom:updated>2021-04-16T18:51:17.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2usFkt0_Zl0HVTa12zW5jA.png" /></figure><p>React has made communication between the client and server side easier. The concept of components and data patterns used by React enhance the performance, and make our code easier to read and understand. Support for JSX syntax, Virtual DOM, code stability and SEO friendliness make it the most popular JavaScript framework. So it is pretty clear why a frontend developer would prefer React, thus we move on with 10 extremely useful React tips and tricks every frontend developer should know.</p><h3><strong>1. Use functional components</strong></h3><p>Previously there were two choices for defining React components, the first being React.createClass() :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*_y86JoKcH0wQ88OTnqqRfg.png" /></figure><p>And the other being ES6 classes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*sO8-ucZ8hqmuJrb6t8Na-Q.png" /></figure><p>React 0.14 introduced a new syntax for defining components, as functions of props:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*1P7E8R1z2ujGL3WYYPCPQQ.png" /></figure><p>This is by far my favourite method for defining React components. Apart from the more concise syntax, this approach can really help make it obvious when a component needs to be split up. It’s important to note that functional components have a few ‘limitations’, which I consider to be their greatest strengths. The first is that a functional component cannot have a “ref” assigned to it. While a ref can be a convenient way for a component to look up it&#39;s children and communicate with them, my feeling is that this is not the most efficient way to write React. refs encourage a very imperative, almost Jquery like way of writing components, taking us away from the functional, one-way data flow concept for which we chose React in the first place.</p><h3>2. Fragment shorthand</h3><p>The React fragment has saved us from having additional DOM elements lying around, but the shorthand can save you a little bit of time and space at many places in your code.</p><pre>// Long<br>&lt;React.Fragment&gt;&lt;/React.Fragment&gt;<br>// Short<br>&lt;&gt;&lt;/&gt;</pre><p>When using the shorthand, just make sure that your linter is set up to not show errors for using it, or that your formatter incorrectly treats the shorthand and creates a random jumbled mess out of your code.</p><h3>3. Always use propTypes</h3><p><a href="https://facebook.github.io/react/docs/reusable-components.html#prop-validation">propTypes</a> offer us a really easy way to add a bit more type safety to our components. They look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*w55moFRPCosVpJhh8qyxRw.png" /></figure><p>When in development, if any component is not given a required prop, or is given the wrong type for one of its props, then React will log an error to let you know. This has several benefits:</p><ul><li>It can catch bugs early, by preventing silly mistakes</li><li>If you use isRequired, then you don&#39;t need to check for undefined or null as often</li><li>It acts as documentation, saving readers from having to search through a component to find all the props that it needs</li></ul><h3>4. Name your components</h3><p>To figure which component has a bug, it’s important to always give your component a name. Even more so when you begin to use React Router or third party libraries.</p><pre>// Avoid these notations <br>export default () =&gt; {};<br>export default class extends React.Component {};</pre><p>There is a debate about whether to use a default or named import. Note that a <strong>default import</strong> doesn’t ensure that the component’s name is consistent in the project. Besides, <a href="https://en.wikipedia.org/wiki/Tree_shaking">tree-shaking</a> will be less effective.</p><p><strong>No matter how you expose your component, name it</strong></p><p>You need to define the class name or the variable name (for functional components) that’s hosting the component.</p><p>React will actually infer the component name from it in error messages.</p><pre>export const Component = () =&gt; &lt;h1&gt;This is a component&lt;/h1&gt;;<br>export default Component;</pre><pre>// Define user custom component name<br>Component.displayName = &#39;My Component&#39;;</pre><h3>5. Use Redux</h3><p>Redux is a predictable state container designed to help you write JavaScript apps that behave consistently across client, server, and native environments and are easy to test.</p><p>Redux is mostly used as a state management tool with React.</p><p>With Redux, the state of your application is kept in a store, and each component can access any state that it needs from this store.</p><h3>6. Keep your logic out of your JSX</h3><p>If you’ve got some logic going on in your JSX, whether it is a callback or the rendering of some elements, defining a separate function can go a long way for readability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*8acpa5dvbJFYestKA_11zg.png" /></figure><h3>7. Keep your components small</h3><p>The smaller your components, the easier they are to test and the easier it will be to keep your components focused on what it is they should actually do. If your components starts to get large, reassess the logic and see if you can’t move some of that into utilities, hooks, or even break that component up into smaller components.</p><h3><strong>8. </strong>Omitting a prop value defaults to true</h3><p>Just like writing an attribute with no value for an element in HTML defaults to true, omitting the prop value for a component will default to true.</p><p>The React documentation shows that both lines below pass the autocomplete prop as true.</p><pre>&lt;MyTextBox autocomplete /&gt;</pre><pre>&lt;MyTextBox autocomplete={true} /&gt;</pre><h3>9. You don’t need super() in your constructor</h3><p>super() is called inside a react component only if it has a constructor. For example, the below code doesn&#39;t require super:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*FzSJ6GzuvUY3nY1YssZPPw.png" /></figure><p>However if we have a constructor then super() is mandatory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*_kqSIMJXlRjkP7FnfFe-pA.png" /></figure><p>If you’re not doing anything with your props in your constructor, you can safely omit super() from your constructor.</p><h3>10. Components don’t neccesarilly have to correspond to DOM nodes</h3><p>When we first learn React, we’re taught that “Components are the building blocks of React and they take in input and return some UI descriptor “. Does that mean that every component needs to directly return UI descriptors as we’re typically taught? What if we wanted to have a component render another component ? What if we wanted a component to manage some slice of state and then instead of returning a UI descriptor, it returns a function invocation passing in the state ? What if we had a component that was in charge of managing sound rather than a visual UI, what would it return? What’s great about React is you don’t have to return typical “views” from your components. As long as what eventually gets returned is a React element, null, or false, you’re good.</p><p>You can return other components,</p><pre>render () {<br>  return &lt;MyOtherComponent /&gt;<br>}</pre><p>you can return function invocations,</p><pre>render () {<br>  return this.props.children(this.State)<br>}</pre><p>or, you can return nothing.</p><pre>render () {<br>  return null<br>}</pre><ul><li><a href="https://github.com/parthsharma1410">parthsharma1410 - Overview</a></li><li><a href="https://www.linkedin.com/in/parth-sharma-59a5851aa/">Parth Sharma - Vellore Institute of Technology - Bareilly, Uttar Pradesh, India | LinkedIn</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68089ff663a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>