<?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[openberry - Medium]]></title>
        <description><![CDATA[Anyone using openberry can become a blockchain engineer - Medium]]></description>
        <link>https://medium.com/openberry?source=rss----9b65c4aa51d4---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>openberry - Medium</title>
            <link>https://medium.com/openberry?source=rss----9b65c4aa51d4---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 22:18:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/openberry" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a Simple Crowdfunding Dapp with Ethereum Solidity and Vue.js]]></title>
            <link>https://medium.com/openberry/creating-a-simple-crowdfunding-dapp-with-ethereum-solidity-and-vue-js-69ddb8e132dd?source=rss----9b65c4aa51d4---4</link>
            <guid isPermaLink="false">https://medium.com/p/69ddb8e132dd</guid>
            <category><![CDATA[crowdfunding]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Sam Benemerito]]></dc:creator>
            <pubDate>Wed, 13 Mar 2019 07:38:17 GMT</pubDate>
            <atom:updated>2019-03-13T09:58:14.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*6aFWmznBvYZgC80khhiiBw.png" /></figure><p>A lot of us might have been in a situation wherein we had a brilliant idea, may it be of a product or an event, but just didn’t have the funds to bring it to life. This is where crowdfunding comes in.</p><p>You might have already heard of <a href="https://www.kickstarter.com/">Kickstarter</a>, or <a href="https://camp-fire.jp/">CAMPFIRE</a>, which are some of the known crowdfunding platforms that currently exist. In this tutorial, we’ll be building something similar, specifically a simple <em>decentralized</em> crowdfunding platform using Ethereum.</p><h3>What We Are About To Build</h3><p>In this tutorial, we’ll be building a simple crowdfunding dapp which will have the ‘minimum’ functionalities that you’d expect from a crowdfunding platform. Basically, we should be able to start crowdfunding projects, and fund them, which will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3QW6sKpA5K4ioilHDDTl5g.gif" /></figure><h4>Function List</h4><ol><li>Start Project — we should be able to start a new crowdfunding project, along with setting its details like goal amount, etc.</li><li>View Projects — we should be able to retrieve our existing projects’ details and display it</li><li>Fund Project — we should be able to fund an existing project with Ether</li><li>Retrieve Funds — in the case where a project does not meet its goal amount, and is past its deadline, funders should be able to retrieve their contributed funds (All-or-Nothing setup)</li></ol><h4>Tools</h4><ol><li>Smart Contract<br><a href="https://solidity.readthedocs.io/en/latest/">Solidity</a>, <a href="https://remix.ethereum.org/">Remix</a>, <a href="https://metamask.io/">Metamask</a></li><li>Frontend<br><a href="https://web3js.readthedocs.io/en/1.0/">Web3.js</a>, <a href="https://vuejs.org/">Vue.js</a>, <a href="https://cli.vuejs.org/">Vue-cli</a>, <a href="https://vuetifyjs.com/en/">Vuetify</a></li></ol><p>Aside from that, we will also be using <a href="https://git-scm.com/">Git</a> later to clone our boilerplate :)</p><h4>Prerequisites</h4><p>Before proceeding with this tutorial, you should first read the following articles:</p><ol><li><a href="https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83">Getting Started with Metamask</a></li><li><a href="https://medium.com/openberry/compile-and-deploy-using-remix-ide-f58fcc662ed0">Compile and Deploy Using Remix IDE</a></li><li><a href="https://solidity.readthedocs.io/en/v0.5.4/introduction-to-smart-contracts.html">Introduction to Smart Contracts and Solidity</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Why Make a Crowdfunding App?</h3><p>Great ideas need effort and funding. You can ask for donations or solicitations, but donors would of course prefer giving to projects where they have some sort of certainty that the project is actually going somewhere.</p><p>This is where crowdfunding comes in, an ideal setup where you can specify your goal, and a deadline for reaching it. If you miss your goal, the donations are returned, therefore reducing the risk for donors.</p><p>The existing platforms are all great, but in every completed project or in every donation sent, the platform takes a certain percent (margin) which could, at times, be too high for the project starters. What’s more, is that we heavily depend on them as the third-party that connects us to the donors. Should they fail, then we’re also in trouble.</p><p>With a decentralized setup, we can have a trustless platform and therefore the only fees everyone will pay are just the gas fees.</p><p>This is also one of the apps that are good to build early on, because you can definitely learn a lot by doing so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Making the Project</h3><h4>Workflow</h4><ol><li>Creating the Smart Contract</li><li>Building the Web App</li></ol><h3>Creating the Smart Contract</h3><p>We’ll be using <a href="https://solidity.readthedocs.io/en/v0.5.4/index.html">Solidity</a>, one of the programming languages used for creating smart contracts, specifically for Ethereum-based ones.</p><p>In <a href="https://remix.ethereum.org/">Remix</a>, create a new file named <strong>Crowdfunding.sol</strong> and add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6605903f7f382c248d11c12c7ab53a9/href">https://medium.com/media/f6605903f7f382c248d11c12c7ab53a9/href</a></iframe><p>We’re creating 2 contracts in one <em>.sol</em> file: <em>Crowdfunding</em> and <em>Project</em>. The <strong>Crowdfunding</strong> contract acts as a container for all Project contracts that will be initialized. Each crowdfunding project will have a contract of its own.</p><p>As for the <strong>Project</strong> contract, it is instantiated through the Crowdfunding contract, and handles all the methods that can be performed in every crowdfunding project, such as <em>contribute</em>(), <em>getRefund</em>(), etc.</p><p>Basically, each project will initially be in the <em>Fundraising </em>state, and will change states through the <em>checkIfFundingCompleteOrExpired</em>() function from there. Every time someone contributes funds towards the project, the state will change depending on certain conditions such has “has the project goal amount been met” or “has the project exceeded set deadline”.</p><p>Also, notice how we send funds from our contract in both the payOut() and getRefund() functions. We did not just directly send it, but had some security considerations because this is an area prone to a <a href="https://solidity.readthedocs.io/en/v0.5.3/security-considerations.html#re-entrancy">re-entrancy attack</a>.</p><p>And so, compile the <strong>Crowdfunding</strong> contract (make sure you select compiler version at the right side of Remix, and choose <strong>0.5.4+commit.9549d8ff </strong>because we are using Solidity version 0.5.4) and deploy it to the <strong>Ropsten Test Network</strong>. Make sure you are compiling and deploying the <strong>Crowdfunding </strong>contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>To check that our contract was deployed, you should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*aNaBsa7tSmyweepJUcrXbQ.png" /><figcaption>Contract was successfully compiled</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*pqayMqgyFg2zbkoIjvU5ZQ.png" /><figcaption>Contract was successfully deployed and is listed in “Deployed Contracts”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h3>Building the Web App</h3><p>We’re done working on our smart contract. However, it doesn’t seem user-friendly and fun to just use Remix to interact with the contract, so we’ll be making a simple web application.</p><h4>Setting Up</h4><p>To get up to speed, let’s clone a boilerplate project (found <a href="https://github.com/openberry-ac/crowdfunding/tree/boilerplate">here</a>) by doing the following in a Terminal (or Command Prompt/Powershell for Windows):</p><pre># Cloning the boilerplate from GitHub<br>git clone -b boilerplate --single-branch <a href="https://github.com/TART-tokyo/cryptovipers.git">https://github.com/openberry-ac/crowdfunding.git</a></pre><pre># Navigating to the directory and installing packages<br>cd <a href="https://github.com/TART-tokyo/cryptovipers.git">crowdfunding</a><br>npm install</pre><pre># To run the app<br>npm run serve</pre><p>In a few minutes, you should see the app running through a browser on <a href="http://localhost:8080/">http://localhost:8080</a>. Apparently, all we see is a white screen, because there is an error. If we open our console, we can see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hMqbG04d_IyZk0etqGulbw.png" /></figure><p>Thing is, we have not connected our web app with our smart contract instance yet, which causes this error. And so, that is exactly what we’re about to do next.</p><h4>Connecting to Our Smart Contract Instance</h4><p>To enable our web app to interact with our smart contract, we will be using <a href="https://github.com/ethereum/web3.js/">web3.js</a>. We already have the package installed, you can see how it is called in the file named <strong>web3.js</strong> inside the “contracts” folder, where we should put something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cc5092574ad4718d9adcb78b1ec605b/href">https://medium.com/media/4cc5092574ad4718d9adcb78b1ec605b/href</a></iframe><p>It basically loads the web3 instance the MetaMask extension initializes, which we will be needing later to interact with our smart contract.</p><p>You <strong>might</strong> encounter a MetaMask pop-up window that asks for access permission. This is because we have ethereum.enable() where the app requests for account (or wallet) access. You should just click the ‘Connect’ button right here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*NJoKFH25a6BtYuT5UvTNiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>Voila! You should see the app running through a browser on <a href="http://localhost:8080/">http://localhost:8080</a> looking like this (though it is not functional yet):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*shaS7dL24HsV_qkV-XOMsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><p>Now, we need our smart contract’s ABI to connect it to our web app. We have 2 contracts, so we need to get both their ABIs. To get it, go back to <a href="https://remix.ethereum.org/">Remix</a>, go to the <strong>Compile</strong> tab, and click <strong>ABI</strong> beside the Details button as shown in the picture (make sure <strong>Crowdfunding </strong>is selected):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*wZxSyIH8vLuy2XXIuZpTig.png" /><figcaption>Copy the ABI by clicking the ABI button</figcaption></figure><p>After getting it, open the file named <strong>crowdfundInstance.js</strong> in the <strong>contracts</strong> folder, then paste it as the variable <strong>abi </strong>’s<strong> </strong>value. There should be an example in the file, which you can always refer to.</p><p>Then, as you can see, we also need the deployed contract’s address, which you can get by going to <a href="https://remix.ethereum.org/">Remix</a>’s Deploy tab, and clicking the copy icon on your deployed contract, as shown in this picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*F2msplcObqmWUVnxZ7wtOA.png" /><figcaption>Copy the contract address by clicking the copy icon</figcaption></figure><p>Go back to <strong>crowdfundInstance.js</strong> in the <strong>contracts</strong> folder, then paste the address as the variable <strong>address </strong>’<strong> </strong>value. Save the file, and we’re done setting the contract information for our Crowdfunding contract. For the Project contract, just go back to <a href="https://remix.ethereum.org/">Remix</a>’s Compile tab, select the <strong>Project</strong> contract, and get the ABI just like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*GISUKdZvtXjyvtmqawBXqQ.png" /><figcaption>Copy the ABI by clicking the ABI button</figcaption></figure><p>After getting it, open the file named <strong>crowdfundProjectInstance.js</strong> in the <strong>contracts</strong> folder, then paste it as the variable <strong>abi </strong>’s<strong> </strong>value. There should be an example in the file, which you can always refer to. We’re all set!</p><h4>Defining the Methods</h4><p>As we see in the browser, our user interface is ready, but apparently, nothing is functional yet. That’s because we have not defined our functions yet, which we will be doing now. Go back to <strong>App.vue</strong>, and go to line 221 where you can see <strong>methods</strong>, but everything just contains a <em>console.log()</em>.</p><p>Our first function is retrieving all projects and their details. Let’s modify the <em>getProjects()</em> function to look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bea916bc306cb8ca35378eb7fe66bca5/href">https://medium.com/media/bea916bc306cb8ca35378eb7fe66bca5/href</a></iframe><p>For this part, we simply call the <em>returnAllProjects</em>() function of our Crowdfunding contract to get all the projects’ contract addresses. Then, for each of them, we call <em>getDetails</em>() and store them in our defined objects, <em>projectInstances</em>, <em>projectData</em>, etc.</p><p>Next, we modify the function for starting a new project, <em>startProject()</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/076fc6364ab17562fec07d2568bf0995/href">https://medium.com/media/076fc6364ab17562fec07d2568bf0995/href</a></iframe><p>Here, we’re just calling Crowdfunding contract’s <em>startProject</em>() function, while passing the data that has been inputted through the form. The contract then receives the data and creates a new project. After that, we get data being returned by the <strong>ProjectStarted</strong> event, and store the new project, along with some default values, in the web app too.</p><p>Note that we use this.account in this part, which was retrieved in the <em>mounted</em>() part of the code (executed when component has been <em>mounted</em>). It’s basically the current account that is active in Metamask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>Now that we’ve set the functions for starting and viewing projects, let’s see them in action, shall we?</p><p>Let’s start a new project by clicking “Start a Project”, filling the form, and then submitting it. Note that there aren’t any form validation in place, so it’d be ideal if you input valid values for now :)</p><p>Once that’s done, your newly created project should immediately show up on the projects list like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cjp8PKI1jkS2PCgEa1i3Ww.png" /><figcaption>New project now shows in project list. Easy!</figcaption></figure><p>Note: The app might not appear like the one shown on the image though. The interface for funding the project might not show because <strong>project creators are not allowed to fund their own project</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><p>Moving on, we have the method that handles the event when a user funds a certain project, <em>fundProject()</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53dc9428ca585333ab5b98ad6e39e7fd/href">https://medium.com/media/53dc9428ca585333ab5b98ad6e39e7fd/href</a></iframe><p>Remember the contribute() function in our smart contract? We just call that function in <em>fundProject</em>() which sends the amount the user inputted in to the form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>After defining the <em>fundProject</em>() function, we should now be able to use the previously ‘<em>not functional</em>’ fund button. What’s more is that immediately after the transaction is completed, the progress bar is updated. It should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E58_oizyVX2-iCRM2J7bgw.gif" /><figcaption>Funding a project</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><p>Finally, we have <em>getRefund</em>(), which allows the user to retrieve his or her previously donated funds to an already expired (past deadline) project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/573499dfaa3144af89ee328372bc1ef5/href">https://medium.com/media/573499dfaa3144af89ee328372bc1ef5/href</a></iframe><p>And, we’re done!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>Refresh your browser to see the changes. This time, the whole web app is complete, and everything is functional! You should then be able to use it like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*3QW6sKpA5K4ioilHDDTl5g.gif" /><figcaption>Sample usage. You did it!</figcaption></figure><p>You can see the final result on this <a href="https://github.com/openberry-ac/crowdfunding/">GitHub repository</a> (master branch) which you can always refer to :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h3>Conclusion</h3><p>We just finished making our simple crowdfunding platform! Awesome!</p><p>We learned how to instantiate a contract using another contract, and many more concepts related to Solidity through this application. We also learned how to set up our own project using Vue.js, and created a simple application.</p><p>So, what’s next?</p><p>Ethereum’s website has a <a href="https://www.ethereum.org/crowdsale">crowdsale tutorial</a> which you might want to check out. It’s similar to what we just did, but uses a different approach (more into having a Decentralized Autonomous Organization). You might also want to write everything from scratch as you already have an idea on how the whole thing works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*sJzvVSLTXSwvzMg80rAtAA.png" /></figure><p>On a side note, you might want to check out openberry’s previous tutorial, <a href="https://medium.com/openberry/ethereum-solidity-vue-js-tutorial-simple-auction-dapp-within-10-minutes-76ba48156b2">Ethereum Solidity + Vue.js Tutorial Simple Auction Dapp within 10 minutes</a>.</p><p>’til the next tutorial!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><p>openberry is a tutorial marketplace, designed to allow anyone to learn blockchain programming.</p><ul><li><a href="https://www.openberry.ac/">openberry | blockchain tutorial marktplace</a></li><li><a href="https://twitter.com/openberry_ac">openberry (@openberry_ac) | Twitter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69ddb8e132dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/openberry/creating-a-simple-crowdfunding-dapp-with-ethereum-solidity-and-vue-js-69ddb8e132dd">Creating a Simple Crowdfunding Dapp with Ethereum Solidity and Vue.js</a> was originally published in <a href="https://medium.com/openberry">openberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ethereum Solidity + Vue.js Tutorial Simple Auction Dapp within 10 minutes.]]></title>
            <link>https://medium.com/openberry/ethereum-solidity-vue-js-tutorial-simple-auction-dapp-within-10-minutes-76ba48156b2?source=rss----9b65c4aa51d4---4</link>
            <guid isPermaLink="false">https://medium.com/p/76ba48156b2</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Hayata Satomi]]></dc:creator>
            <pubDate>Wed, 27 Feb 2019 05:33:29 GMT</pubDate>
            <atom:updated>2019-02-27T05:33:29.308Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ethereum Solidity + Vue.js Tutorial Simple Auction Dapp within 10 minutes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*sJzvVSLTXSwvzMg80rAtAA.png" /></figure><p>You might have heard of auctions, a place where you can buy and sell things. Although it is very convenient, it costs sellers about 10% of their earnings to pay the service charge to the auction’s managing company.</p><p>If the company itself cheats some transactions and get the money, how will you know that you have been cheated?</p><p>This is where a decentralized setup is an optimal solution.<br>If there is no third party, sellers can earn more, in a secure way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-b3ZB_iZt1DdQ8hHBIlHw.gif" /></figure><h4>Function List</h4><ol><li>Creating an auction</li><li>Placing a bid</li><li>Finalizing an auction</li></ol><h4>Tools</h4><ol><li>Smart Contract<br><a href="https://solidity.readthedocs.io/en/latest/">Solidity</a>, <a href="https://remix.ethereum.org/">Remix</a>, <a href="https://metamask.io/">Metamask</a></li><li>Frontend<br><a href="https://web3js.readthedocs.io/en/1.0/">Web3.js</a>, <a href="https://vuejs.org/">Vue.js</a>, <a href="https://cli.vuejs.org/">Vue-cli</a>, <a href="https://bootstrap-vue.js.org/">Boostrap-vue</a></li></ol><h4>Prerequisites</h4><ol><li><a href="https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83">Getting Started with MetaMask</a></li><li><a href="https://medium.com/openberry/compile-and-deploy-using-remix-ide-f58fcc662ed0">Compile and Deploy Using Remix IDE</a></li><li><a href="https://solidity.readthedocs.io/en/latest/">Introduction to Smart Contracts and Solidity</a></li></ol><h4>Github</h4><p>If you only want to see the code, you can find it here:<br><a href="https://github.com/openberry-ac/Auction">https://github.com/openberry-ac/Auction</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Why Build an Auction Dapp?</h3><p>The auction system is a good application to build for the purpose of learning about smart contracts and decentralized applications, especially for beginners.</p><p>Smart contracts will help you exchange money, properties, shares, or anything of value in a transparent, conflict-free way while avoiding the services of a middleman, like the auction system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Making the Project</h3><h4>Work flow</h4><ol><li>Creating the Smart Contract</li><li>Building web app &amp; Web3.js setting</li><li>Defining the Methods: Frontend Coding</li></ol><h3>Creating the Smart Contract</h3><p>Since our contract will be based on Ethereum, we will use <a href="https://solidity.readthedocs.io/en/latest/">Solidity</a>, a programming language used for creating smart contracts.</p><p>In <a href="https://remix.ethereum.org/">Remix</a>, create a new file named <strong>AuctionBox.sol</strong> and add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a7d6a8e4ad7996843efcef5d7845398/href">https://medium.com/media/6a7d6a8e4ad7996843efcef5d7845398/href</a></iframe><p>In an actual setting, many items can be auctioned. In order to make it easy to access all the auctioned items, we created a bundle or box called “AuctionBox” which includes all the auction addresses!</p><p>To make this system work, we need to prepare two types of contracts, called Auction contract and AuctionBox contract.</p><p>After writing it in Remix, deploy it to the <strong>Ropsten Test Network.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>To verify that our contract was deployed, you should see this in Remix:<br>Here, we need to select <strong>AuctionBox</strong> contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZZdDLn5gbQeReF9EJcVPJQ.png" /></figure><p><strong>Let’s create an auction !</strong></p><p>After deploying, let’s try to make an auction using <strong>createAuction</strong> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uLVtpscofsgf4zqJ1CXdQ.png" /></figure><p>If you success, you can click <strong>returnAllAuctions</strong> and see its contract address!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h3>Building the Web App</h3><p>Our smart contract now works, but there’s no fun in just looking at numbers so we’ll be making a simple web application.</p><h4>Setting Up</h4><p>To speed up things, a template project is provided which can be found here. Now let’s follow the commands below, in your Terminal (or Command Prompt/Powershell for Windows):</p><pre># git clone the project template<br>git clone -b boilerplate --single-branch <a href="https://github.com/openberry-ac/Auction.git">https://github.com/openberry-ac/Auction.git</a></pre><pre># go inside the folder<br>cd Auction</pre><pre># install packages needed in the web application<br>npm install</pre><pre># install web3, this is for connecting the contract <br>npm install -s web3@1.0.0-beta.37</pre><pre># To run the app<br>npm run dev</pre><p>Then it should automatically render on <a href="http://localhost:8080/">http://localhost:8080/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YXgv8M3dhN3gsO8cvkZRSQ.png" /></figure><h4>Setting up web3.js</h4><p>Open the file named <strong>web3.js </strong>in the <strong>contracts</strong> folder, then paste it as following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4eac4aecba4054e478f62c97802d8f54/href">https://medium.com/media/4eac4aecba4054e478f62c97802d8f54/href</a></iframe><p>This basically gets the web3 instance that the Metamask extension initializes, so we can use it in our app too. We need to call this later when retrieving our smart contract instance.</p><p>You might encounter a MetaMask pop-up window in your browser that asks for access permission. You should just click the ‘Connect’ button right here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*joc1FhjwHd8WZYSTeUR2uw.png" /></figure><h4>Connecting to Our Smart Contract Instance</h4><p>Now, we need our smart contract’s ABI and the contract address to connect it to our web app. To get the ABI, go back to <a href="https://remix.ethereum.org/">Remix</a>, go to the <strong>Compile</strong> tab, and click <strong>ABI</strong> beside the Details button as shown in the picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*5v3ExVur6cZtPU79teWzqA.png" /></figure><p>To get the contract address, go to the <strong>Run</strong> tab, and click <strong>Copy</strong> button as shown in the picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3amRrIr3uTKq6JxZNrXRfg.png" /></figure><p>You can also get <strong>Auction</strong> contact’s <strong>ABI</strong> by changing the selected contract to Auction and clicking ABI.</p><p>After getting it, open the files named <strong>AuctionBoxInstance.js </strong>and <strong>AuctionInstance.js</strong> in the <strong>contracts</strong> folder, then paste it as the variable <strong>abi </strong>’s<strong> </strong>value and the contract address, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2668dd52dfc761475e95de36c3c6a83f/href">https://medium.com/media/2668dd52dfc761475e95de36c3c6a83f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01224abdddd1165d82f28d58953ad838/href">https://medium.com/media/01224abdddd1165d82f28d58953ad838/href</a></iframe><h4>Defining the Methods</h4><p>You might notice that the user interface is there, but the buttons aren’t functional. That’s because we have not defined our functions yet, which we will be doing now. Open <strong>App.vue</strong> in the src folder<strong> </strong>and let’s get started to fill in the blanks!</p><p><strong>beforeMount</strong></p><p>Here, we will get the number of auctions that you created before.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00cfefb4c48e82140f8a1f40f5fb605f/href">https://medium.com/media/00cfefb4c48e82140f8a1f40f5fb605f/href</a></iframe><p><strong>Create Auction Function</strong></p><p>Here, we create an auction using the user’s inputs, which will be shown at the bottom of the page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23587821e2c14456e52d348a4b59cba6/href">https://medium.com/media/23587821e2c14456e52d348a4b59cba6/href</a></iframe><p><strong>Place Bid Function</strong></p><p>Here, we handle the event wherein the user places a bid.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abc69b49d7a471e2dd98e6f64f4f4aab/href">https://medium.com/media/abc69b49d7a471e2dd98e6f64f4f4aab/href</a></iframe><p><strong>Finalize Auction Function</strong></p><p>Here, we handle the event wherein the user finalizes an auction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31b445d02d12414c7c1a66c9f68b0259/href">https://medium.com/media/31b445d02d12414c7c1a66c9f68b0259/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>We have already created an auction in Remix, you can see its contract address in console.</p><p>In my case, I created 9 auctions, so I can see this in console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zc523Ip9waBd3oxV7hw1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><p>Complete!!</p><p>Refresh your browser to see the changes. This time, the whole web app is complete, and everything is functional! You should then be able to use it like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-b3ZB_iZt1DdQ8hHBIlHw.gif" /></figure><p>NOTE: The one who made the action cannot place a bid in his own auction. So, you need to switch to another account (other than the auction starter) to place a bid.</p><p>NOTE: To display the auction card, please create another auction in your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Summary</h3><p>You learned how to create a smart contract and how to interact with it using web3.js. You also learned how to setup your own project using Vue.js, and created a simple application.</p><p>So what’s next?</p><p>You might want to add the logic for the “deadline” because it is important in a real auction application. For now, we skipped it to avoid complexity and to lessen the time, but if you want to try to build it, <a href="https://solidity.readthedocs.io/en/v0.5.2/solidity-by-example.html#blind-auction">this will help you a lot</a> :)</p><p>If you want the full code of this tutorial, you can check it here:<br><a href="https://github.com/openberry-ac/Auction">https://github.com/openberry-ac/Auction</a></p><p>On a side note, you might want to check out openberry’s previous tutorial, <strong>“ERC721 + Vue.js CryptoKitties-like Dapp in under 10 minutes”</strong>.</p><p><a href="https://medium.com/openberry/erc721-vue-js-cryptokitties-like-dapp-in-under-10-minutes-5115efc9e0bb">ERC721 + Vue.js CryptoKitties-like Dapp in under 10 minutes</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><p>openberry is a tutorial marketplace, designed to allow anyone to learn blockchain programming.</p><ul><li><a href="https://www.openberry.ac/">openberry | blockchain tutorial marktplace</a></li><li><a href="https://twitter.com/openberry_ac">openberry (@openberry_ac) | Twitter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76ba48156b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/openberry/ethereum-solidity-vue-js-tutorial-simple-auction-dapp-within-10-minutes-76ba48156b2">Ethereum Solidity + Vue.js Tutorial Simple Auction Dapp within 10 minutes.</a> was originally published in <a href="https://medium.com/openberry">openberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ERC721 + Vue.js CryptoKitties-like Dapp in under 10 minutes]]></title>
            <link>https://medium.com/openberry/erc721-vue-js-cryptokitties-like-dapp-in-under-10-minutes-5115efc9e0bb?source=rss----9b65c4aa51d4---4</link>
            <guid isPermaLink="false">https://medium.com/p/5115efc9e0bb</guid>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[erc721]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Sam Benemerito]]></dc:creator>
            <pubDate>Wed, 20 Feb 2019 03:47:49 GMT</pubDate>
            <atom:updated>2019-02-21T06:28:14.531Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*zeWiAynsLbvG3kBVEe7wpw.png" /></figure><p>You might have heard of <a href="https://www.cryptokitties.co/">CryptoKitties</a>, an Ethereum-based platform where you can collect, buy, sell, and even breed digital cats, and about how people have been <a href="https://techcrunch.com/2017/12/03/people-have-spent-over-1m-buying-virtual-cats-on-the-ethereum-blockchain/">spending a crazy amount of money in the game</a>.</p><p>Making a CryptoKitties-like application is actually quite easy! And in this tutorial, we’ll be doing just that.</p><h3>What We Are About To Build</h3><p>From here onwards, we will be building a simple CryptoKitties-like dapp, which we will call CryptoVipers (vipers, because why not?). In our simple application, we will be able to buy vipers, breed vipers, and view the ones we own. Which will be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dMtasuRyKjnlHaJA" /></figure><h4>Function List</h4><ol><li>Viper Creation — we should be able to own new vipers by <strong>buying</strong> one or <strong>breeding</strong> two of them</li><li>View Viper Details — we should be able to retrieve our vipers’ details and <strong>display</strong> it.</li></ol><h4>Tools</h4><ol><li>Smart Contract<br><a href="https://solidity.readthedocs.io/en/latest/">Solidity</a>, <a href="https://remix.ethereum.org/">Remix</a>, <a href="https://metamask.io/">Metamask</a></li><li>Frontend<br><a href="https://web3js.readthedocs.io/en/1.0/">Web3.js</a>, <a href="https://vuejs.org/">Vue.js</a>, <a href="https://cli.vuejs.org/">Vue-cli</a>, <a href="https://bootstrap-vue.js.org/">Boostrap-vue</a></li></ol><p>Aside from that, we will also be using <a href="https://git-scm.com/">Git</a> later to clone our boilerplate :)</p><h4>Prerequisites</h4><p>Before proceeding with this tutorial, you should first read the following articles:</p><ol><li><a href="https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83">Getting Started with MetaMask</a></li><li><a href="https://medium.com/openberry/compile-and-deploy-using-remix-ide-f58fcc662ed0">Compile and Deploy Using Remix IDE</a></li><li><a href="https://solidity.readthedocs.io/en/v0.5.3/introduction-to-smart-contracts.html">Introduction to Smart Contracts and Solidity</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Understanding ERC721</h3><p><strong>ERC721</strong> is a standard that describes how non-fungible (or <strong>unique tokens</strong>) on the <a href="https://ethereum.org/">Ethereum blockchain</a> should be made. With ERC721, each item or token is unique, meaning it is not equal to any other token. You could think of each one as a rare, <strong>one-of-a-kind</strong> <strong>collectible</strong>.</p><h4>ERC721 Interface</h4><p>According to the specifications, ERC721 defines a minimum interface a smart contract must implement to allow unique tokens to be managed, owned, and traded:</p><ul><li><strong>balanceOf( _owner )</strong> — Returns the number of tokens in a specific _owner’s wallet.</li><li><strong>ownerOf( _tokenId )</strong> — Returns the wallet address of the specific token’s owner.</li><li><strong>totalSupply() — </strong>Returns the total amount of tokens created</li><li><strong>transfer( _to, _tokenId ) </strong>— Transfers token with <em>_tokenId</em> from sender’s wallet to a specific wallet.</li><li><strong>takeOwnership( _tokenId )</strong> — Claims the ownership of a given token ID</li><li><strong>approve( _to, _tokenId )</strong> — Approves another address to claim for the ownership of the given token ID</li></ul><p>Also, it defines two events: <strong>Transfer</strong>, and <strong>Approval</strong>. A <em>Transfer</em> event is emitted when a token is transferred from one wallet to another. On the other hand, an <em>Approval </em>event is emitted when an address (user) approves another address to claim the ownership of a certain token that he owns.</p><h4>OpenZeppelin ERC721 Implementation</h4><p><a href="https://github.com/OpenZeppelin/openzeppelin-solidity">OpenZeppelin</a> provides reusable smart contracts with implementations of standards like ERC20 and ERC721. In this case, we will be importing <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol">their ERC721 implementation</a> so we don’t have to write it ourselves from scratch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Making the Project</h3><h4>Workflow</h4><ol><li>Creating the Smart Contract</li><li>Building the Web App</li></ol><h3>Creating the Smart Contract</h3><p>Since our clone will also be based on Ethereum, our token will also be made using <a href="https://solidity.readthedocs.io/en/v0.5.2/index.html">Solidity</a>, one of the programming languages used for creating smart contracts.</p><p>In <a href="https://remix.ethereum.org/">Remix</a>, create a new file named <strong>ViperToken.sol</strong> and add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f327a6e230dfd92e10a5d949f27b449/href">https://medium.com/media/8f327a6e230dfd92e10a5d949f27b449/href</a></iframe><p>We’re basically importing OpenZeppelin’s <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol">ERC721 implementation,</a> and adding our custom functions. We’re also importing <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol">SafeMath</a> to avoid <a href="https://github.com/ConsenSys/smart-contract-best-practices/blob/master/docs/known_attacks.md#integer-overflow-and-underflow">Integer Overflow and Underflow</a>. Now, to explain each function:</p><p>First, the function <strong>generateViperGenes</strong> is responsible for determining the new viper’s genes, especially when it is being created through breeding (getting both parents’ genes). This is a very simple implementation though, and in this case, we use a simple number from 1–6 to determine how the viper will look like. You could do something better if you feel like it :)</p><p>Then, we have the function <strong>createViper</strong> which basically creates a new viper and gives it to the address passed in the parameter, “viperOwner”.</p><p>The function <strong>buyViper</strong> is a <em>payable</em> function (accepts payments) and calls the <strong>createViper</strong> function we previously defined. The word payable is a modifier that is used to indicate that this function can receive ether when you execute it. Now, you might have noticed this part:</p><pre>require(msg.value == 0.02 ether);</pre><p>The <strong>require</strong> statement checks a condition and raises an error when false. In Solidity, msg.value holds the amount of Ether being sent by the one who called the function. In this case, we want the user to pay 0.02 ether for buying a random viper. You may change this amount, or even remove it if you wish to.</p><p>We then have the <strong>breedVipers</strong> function which takes 0.05 ether as payment, and creates a new viper based off the two parents’ genes.</p><p>Next, we have the function <strong>getViperDetails</strong> which just returns details such as genes, and parent IDs of a given viper.</p><p>Finally, we have the <strong>ownedVipers</strong> function which returns a list of viper IDs that the function caller owns. The word msg.sender is the address of the user that executed that function.</p><p>Now, compile the <strong>ViperToken</strong> contract (make sure you select compiler version at the right side of Remix, and choose <strong>0.5.3+commit.10d17f24</strong> because we are using Solidity version 0.5.3) and deploy it to the <strong>Ropsten Test Network</strong>. Make sure you are compiling and deploying the <strong>ViperToken </strong>contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>To check that our contract was deployed, you should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*npLBHcs0ZmP3CA8TQ6Z1cw.png" /><figcaption>The contract was successfully compiled</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*HfvU2UQrLXra_crjgaUJUg.png" /><figcaption>The contract was successfully deployed and is listed in ‘Deployed Contracts’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h3>Building the Web App</h3><p>Our smart contract now works, but there’s no fun in just looking at numbers so we’ll be making a simple web application.</p><h4>Setting Up</h4><p>To get up to speed, let’s clone a boilerplate project (found <a href="https://github.com/openberry-ac/cryptovipers/tree/boilerplate">here</a>) by doing the following in a Terminal (or Command Prompt/Powershell for Windows):</p><pre># Cloning the boilerplate from GitHub<br>git clone -b boilerplate --single-branch <a href="https://github.com/TART-tokyo/cryptovipers.git">https://github.com/openberry-ac/cryptovipers.git</a></pre><pre># Navigating to the directory and installing packages<br>cd cryptovipers<br>npm install</pre><pre># Installing Web3<br>npm install -s web3@1.0.0-beta.37</pre><pre># To run the app<br>npm run dev</pre><p>Voila! In a few minutes, you should see the app running through a browser on <a href="http://localhost:8080/">http://localhost:8080</a> looking like this (though it is not functional yet):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nT6cd_vnTXTV1GKm" /><figcaption>CryptoVipers’ index page</figcaption></figure><h4>Connecting to Our Smart Contract Instance</h4><p>To enable our web app to interact with our smart contract, we will be using <a href="https://github.com/ethereum/web3.js/">web3.js</a>. We already have the package installed, you can see how it is called in the file named <strong>web3.js</strong> inside the “contracts” folder, where we should put something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48f6e4c18985fe59ed4170eb74ccf367/href">https://medium.com/media/48f6e4c18985fe59ed4170eb74ccf367/href</a></iframe><p>It basically loads the web3 instance the MetaMask extension initializes, which we will be needing later to interact with our smart contract.</p><p>You might encounter a MetaMask pop-up window that asks for access permission. This is because we have ethereum.enable() where the app requests for account (or wallet) access. You should just click the ‘Connect’ button right here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*EV4X0zSwPsDPVadQNXavHw.png" /></figure><p>Now, we need our smart contract’s ABI to connect it to our web app. To get the ABI, go back to <a href="https://remix.ethereum.org/">Remix</a>, go to the <strong>Compile</strong> tab, and click <strong>ABI</strong> beside the Details button as shown in the picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/0*1qYsXyyi5-wu41z3" /><figcaption>Copy the ABI using the ABI Button</figcaption></figure><p>After getting it, open the file named <strong>abi.js</strong> in the <strong>contracts</strong> folder, then paste it as the variable <strong>contractAbi </strong>’s<strong> </strong>value, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1656b552d0e35429d2da556cdcfe22f5/href">https://medium.com/media/1656b552d0e35429d2da556cdcfe22f5/href</a></iframe><p>There should be an example in the file, which you can always refer to. Then, we will have to specify the smart contract’s instance address too, which you can get by going to <a href="https://remix.ethereum.org/">Remix</a>’s Deploy tab, and clicking the copy icon on your deployed contract, as shown in this picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*SXjgoREW4T24DHAO" /><figcaption>Copy the Instance address using the Copy Button</figcaption></figure><p>Open <strong>App.vue</strong> found inside the <strong>src</strong> folder, and paste your contract address on line 86 as the variable <strong>contractAddress</strong>’ value (there should also be comments in the file, which you can always refer to):</p><pre>const contractAddress = &#39;&#39;; // Right here!<br>// Ex: const contractAddress = &#39;0xf59c4c3c79071d3e11034a9344789bd3&#39;;</pre><h4>Defining the Methods</h4><p>You might notice that the user interface is there, but the buttons aren’t functional. That’s because we have not defined our functions yet, which we will be doing now. Go back to <strong>App.vue</strong>, and go to line 116 where you can see <strong>methods</strong>, but everything just contains a <em>console.log()</em>.</p><p>Our first function is for buying a viper. Let’s modify the <em>buyViper()</em> function to look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae6ea20443d6beeb50b3e39fd3a1a994/href">https://medium.com/media/ae6ea20443d6beeb50b3e39fd3a1a994/href</a></iframe><p>For buying a single viper, we have a fee of <strong>0.02 ether</strong>, so we need to pay it by sending our account details and 0.02 ether. We then call the <em>buyViper() </em>function from our smart contract, which returns the details of the new viper. We will save these details inside the vipers array.</p><p>Next, we modify the function for viper breeding, <em>breedVipers()</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71de66aa33c3e9155ec34f19b7d68270/href">https://medium.com/media/71de66aa33c3e9155ec34f19b7d68270/href</a></iframe><p>We need to pay <strong>0.05 ether</strong> to access this function. The <em>breedVipers()</em> function in our smart contract requires two integer parameters, <em>matron</em> and <em>sire</em>, so we pass the two integers to the function. This function also returns the details of the new viper and we need to save it to the vipers array.</p><p>Finally, we define the method for retrieving the details of vipers we own, called <em>getVipers()</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f88bc94a81401eddb9340d7fcd459bb4/href">https://medium.com/media/f88bc94a81401eddb9340d7fcd459bb4/href</a></iframe><p>There are two functions to get the details, <em>ownedVipers()</em> and <em>getViperDetails()</em>. The first function is to get an array of our vipers then the second function is to get the details of each of the vipers. After getting the details of each viper, we save it to the vipers array.</p><p>And, we’re done!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>Refresh your browser to see the changes. This time, the whole web app is complete, and everything is functional! You should then be able to use it like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dMtasuRyKjnlHaJA" /><figcaption>CryptoVipers’ sample usage. You did it!</figcaption></figure><p>You can see the final result on this <a href="https://github.com/openberry-ac/cryptovipers">GitHub repository</a> (master branch) which you can always refer to :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h3>Conclusion</h3><p>We just finished making our simple Cryptokitties clone! Awesome!</p><p>We learned how to create our own ERC721 implementation, and define our own custom functions. We also learned how to set up our own project using Vue.js, and created a simple application.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FoBPOP48aQpIxq%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FoBPOP48aQpIxq%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FoBPOP48aQpIxq%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="278" frameborder="0" scrolling="no"><a href="https://medium.com/media/897a0421502a8f436e79b65bea3ba100/href">https://medium.com/media/897a0421502a8f436e79b65bea3ba100/href</a></iframe><p>So what’s next?</p><p>You might want to write the token code (ERC721 implementation) from scratch while referencing to <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol">OpenZeppelin’s implementation</a> or the <a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md">standard specification</a>. Or perhaps, you’d like to expand from what we have done and add more features like trading with other users, which is a good idea too 👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*n62aOwPOokWobQTJZojIPQ.png" /></figure><p>On a side note, you might want to check out openberry’s previous tutorial, <a href="https://medium.com/openberry/https-medium-com-creating-an-instagram-like-dapp-with-ipfs-cc4fac85cbfe">creating an Instagram-like DApp with IPFS + Vue.js</a>.</p><p>’til the next tutorial!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><p>openberry is a tutorial marketplace, designed to allow anyone to learn blockchain programming.</p><ul><li><a href="https://www.openberry.ac/">openberry | blockchain tutorial marktplace</a></li><li><a href="https://twitter.com/openberry_ac">openberry (@openberry_ac) | Twitter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5115efc9e0bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/openberry/erc721-vue-js-cryptokitties-like-dapp-in-under-10-minutes-5115efc9e0bb">ERC721 + Vue.js CryptoKitties-like Dapp in under 10 minutes</a> was originally published in <a href="https://medium.com/openberry">openberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compile and Deploy Using Remix IDE]]></title>
            <link>https://medium.com/openberry/compile-and-deploy-using-remix-ide-f58fcc662ed0?source=rss----9b65c4aa51d4---4</link>
            <guid isPermaLink="false">https://medium.com/p/f58fcc662ed0</guid>
            <category><![CDATA[remix]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ide]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Vince Millora]]></dc:creator>
            <pubDate>Wed, 13 Feb 2019 03:08:53 GMT</pubDate>
            <atom:updated>2019-02-14T02:29:53.162Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mkTfH_SzupDN-sNAiAZn2g.png" /></figure><p><a href="https://remix.ethereum.org/">Remix IDE</a> (<em>Integrated Development Environment</em>) is a web application that can be used to <em>write</em>, <em>debug</em>, and <em>deploy</em> <strong>Ethereum</strong> <strong>Smart Contracts</strong>. When you want to write Smart Contracts, you can use this application.</p><p>Using Remix IDE is actually quite easy! In this tutorial, we’ll learn how to use it.</p><h3>What We Are Trying To Do</h3><p>From here onwards, we will study each part of the <a href="https://remix.ethereum.org/">Remix IDE</a>. We will write a simple Smart Contract, compile, then deploy it using <a href="https://metamask.io/">Metamask</a> <strong>Ropsten Test Network</strong>. Don’t worry, we will guide you as you write your Smart Contract.</p><h4>Function List</h4><ol><li>Setting a Greeting — we should be able to <strong>set </strong>a greeting.</li><li>Displaying the Greeting — we should be able to retrieve the greeting and <strong>display</strong> it.</li></ol><h4>Tools</h4><ol><li>Smart Contract<br><a href="https://solidity.readthedocs.io/en/v0.5.3/">Solidity</a>, <a href="https://remix.ethereum.org/">Remix</a>, <a href="https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83">Metamask</a></li></ol><h4>Prerequisites</h4><p>Before proceeding with this tutorial, you should first read the following articles:</p><ol><li>How to Use <a href="https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83">Metamask</a></li><li>Basic <a href="https://solidity.readthedocs.io/en/v0.5.3/">Solidity</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Studying Remix IDE</h3><h4>Work Flow</h4><ol><li>Creating the Smart Contract</li><li>Compiling and Deploying the Smart Contract</li></ol><h3>Creating the Smart Contract</h3><p>Since we really don’t need a complex Smart Contract, we’ll just make one for setting a greeting and displaying it. Our Smart Contract will be made using <a href="https://solidity.readthedocs.io/en/v0.5.3/">Solidity</a>.</p><p>In <a href="https://remix.ethereum.org/">Remix</a>, create a new file named <strong>TestContract.sol</strong>. To create a file, click the <strong>Create New File </strong>button at the top left corner of the page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*Gx0kaIK8K3XlQ77hZFL7ZA.png" /><figcaption>Create a new file using the Create New File button.</figcaption></figure><p>After clicking the button, a window will appear. This will ask the filename of the new contract. Just input <em>TestContract.sol </em>like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*xn54YIN_7-A3J8bgp35U2w.png" /></figure><p>After the file is created, add the following code to the code editor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/183dc5c5f730caf21710d4a371c74da1/href">https://medium.com/media/183dc5c5f730caf21710d4a371c74da1/href</a></iframe><p>We’ve just basically defined two functions, <em>setGreeting(), greet()</em>, for setting a greeting and displaying it.</p><h3>Compiling and Deploying Contracts</h3><p>After writing the Smart Contract, we should compile the code to check if there are <strong>errors</strong> or <strong>warnings</strong>. If there are no any errors, the Smart Contract is ready to be deployed.</p><h4>Compiling a Contract</h4><p>To compile a Smart Contract, go to the <em>Compile Tab </em>and select the <strong>compiler version </strong>and select the appropriate version that is suitable to your <strong>Solidity version </strong>(in our tutorial, we will use <em>0.5.3+commit.10d17f24 </em>since we used <em>Solidity 0.5.3). </em>You can refer to the screenshot below to find the tab and the settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*DNIgYs2Dx3-3Pcdb5BnXQQ.png" /></figure><p>After settings the options, click the <em>Start to compile </em>button, a success <strong>message</strong> or a list of <strong>errors</strong> will show below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*pFDJPQ4PPYLN0CanJ3ViHA.png" /></figure><p>If there are no errors, a box with a green color, then the Smart Contract is successfully compiled. You can now deploy the code or get the <a href="https://solidity.readthedocs.io/en/v0.5.3/abi-spec.html"><strong>ABI</strong></a>. The ABI is basically a specification in the form of a JSON, that describes the contract. This is very important when you want to deploy your contract to your applications.</p><h4>Deploying a Contract</h4><p>After successfully compiling your contract, you can now deploy it. Deploying a contract will let you test it and use it to your applications. Go to the <em>Run Tab</em> located at the side of the <em>Compile Tab</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*p9NBKffSSp1QHNkRCN5RSA.png" /></figure><p>Set the <strong>options</strong> first at the top part of the tab. Here are what you need to know about the options before you run a contract:</p><ul><li>JavaScript VM - The instance will be deployed in a <em>sandbox blockchain</em> in the browser. This means nothing will be saved when the page reloads, a new instance will be created.</li><li>Injected Provider - Remix will connect to an <em>injected web3 provider</em>. Metamask and Mist are example of injected web3 providers.</li><li>Web3 Provider - Remix will connect to a <em>remote instance</em>. You will need to provide the URL address of your selected provider.</li><li>Account - the list of accounts that will be associated with the current instance.</li><li>Gas Limit - the maximum gas amount of each transaction.</li><li>Value - the amount of value for the next created transaction.</li></ul><p>Since we will use the <a href="https://metamask.io/">Metamask</a> to deploy our contract, we will select the Injected Provider for the <em>Environment</em> and leave the other options to default. Then click the <em>Deploy </em>button to deploy the contract. A <a href="https://metamask.io/">Metamask</a> window will appear and you will need to confirm to deploy the contract:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*DVsemWPcFj8P-Hk52tBxcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>After the contract is deployed, the <em>instance</em> will show up at the bottom of the tab and you will be able to access the functions. In this example, we set the greeting to <em>New Hello!!</em> and then displayed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BW8RhoC9f6NFeUzbJvxSeQ.png" /></figure><p>After testing, you can also copy the Smart Contract’s <strong>instance address </strong>using the <em>copy</em> button beside the address. This address basically tells where your contract is running. Along with the ABI, these two are the required contract information that will be used to connect the contract to your applications.</p><p>And we’re done. We’ve created a Smart Contract, compiled it, then deployed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h3>Conclusion</h3><p>Now, you know how to use the Remix IDE. You can now write Smart Contracts in Remix, compile it, and deploy.</p><p>Remix is very helpful when you are just starting to learn programming in Ethereum. Every basic thing you need to deploy your Smart Contract can be found in the IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*zpeSd24LATR2pWvd" /></figure><p>So what’s next?</p><p>You can now study more about Ethereum and practice coding using the Remix IDE. You can also study <a href="https://web3js.readthedocs.io/en/1.0/">Web3.js</a>, a tool to connect the <strong>Smart Contract Instance</strong> to your <strong>Web application</strong>. OR, you can practice developing Dapps by viewing openberry’s other tutorials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><p>openberry is a tutorial marketplace, designed to allow anyone to learn blockchain programming.</p><ul><li><a href="https://www.openberry.ac/">openberry | blockchain tutorial marktplace</a></li><li><a href="https://twitter.com/openberry_ac">openberry (@openberry_ac) | Twitter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f58fcc662ed0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/openberry/compile-and-deploy-using-remix-ide-f58fcc662ed0">Compile and Deploy Using Remix IDE</a> was originally published in <a href="https://medium.com/openberry">openberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an Instagram-like DApp with IPFS + Vue.js]]></title>
            <link>https://medium.com/openberry/https-medium-com-creating-an-instagram-like-dapp-with-ipfs-cc4fac85cbfe?source=rss----9b65c4aa51d4---4</link>
            <guid isPermaLink="false">https://medium.com/p/cc4fac85cbfe</guid>
            <category><![CDATA[metamask]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[ipfs]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Gwen Danielle Merida]]></dc:creator>
            <pubDate>Wed, 13 Feb 2019 03:08:26 GMT</pubDate>
            <atom:updated>2019-02-20T04:29:55.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*n62aOwPOokWobQTJZojIPQ.png" /></figure><p>Instagram is a social platform where you can share your photos and videos to all the people you are connected to.</p><p>Now, imagine creating your own social platform like Instagram. An Instagram-like DApp that is running on top of Blockchain technology.</p><h3>What We Are Trying To Build</h3><p>In this tutorial, we will be building an Instagram-like platform integrated with both technologies, InterPlanetary File System <a href="https://docs.ipfs.io/"><strong>IPFS</strong></a> and <a href="http://www.ethdocs.org/en/latest/"><strong>Ethereum</strong></a> blockchain. These two have been tightly coupled for some time now because of their similar nature, it decentralizes the data. And with that, when making a decentralized app, they synergize pretty well. You will understand this later on, as you read along the tutorial.</p><p>Also, we will be using <a href="https://vuejs.org/v2/guide/">Vue.js</a> for the application’s front-end. We won’t be discussing much about this tool since I don’t want you to get the idea that it should just be Vue.js, there are many available front-end languages that you can use for creating this app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j14q7hfbX8JY9GmNsVC-qw.gif" /></figure><h4>Function List</h4><ol><li>Upload data (POST image in IPFS)</li><li>Retrieve data (GET image from IPFS)</li></ol><h4>Tools</h4><ol><li>Smart Contract<br><a href="https://solidity.readthedocs.io/en/latest/">Solidity</a>, <a href="https://remix.ethereum.org/">Remix</a>, <a href="https://metamask.io/">Metamask</a></li><li>Frontend<br><a href="https://web3js.readthedocs.io/en/1.0/web3-eth.html">Web3.js</a>, <a href="https://github.com/ipfs/js-ipfs-http-client">ipfs-http-client</a><br><a href="https://vuejs.org/">Vue.js</a>, <a href="https://cli.vuejs.org/">Vue-cli</a>, <a href="https://bootstrap-vue.js.org/">Boostrap-vue</a></li></ol><h4>Content should be read in advance</h4><ol><li>How to deploy in <a href="https://medium.com/openberry/compile-and-deploy-using-remix-ide-f58fcc662ed0">Remix</a> and use <a href="https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83">Metamask</a></li><li><a href="https://solidity.readthedocs.io/en/v0.5.3/">Basic Solidity</a></li></ol><h4>Github</h4><p>If you just want to get the code you can get it here: <br><a href="https://github.com/openberry-ac/instagram">https://github.com/openberry-ac/instagram</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Why IPFS?</h3><p>In basic terms, InterPlanetary File System is a peer-to-peer storing and sharing file system. Using IPFS, you can upload files such as text, images and even videos.</p><p>In centralized storages, you can only get data from their servers, and the speed of that transfer depends on the distance between you and that server. But unlike a peer-to-peer storage such as IPFS, you can get the data from anyone who has the exact data you need, so the transfer is a lot faster.</p><p>IPFS uses content-addressable hashes to verify that the data you’re getting is right, since all data has their own unique hash value.</p><pre># An example of a file&#39;s unique hash ID:<br>Qmf7bwqcd4BD7ohtkCBQvHu1BGMc8wMSP2nrLxsTBLDP4t</pre><p>So when you upload a file in IPFS, you will get the data’s unique hash ID as return, then you can retrieve it by using the same hash through a gateway , it’s that simple.</p><pre># Gateway: https://ipfs.io/ipfs/<br># Retrieve: Gateway + Unique Hash ID<br>https://ipfs.io/ipfs/ + Qmf7bwqcd4BD7ohtkCBQvHu1BGMc8wMSP2nrLxsTBLDP4t</pre><p>Try this one out!<br><a href="https://ipfs.io/ipfs/Qmf7bwqcd4BD7ohtkCBQvHu1BGMc8wMSP2nrLxsTBLDP4t">https://ipfs.io/ipfs/Qmf7bwqcd4BD7ohtkCBQvHu1BGMc8wMSP2nrLxsTBLDP4t</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Build the Project!</h3><h4>Workflow</h4><ul><li>Writing our Smart Contract</li><li>Setting Web3.js, Contract Instance and IPFS</li><li>Getting Users Account</li><li>Posting data in IPFS</li><li>Fetching data from IPFS</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Writing our Smart Contract</h3><p>In creating this contract, we will be using Solidity.</p><blockquote>Solidity is an object-oriented, high-level language for implementing smart contracts.<br><em>https://solidity.readthedocs.io/en/v0.5.3/</em></blockquote><p>Here are the function that will be in our contract:</p><ul><li><strong>sendHash(_imgHash, _textHash) </strong>— sends the image and text hashes and stores it.</li><li><strong>getCounter() </strong>— gets the total number of posts that are already stored.</li><li><strong>getHash(_index) </strong>— gets the image and text hashes using an index number.</li></ul><p>We will name our contract, <strong>InstagramPosting.sol</strong>, and use the current latest and stable version of Solidity, version 0.5.3. Also, we imported <strong>SafeMath </strong>library for safe math operations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b9629024d2c89968c2eb2576539a551/href">https://medium.com/media/9b9629024d2c89968c2eb2576539a551/href</a></iframe><p>In this snippet of code, we created a struct, named <strong>Post</strong>. This holds the data: <strong>owner</strong>, <strong>imgHash</strong> and <strong>textHash</strong>, that will be used to store the post’s data.</p><ul><li><strong>owner(address) </strong>— the address of the post’s owner.</li><li><strong>imgHash(string) </strong>— the hashes of images stored in IPFS.</li><li><strong>textHash(string) </strong>— the hashes of image’s captions stored in IPFS.</li></ul><p>Then, we declared a public mapping for Post. We created a mapping named <strong>posts</strong>, to list and store the data, with uint256 as its key reference. Lastly, we created a uint256, named <strong>postCtr</strong>, to traverse inside the posts mapping.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/426e9b2a91492c3d44faf519af82a583/href">https://medium.com/media/426e9b2a91492c3d44faf519af82a583/href</a></iframe><p>Next, is the <strong>sendHash</strong> function, this is where the image and text hashes retrieved from an IPFS upload are sent (As seen on parameters <strong>_img</strong> and <strong>_text</strong>) and stored. Before storing, first increment the <strong>postCtr</strong> variable by 1 using <strong>SafeMath’s add()</strong> function to avoid overflow, and set it as the new index reference of the post. After that, the msg.sender which refers to the address of the sender is stored as the owner of the post, followed by storing the two hashes in <strong>imgHash</strong> and <strong>textHash</strong>.</p><p>At the last part, we see the emit <strong>NewPost(),</strong> this refers to the event above the function. It is an event watcher that notifies the web application if the sendHash() function transaction is finished.</p><p>Send function is done, now let’s create a function that retrieves it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf3a760faf0cc98f53e5cf914c98ce75/href">https://medium.com/media/cf3a760faf0cc98f53e5cf914c98ce75/href</a></iframe><p>As you would notice, the <strong>getCounter()</strong> plays a role in getting a hash, since it returns the number of total posts based on the <strong>postCtr</strong> variable.</p><p>For the <strong>getHash() </strong>function, by simply choosing an index number (As seen on <strong>_index</strong> parameter) within the range of the returned value from <strong>getCounter()</strong>, we can traverse inside and get our desired post. The return data are, <strong>img</strong>, <strong>text</strong>, and <strong>owner</strong>, and each are populated by the posts mapping with the chosen index.</p><p><strong>InstagramPosting.sol</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf2264747286085c6500b9cb0dab9ab2/href">https://medium.com/media/cf2264747286085c6500b9cb0dab9ab2/href</a></iframe><h3>Setting Web3.js, Contract Instance and IPFS</h3><p>For this tutorial, a template project with frontend is provided which you can use while following this tutorial. you can clone the project:</p><pre># git clone the project template<br>git clone -b boilerplate --single-branch <a href="https://github.com/openberry-ac/instagram.git">https://github.com/openberry-ac/instagram.git</a></pre><pre>#go to folder<br>cd instagram</pre><pre># install packages needed in the web application<br>npm install</pre><p>Using the template provided, on the root folder, let’s install the packages (web3 and ipfs-http-client):</p><pre># install web3 <br>npm install -s web3@1.0.0-beta.37</pre><pre># install ipfs-http-client<br>npm install -s ipfs-http-client</pre><pre># run web application<br>npm run dev</pre><p>When you run the app, the page should looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*AWoB4OfoDWHYmsceXr60RA.png" /></figure><p>Now let’s go in, <strong>web3.js, </strong>inside the <strong>contract</strong> folder<strong>. </strong>Here is where we will setup and initialize our web3, by importing the web3<strong> </strong>package, named <strong>Web3</strong> and then declare a constant variable named, <strong>web3 </strong>and instantiate <strong>Web3 </strong>on it.</p><p>The code should look like this:</p><p><strong>web3.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfabd482d5c2ea2acf510add35ab7fd1/href">https://medium.com/media/dfabd482d5c2ea2acf510add35ab7fd1/href</a></iframe><p>We have successfully created web3.js. Now go back to your browser and refresh the page, you must be redirected on connection request in metamask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*xKBxS22FAIrfRAR3XsgnJw.png" /></figure><p>Click <strong>CONNECT, </strong>and your contract is now connected to the Ethereum Network.</p><p>Then in <strong>contractInstance.js, </strong>which is also in <strong>contract</strong> folder, we will create an instance of our contract using the <strong>ABI </strong>and declare the <strong>contract address</strong>.</p><p>To connect the smart contract on Ethereum, ABI and its contract address are needed.</p><p>Then back on Remix, under the Run tab, in the list of deployed contract click the copy button beside the desired contract, to get the <strong>contract address</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/0*O8gC00qJjo1BlSxs.PNG" /></figure><p>Then, on <strong>contractInstance.js</strong>, declare it also on a constant variable named, <strong>address</strong></p><p>Back to Remix again, move to compile tab and copy <strong>ABI</strong> by clicking the button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/0*Bdvp_3mw_bHX3yjz.PNG" /></figure><p>Now paste it in our <strong>contractInstance.js</strong>, by declaring it on a constant variable named, <strong>abi.</strong></p><p><strong>contractInstance.js </strong>should look like this, with your copied address and abi.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a1d6a309c73bb02971b2ee065f41a2b/href">https://medium.com/media/5a1d6a309c73bb02971b2ee065f41a2b/href</a></iframe><p>Now you can connect to the contract.</p><p>Now to connect to IPFS, go to ipfs.js which is also in <strong>contract</strong> folder, then import ipfs-http-client and name it <strong>IPFS</strong>. Then instantiate <strong>IPFS</strong> in a constant variable, <strong>ipfs</strong>, to connect to infura’s gateway. We will be using infura’s gateway, to post and get data in IPFS.</p><p><strong>ipfs.js</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b1d8d665553e6335f5834a2c5733543/href">https://medium.com/media/6b1d8d665553e6335f5834a2c5733543/href</a></iframe><p>Now that we are done in instantiating IPFS, We have to declare contract in main.js, so we could call the functions in our smart contract.</p><p><strong>main.js</strong></p><p>We need to declare the contract instance that was already imported above, so add <strong>contract</strong> in <strong>data</strong> to declare the contract instance. With it, we can call methods from our deployed smart contract.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e4d85c9d2829846a5937a7e8f824404/href">https://medium.com/media/9e4d85c9d2829846a5937a7e8f824404/href</a></iframe><p>Finally, we are done setting up web3, contract and IPFS. It’s now time to learn how to post and get data in IPFS.</p><h3>Posting data in IPFS</h3><p>First, we will teach you how to post the data in IPFS. But, before we can do that, first we have to get and set the user’s wallet address. In <strong>main.js</strong>, inside <strong>methods </strong>we will create an async function called, <strong>updateAccount()</strong>, to get the current account being used in metamask.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5eb5a865f29e5b8902681e41b9e523d9/href">https://medium.com/media/5eb5a865f29e5b8902681e41b9e523d9/href</a></iframe><p>Now let’s learn how we can upload post in the Ethereum Blockchain and IPFS. First, let’s open the <strong>App.vue </strong>which can be seen inside <strong>src</strong> folder.</p><p>We will only be working inside the script tag, now under <strong>methods</strong>, is the empty async function <strong>onSubmit(), </strong>which is being called in the <strong>handleOk()</strong> function, which checks if the input is not empty. <strong>onSubmit()</strong> function, sends file to IPFS and the hashes retrieved are sent to our contract.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/332f48dfe58214f3a59d0821231c0b6e/href">https://medium.com/media/332f48dfe58214f3a59d0821231c0b6e/href</a></iframe><p>We also need a function that will handle the choosing of file and converts it to buffer and a function that will return the converted file to buffer. This can be done in <strong>captureFile().</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ee8201b24121c00392543ebe9ada1dd/href">https://medium.com/media/0ee8201b24121c00392543ebe9ada1dd/href</a></iframe><p>and to make the code cleaner we have created <strong>convertToBuffer() </strong>function for the conversion of file to buffer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eace7f651427046c51cc2c02397edf09/href">https://medium.com/media/eace7f651427046c51cc2c02397edf09/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>Ok let’s have a checkpoint on what we have done so far. This part of the tutorial is about uploading image in the IPFS. So let’s try to upload and check if it is really stored in the IPFS.</p><p>But before uploading, let’s add a console log to check the hashed of the image to be uploaded in the IPFS. On <strong>onSubmit()</strong> function, let’s add the logger after we get the image hash from ipfs and before we return the value. This part of the code, should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1abec32eff0df7a10335ee70373ac409/href">https://medium.com/media/1abec32eff0df7a10335ee70373ac409/href</a></iframe><p><em>Note: you can delete the console.log() after this checkpoint.</em></p><p>Now upload image in our page and check “imgHash” in the browser’s console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t1dG2b62lfacnRx4T6WDIQ.png" /></figure><p>As I mentioned above, use this url to check if the image was uploaded in IPFS:</p><p><a href="https://ipfs.io/ipfs/Qmf7bwqcd4BD7ohtkCBQvHu1BGMc8wMSP2nrLxsTBLDP4t">https://ipfs.io/ipfs/</a> + imgHash</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h3>Fetching data from IPFS</h3><p>We don’t want to always check our uploaded image in <a href="https://ipfs.io/ipfs/Qmf7bwqcd4BD7ohtkCBQvHu1BGMc8wMSP2nrLxsTBLDP4t">https://ipfs.io/ipfs/</a>, We want to show it in our page. To do that, in <strong>main.js </strong>file, in async function <strong>getPosts(), </strong>we need to get the images in IPFS and here is how we do it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4611d9d15eec5eda11cc476cad32e5a/href">https://medium.com/media/c4611d9d15eec5eda11cc476cad32e5a/href</a></iframe><p>Alright! we are done with everything. This should be the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j14q7hfbX8JY9GmNsVC-qw.gif" /></figure><p>If you want the full code of this tutorial, you can check it here: <a href="https://github.com/openberry-ac/instagram">https://github.com/openberry-ac/instagram</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Summary</h3><p>You just made your very own Instagram web application integrated with IPFS and Ethereum! You did great for getting this far, you can totally show this off to your developer friends!</p><p>From this tutorial you learned how to send and retrieve files from IPFS, and how to establish connection with it. Also you have learned how to interact with your smart contract by connecting to Web3. Man, you have come a long way, and you owned it!</p><p><em>Me being proud right now:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*iOUHqE-LuOQ9RUPh" /></figure><p>For your next step you might want to explore more about <a href="https://docs.ipfs.io/">IPFS</a> and <a href="https://solidity.readthedocs.io/en/v0.5.3/">Solidity</a>. There’s so much more that you can learn and can do from this technologies, so go ahead and click the links I gave just now!</p><p>You can also add more features to this project you created and deploy your very own live Instagram-like decentralized application, your call!</p><p>Well then, see you on the next tutorial!</p><p>If you get interested in the following topics:</p><ul><li>state management</li><li>page routing</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*BadkrhD_n76G-mknWJ1-Ng.gif" /></figure><p>let us know by giving a clap.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><p>openberry is a tutorial marketplace, designed to allow anyone to learn blockchain programming.</p><ul><li><a href="https://www.openberry.ac/">openberry | blockchain tutorial marktplace</a></li><li><a href="https://twitter.com/openberry_ac">openberry (@openberry_ac) | Twitter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc4fac85cbfe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/openberry/https-medium-com-creating-an-instagram-like-dapp-with-ipfs-cc4fac85cbfe">Creating an Instagram-like DApp with IPFS + Vue.js</a> was originally published in <a href="https://medium.com/openberry">openberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Metamask!]]></title>
            <link>https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83?source=rss----9b65c4aa51d4---4</link>
            <guid isPermaLink="false">https://medium.com/p/b9ac23a10c83</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[metamask]]></category>
            <category><![CDATA[ipfs]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Markus Viola]]></dc:creator>
            <pubDate>Wed, 13 Feb 2019 02:59:24 GMT</pubDate>
            <atom:updated>2019-02-20T04:34:38.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4iGjv8hglh_R2572-XZVQ.png" /></figure><p>In this tutorial, we’ll be discussing about an essential technology that correlates with the core operation of Ethereum: <strong>transactions</strong>. Whenever you have to make transactions, you will and will always have to go through that fox dude above.</p><h3>What’s the good news…</h3><p>It’s a great that you’re here, because I’m gonna discuss about the basic stuffs on how Metamask works, just enough for you to get started on your dApp developments.</p><h3>Understanding Metamask</h3><blockquote><a href="https://metamask.io/"><em>Metamask is a bridge that allows you to visit the distributed web of tomorrow in your browser today. It allows you to run Ethereum DApps right in your browser without running a full Ethereum node.</em></a></blockquote><p>Basically, when you do transactions on the blockchain network, these uses computing power which what we call, <em>gas cost</em>. And much like gas in real life, you have to pay for it. So in order for you to pay that <em>gas cost</em>, you will need a wallet that handles your money, and that’s where Metamask comes in.</p><p>Well, I guess that’s enough information about Metamask for now, we don’t have to dive in to every side of the box, I bet you get the gist of its purpose already. So without further ado, let’s jump right into the first question!</p><h3>How can I install it?</h3><p>Before you could actually install Metamask, you have to know that Metamask only supports a couple of browsers. Metamask supports the following browsers:</p><ul><li><strong>Google Chrome</strong> (or any Chromium browsers, <em>Brave</em>, a DApp Chromium browser.)</li><li><strong>Mozilla Firefox</strong></li><li><strong>Opera</strong></li></ul><p>If you already have any of the above, you can proceed, otherwise, you should download at least one that is listed browsers and you’re good to go!</p><p>So, for you to download Metamask, you should first go to this website:</p><p>Metamask: <a href="https://metamask.io/">https://metamask.io/</a></p><p>You can also download Metamask on your browser’s plugin extension web store, but if you want to be directed automatically to the download page dedicated for your browser, this is the way to go.</p><p>Once you’re inside, you should see Metamask’s iconic fox head following your mouse direction. Under it, you should see the <strong>GET CHROME EXTENSION</strong> orange button, click that, and you’ll be automatically directed to your browser’s store.</p><p>For Google Chrome browser’s example, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mbOcSUi1L8FzVOhu.png" /></figure><p>Now after getting in, just add the plugin extension, and it will install itself on the browser after downloading. (in Chrome’s case, click the <em>Add to Chrome</em> button.)</p><p>Once it is installed, a new tab will suddenly pop up, it’s the Metamask wallet’s welcome page. But you’ll get the same interface on the actual wallet so just close it. Once closed, go and click here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/0*3CeTtHYbVcdeZQu-.png" /></figure><p>If you click that icon, you should trigger the Metamask wallet’s user interface. This is how the wallet looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*2xryJXLw5Vq8fhlp.png" /></figure><p>Now just click continue, and you’ll be directed to creating your own password. Don’t go <strong>import seed</strong> since you don’t have an existing account yet. You will use that if you want to recover your account which will be tackled as well later on.</p><p>After creating and confirming your password, you’ll go through some terms and agreements, then you’ll be given a <strong>secret backup phrase</strong>. That phrase is the heart of your account since it is derived from a unique hash created when you made created the account just now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*wD7JLtMJrBW4DNTM.png" /></figure><p>As said, you shouldn’t compromise the phrase to anyone, because if you’re wallet has cryptocurrencies inside then that can be transferred to someone else. Although Metamask is a wallet made for developers, you still have to exercise secrecy.</p><p>(The account I have shown is for demonstration purposes so it’s totally fine.)</p><p>After saving the phase, you will need to confirm it next. Then it will ask you if you want to deposit, skip, and close that for now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*kh_JBVGkURgoRgDm.png" /></figure><p>Finally, you’re done! You have successfully installed Metamask, and made you’re very own wallet. Yeah, we did install Metamask, but what is the catch about <em>that</em> wallet, what is it capable of. This leads us to the next point:</p><h3>What can it do?</h3><p>For the features of Metamask, there’s actually a lot that you can do, but I’m not gonna cover everything since my focus is to teach you just enough to get you ready for developing your Ethereum decentralized applications.</p><p>Here are the basic features of Metamask that you will need:</p><ul><li><strong>Add/Importing accounts</strong></li><li><strong>Switching accounts</strong></li><li><strong>Switch networks</strong></li><li><strong>Request tokens</strong> (Testnet Faucet)</li><li><strong>Sending tokens</strong> (Cryptocurrency)</li><li><strong>Add/Search token</strong></li><li><strong>Get backup seed</strong></li></ul><p>Alright, so that’s all the things that you will learn about in this tutorial. Let’s now head to the next question:</p><h3>How do I use it?</h3><p>To track our progress easier, let’s just learn all those listed features from top to bottom. But before that, I’m just gonna show you a few helpful things:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*eJTTccEBHCWPA6m9.png" /></figure><p>Let’s try to look at the highlighted portion on the top side.</p><p>Below the name of the account: <em>Account 1</em>, you can see random-looking character string, something that looks like this, <strong>0x557e…4c12</strong>. That is your account’s wallet address, if you click it, the address will be copied on your clipboard.</p><p>This is very helpful since you’ll be using your account a lot on your smart contract development and on your dApps as a test account.</p><p>Next is the one below, that is your transaction history. There, you will see the state of your transactions whether or not it is finished, pending or the transaction had failed, etc.</p><p>Also, if you want to switch the value from Fiat to ETH you can do that by going to the top right highlighted button, as shown here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*aw7MIPPXnifEtwWg.png" /></figure><p>When clicked, a window will show up under it. From there, you can see from the bottom most part, which is the <strong>Settings</strong> button with the gear icon. Hit that button and it should this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/0*2rJch1S4x0t7ox6V.png" /></figure><p>You’ll be taken to this interface, initally on the <em>Settings</em> tab. Without scrolling, you’ll be able to see the <em>Primary Currency</em> section, from the <em>Fiat</em> radio button, switch it to *ETH, and that’s it. If you go back to your Main interface by hitting the fox head button, it should change by now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/0*xgcRiDI7iGic8gxc.png" /></figure><p>So, too much for that, now let’s head on to the first topic.</p><h3>Add/Importing accounts</h3><p>For this feature, this lets you add more than one wallet. This can be useful both in development and in real life. Since you’ll be making applications, you will need to test not only one account, you have to get your accounts interact with each other on a smart contract, makes sense right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*5Jsd8Kyaos4KJH7H.png" /></figure><h4>Adding accounts</h4><p>From main, for you to add an account, just go to the highlighted top right button and click it. This will prompt a new window, showing a list of items.</p><p>On the top side of that window, it shows the list of accounts that you currently have. As of now, you only have one account which is <em>Account 1</em>.</p><p>To add another, just click the first option below it: <strong>+ Create Account</strong>. When clicked, you’ll be directed to a very self explanatory interface, which contains an input for the <strong>name your account</strong> and the button <strong>Create</strong>, hit it.</p><p>When you go back, alas, you have your new account! It also has its own unique address, which is nice. You can make as much as you want. (I think? Haven’t tried 100 accounts yet.)</p><h4>Importing accounts</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/0*p7NElL1N5juLxhZO.png" /></figure><p>If you have an existing account, you can hit the <strong>Import Account</strong>. You will be taken in an interface where you will have to put a <em>secret backup phase</em> in the private key string text input of the <em>Private Key</em> category. If you want to import JSON, you can do so by changing it in JSON. But it’s very unlikely to use that one though. Last thing to do is to hit the <strong>Import</strong> button.</p><h3>Switching accounts</h3><p>Since you learned how to import and add accounts, I assume you made new ones too. So let’s learn how to switch accounts!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*RzdjAmne7RPyVUrc.png" /></figure><p>In the example above, you can see that I have already added 2 more accounts: <em>Account 2</em> and <em>Account 3</em>. On the same window as before, if we want to switch to <em>Account 2</em>, from the list, just click it. That easy, you have already switched accounts!</p><h3>Switch networks</h3><p>Switching networks is an important thing about Metamask. As you have recently seen, we’re using the <strong>Main Ethereum Network</strong>. But that’s not the development network, there’s a network for one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*Gu9G6SNeOj7Cey1Y.png" /></figure><p>As you can see on the picture above, we’re on the Main network. But underneath it are developers’ available networks. Most often, developers usually use the <strong>Ropsten Test Network</strong>and <strong>Rinkeby Test Network</strong>. That is if you’re using Remix directly with injected Web3 setting. <em>Localhost:8545</em> however, is for your local Ethereum network, if you’re using Truffle and you made your own blockchain network locally.</p><p>Choosing a network is a case to case basis, but for a common action, let’s choose <strong>Ropsten Test Network</strong>, click it and you’re in it already!</p><h3>Request tokens</h3><p>In making transactions, it costs gas amount, and gas costs money. So, we will need tokens everytime we interact/test contracts or sending tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*rbZl7r9oo_OJbiBH.png" /></figure><p>In the Main network, you have three ways to deposit token:</p><ul><li><strong>Directly Deposit Ether</strong>: by clicking the <em>View Account</em>, using QR code, your other wallet that has tokens can transfer tokens by reading it with a camera.</li><li><strong>CoinBase</strong>: this is usually the way if you’re new to cryptocurrency. You can go to its site, and buy ETH tokens.</li><li><strong>ShapeShift</strong>: basing on its name, it shifts your non-Ethereum tokens to Ethereum ones.</li></ul><p>But all these are mostly used if you’re actually going to spend and do real transactions on Ethereum. For the developers however, if you switch to a developer network such as <strong>Ropsten Network</strong>, you will see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*Go7vizr2t2oBpyYw.png" /></figure><p>Instead of Coinbase and ShapeShift, you will see a <strong>Test Faucet</strong>. By clicking the <strong>Get Ether </strong>button, you will be able to get free tokens. But these tokens have no real value since it’s a testing network. You’ll be taken on a website, for example for Ropsten.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/0*h6UIFIFPF_CeE4TG.png" /></figure><p>By just clicking the green button, you’ll be able to request ether. From there, for a short moment, it will take effect and give you tokens that you’ll be needing as gas for testing in development.</p><p>Here is the link of the <a href="https://faucet.metamask.io/">Testnet Faucet</a>, get yours now!</p><h3>Send tokens</h3><p>Before proceeding, try getting tokens for at your one account from the <em>Test Faucet</em> on <em>Ropsten Network</em>. If you already have tokens, we can now try send tokens to another account. To see the effect, send it to your other created account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*-x-qx-CbHxQvW5m7.png" /></figure><p>From the Ropsten Network, if you hit the <strong>Send</strong> button, you’ll be sent to this interface. In the example, <em>Account 3</em> has 3 <em>ETH</em>, and by hitting the recipient address input text, you’ll be able to choose or paste down an address.</p><p>In your case, use your account that has <em>ETH</em>, and send it to your other account. Set the amount on the <strong>Amount</strong> section, and you can set how fast the transaction will be beneath it, it’s actually customizable if you choose <em>Advance Options</em>.</p><p>After you had set everything, hit <strong>Next</strong>. And you’ll be sent in this interface:</p><h4>Confirmation Interface</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/0*kxkQxRkXL3pvJXLq.png" /></figure><p>This is the exact interface whenever you make transactions on Ethereum using Metamask. You’ll see a lot of this prompting interface once you start developing.</p><p>From here you can also edit the gas fee, to make your transaction faster. In here, we are sending 0.457 ETH to <em>Account 1</em>. Hit <strong>Confirm</strong> and you’re transaction will be processed and will also show up on your <em>Transaction History</em> on the Main interface.</p><h3>Add/Search tokens</h3><p>Aside from <em>ETH</em> token, there are also different kinds of tokens that you can use based on what kind of DApp are you using, usually when you make a DApp they also make their own cryptocurrency. So in here, I’ll show you how to search and add your own token.</p><p>(By standard, cryptocurrency tokens should be <a href="https://theethereum.wiki/w/index.php/ERC20_Token_Standard">ERC20</a> type.)</p><h4>Add tokens</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*dED9KADMSydhJotr.png" /></figure><p>From the Main interface, go to top left menu icon beneath the fox’s head or the Home button. Once you hit the menu, you’ll be able to see this one slide:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*es0IheqYqgeX6_Kr.png" /></figure><p>From what you can see above, your token shows up, under that is actually a supposed list for the other tokens. Since you only have the <em>ETH</em> token, you can’t notice the list.</p><p>With that said, you can add a token, it’s either you add your own made token from an <em>ERC20 </em>standard contract or you search someone’s token assuming that you have one already. Let’s go with the adding your own first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/0*EX-JCOGPiZz2gWIp.png" /></figure><p>On the <em>Custom Token</em> tab, is where you can add your own created token. There are 3 input fields. The last two fills in by itself once you fill in the <strong>Token Address</strong> input text field. So the first one is the only needed.</p><p>If you plan to make your own token, you can try it on the Custom Token tab. Just hit <strong>Next</strong> then you’re good to go, it is added to the list. If you choose one from the list, you can use it for your transactions related to that token.</p><p>Now on to the searching of token.</p><h4>Search tokens</h4><p>Same as before, if you go to the menu icon again, on the <em>Search</em> tab, you will see this interface:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*YcxaNUsOdNAvqZvT.png" /></figure><p>As seen above, <em>EOS</em> is a known example of a crypto token. If in an instance, you have received <em>EOS</em> tokens, then you can search and verify it from here, and add it to your token list.</p><h3>Get backup seed</h3><p>If in case you forgot your <em>secret backup phrase</em>, you can get it from your settings, so go back to settings from the top right menu button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/0*moHwpx3M1sCKjFTI.png" /></figure><p>When you get inside <em>Settings</em>, and if you scroll down on the middle you will find the <em>Reveal Seed Words</em> section. If you hit the <strong>Reveal Seed Words</strong> button, the <em>secret backup phrase</em> will be shown and you can copy it. Keep it safe!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Summary</h3><p>It’s finished! That tutorial sure was a bit long but I’m pretty sure that what you learned just now, will equip you enough for your future or current developments for making your decentralized Ethereum applications.</p><p>In case you forget some things you learned from here, you can always refer back here. It’s natural if you don’t remember everything in one go, every developer’s been there. You’ll get better soon enough!</p><p>Look, even these non-blockchain related Microsoft developers are even happy for you:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*Orv9c6dUgYBXC-LT.gif" /></figure><p>But really now, you did a great job out there. Hope you learned a lot and good luck venturing more about blockchain.</p><p>Until then, signing out, and stay tuned!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><p><strong>openberry</strong> is a tutorial marketplace, designed to allow anyone to learn blockchain programming.</p><ul><li><a href="https://www.openberry.ac/">openberry | blockchain tutorial marktplace</a></li><li><a href="https://twitter.com/openberry_ac">openberry (@openberry_ac) | Twitter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9ac23a10c83" width="1" height="1" alt=""><hr><p><a href="https://medium.com/openberry/getting-started-with-metamask-b9ac23a10c83">Getting Started with Metamask!</a> was originally published in <a href="https://medium.com/openberry">openberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Smart Contracts with Truffle]]></title>
            <link>https://medium.com/openberry/deploying-smart-contracts-with-truffle-1c056b452cde?source=rss----9b65c4aa51d4---4</link>
            <guid isPermaLink="false">https://medium.com/p/1c056b452cde</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[truffle]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Sam Benemerito]]></dc:creator>
            <pubDate>Wed, 13 Feb 2019 02:58:53 GMT</pubDate>
            <atom:updated>2019-02-20T04:35:24.653Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MmLuVxZf0Dn7UAsf.png" /></figure><p>All this time, you might have been deploying your smart contracts with Remix, and the Ropsten Test Network. What if I told you that you could easily set up a blockchain development environment and work on your decentralized application (dapp) completely locally?</p><p>Yes you can, with Truffle!</p><h3>What We Are Going To Do</h3><p>For this tutorial, we will be deploying a simple smart contract with Truffle, and try to interact with it with a very simple web application.</p><h4>Function List</h4><ol><li>Getting the message— we will be retrieving data (string data) from our Smart Contract and display it in our web page</li><li>Setting the message — we will be able to change the message text</li></ol><h4>Tools</h4><ol><li>Smart Contract<br><a href="https://solidity.readthedocs.io/en/latest/">Solidity</a>, <a href="https://metamask.io/">Metamask</a>, <a href="https://truffleframework.com/">Truffle</a>, <a href="https://truffleframework.com/ganache">Ganache</a></li><li>Frontend<br><a href="https://web3js.readthedocs.io/en/1.0/">Web3.js</a>, <a href="https://www.npmjs.com/package/live-server">live-server</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>About Truffle</h3><p>Truffle is basically a development environment where you could easily develop smart contracts with it’s built-in testing framework, smart contract compilation, deployment, interactive console, and many more features.</p><p>It is mostly recommended for developers who want to build Javascript projects based on smart contracts (like dapps). With Truffle, you are able to have a better simulation of a real blockchain environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><h3>Making the Project</h3><h4>Workflow</h4><ol><li>Getting Started with Truffle</li><li>Interacting with the Smart Contract</li></ol><h3>Getting Started with Truffle</h3><p>First, we install the packages we will be using by first opening Terminal/CMD and then execute this command:</p><pre>npm install -g truffle ganache-cli live-server</pre><p>After that, let’s create our project folder, which we will call <strong>HelloWorld</strong>. You can do this using the same Terminal/CMD, and executing these commands:</p><pre>mkdir HelloWorld<br>cd HelloWorld</pre><p>With Truffle, you can create a bare project template, or use <a href="https://truffleframework.com/boxes">Truffle Boxes</a>, which are example applications and project templates. For this tutorial, we will be starting from scratch, so we execute this command:</p><pre>truffle init</pre><p>This command creates a bare Truffle project without anything else included.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>After doing so, you should have the following files and folders:</p><ul><li><strong>contracts/</strong>: Directory for Solidity contracts</li><li><strong>migrations/</strong>: Directory for scriptable deployment</li><li><strong>test/</strong>: Directory for test files for testing your application and contracts</li><li><strong>truffle-config.js</strong>: Truffle configuration file</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><h4>Contract Compilation</h4><p>Now let’s proceed to smart contract compilation with Truffle. Before anything else, let’s create a very simple smart contract named <strong>HelloWorld.sol</strong> and place it inside the <strong>contracts</strong> folder. All smart contracts you create should be placed inside this folder.</p><p>The smart contract will contain code that’s as simple as this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b61d46404f3b28389d8e85aeb88a0047/href">https://medium.com/media/b61d46404f3b28389d8e85aeb88a0047/href</a></iframe><p>Basically, our smart contract has a variable named <strong>message</strong>, which contains string data that is initialized as hello world. Then we have functions that can get or set that variable’s value.</p><p>Let’s try compiling our smart contract! Execute the command:</p><pre>truffle compile</pre><p>Now, compilation could fail and show an error similar to this:</p><pre>SyntaxError: Source file requires different compiler version</pre><p>By default, Truffle uses Solidity version 0.5.0, but our contract uses 0.5.3. And so, we need to tell Truffle to use Solidity version 0.5.3 to compile our contracts by editing the Truffle configuration (<strong>truffle-config.js</strong>). Currently, the configuration should look like this:</p><pre>module.exports = {<br>  networks: {<br>  },<br>  mocha: {<br>  },<br>  compilers: {<br>    solc: {<br>    }<br>  }<br>}</pre><p>To briefly describe the parts that make up the configuration:</p><ul><li><strong>networks</strong>: will hold the configuration of our Ethereum client where we will be deploying our contracts. We will discuss more on this on the later part of the tutorial.</li><li><strong>mocha</strong>: configuration for automated tests using the Javascript testing framework called “Mocha”.</li><li><strong>compilers</strong>: specification of compilers to be used, like <em>solc</em> (Solidity compiler), and what version should be used.</li></ul><p>You might have already guessed which part we will be editing for now, which is the <strong>compilers</strong> part of the configuration.</p><p>Since we want Truffle to use Solidity version 0.5.3, we must use the following <strong>compilers</strong> configuration:</p><pre>compilers: {<br>  solc: {<br>    version: “0.5.3”,<br>    docker: false<br>  }<br>}</pre><p>Let’s run truffle compile once again. The contracts should successfully compile this time. Basically, the compile command compiles Solidity code to <em>bytecode</em> (the code that the Ethereum Virtual Machine or EVM understands).</p><p>Now all that’s left is the deployment!</p><h4>Contract Deployment</h4><p>Now that we’ve created and compiled our sample smart contract, let’s see how we can deploy it to the blockchain. In order to do this, we’ll need to create a new file in the <strong>migrations</strong> directory. So, create a new file named <strong>2_deploy_contracts.js</strong>, and place the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8340cdcddd53a96d63e13c4390b5212f/href">https://medium.com/media/8340cdcddd53a96d63e13c4390b5212f/href</a></iframe><p>Truffle migrations are basically scripts that help us deploy our contracts to the blockchain. The first line is there to import the <strong>HelloWorld.sol</strong> file from the <strong>contracts</strong> folder, and line 4 deploys it to the blockchain.</p><p>Let’s try deploying by executing the command:</p><pre>truffle migrate</pre><p>You’ll notice that it will raise an error saying something like</p><blockquote>Could not connect to your Ethereum client. Please check that your Ethereum client:<br> — is running<br> — is accepting RPC connections (i.e., “ — rpc” option is used in geth)<br> — is accessible over the network<br> — is properly configured in your Truffle configuration file (truffle-config.js)</blockquote><p>Yes, you guessed it right, it’s because we haven’t specified our Ethereum client yet in the <strong>networks</strong> part of our configuration. We can use a locally setup blockchain here, via the truffle develop command or Ganache. We could even deploy straight to Ethereum’s Ropsten Test Network if we configure it here. For this tutorial though, we’ll be using Ganache.</p><p>Let’s open <strong>truffle-config.js</strong>, and change the <strong>networks</strong> part to look like this:</p><pre>networks: {<br>  development: {<br>    host: “127.0.0.1”,<br>    port: 8545,<br>    network_id: “*”<br>  }<br>}</pre><p>This means that we will be using a local Ethereum client (hosted at 127.0.0.1, which means local) on port 8545.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lf2G6MW-q21TD6SR-4002Q.png" /></figure><p>Your <strong>truffle-config.js</strong> file should now look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43119f86b9a6aaacc981f4819ad687a6/href">https://medium.com/media/43119f86b9a6aaacc981f4819ad687a6/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yhwlEFr9p7qRN9ugU3_Lg.png" /></figure><p>Then, open a new Terminal/CMD and start Ganache on port 8545 by executing the following command:</p><pre>ganache-cli -p 8545</pre><p>Now, back to our first Terminal/CMD, we execute</p><pre>truffle migrate -network development</pre><p>to deploy the code to the blockchain. In our case, the blockchain could be found in the network <strong>development</strong> which we set earlier in the <strong>truffle-config.js</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8MjhMBlpSPSxtITvb-d6lQ.png" /><figcaption>truffle deploy (Left), ganache-cli (Right)</figcaption></figure><p>If everything went well as expected, you should be able to see a summary of the deployment on the Terminal/CMD where we did truffle deploy (as shown on the left image), and the transaction data on the Terminal/CMD with Ganache running (as shown on the right image).</p><p>At this point, we’re basically done deploying our contract!</p><h3>Interacting with the Smart Contract</h3><p>Let’s try interacting with our deployed contract through a very simple web application! Here, we’ll just be calling the getMessage() function, and display the text.</p><p>Create a folder named <strong>src</strong> (same level as contracts folder and truffle-config.js) and create a file named <strong>abi.js </strong>inside it. Then, from the <strong>build</strong> folder, and then <strong>contracts</strong> folder, open <strong>HelloWorld.json </strong>(build/contracts/HelloWorld.json), and copy the value of the abi key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*Z8dB2iwWBMJi_cDKacud3Q.png" /></figure><p>Now in <strong>abi.js</strong>, make a variable named <strong>abi</strong> and paste the data we previously copied. Now, <strong>abi.js</strong> should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8d405f192389e341bad4518999f1906/href">https://medium.com/media/a8d405f192389e341bad4518999f1906/href</a></iframe><p>The <a href="https://solidity.readthedocs.io/en/v0.5.3/abi-spec.html">Application Binary Interface</a> (ABI) is basically a specification in the form of a JSON, that describes the contract. We will need this for the web3 connection later.</p><h4>Simple Web Page</h4><p>On the same folder (<strong>src</strong>), create a file named <strong>index.html</strong>, and add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3c953540a8b3f207f4cba6d4c4a88e2/href">https://medium.com/media/d3c953540a8b3f207f4cba6d4c4a88e2/href</a></iframe><p>Simply put, we are creating a web page with one &lt;div&gt; having the ID, message. And as you see, we have 3 &lt;script&gt; tags in place.</p><p>The first one just imports the web3 from a CDN, as can be seen in their short documentation <a href="https://github.com/ethereum/web3.js/">right here</a>. The second one imports the <strong>abi.js</strong> file that we created earlier. Finally, the third one will be where we will be putting some Javascript code to interact with our deployed contract. Now, in this part (3rd script tag), we will now be adding some code which will make it look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/656c2e1dbc80dd10f53733077c90ea52/href">https://medium.com/media/656c2e1dbc80dd10f53733077c90ea52/href</a></iframe><p>Let’s briefly go through the code. On the first line, window.addEventListener(‘load’, async () =&gt; {} just means that when the page loads, we do the commands inside {}. Then, in</p><pre>var contract;<br>const contractAddress = “0x9abd5ea4f8fd7194efa51a3435bfceb24acbee31”;</pre><p>we initialize some variables that we will be needing in the later part of the code. Make sure you change the value of <strong>contractAddress</strong> to your own deployed contract address. You can find it in the Terminal/CMD where you did truffle deploy, somewhere in this part:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/0*2d87wCIRA5tj7eWk.png" /></figure><p>Following that part is an async() call definition stored to const contractMessage:</p><pre>const contractMessage = async () =&gt; {<br> contract = new web3.eth.Contract(abi, contractAddress);<br> let message = await contract.methods.getMessage().call();<br> return message;<br>}</pre><p>Here, we first get our contract instance using our ABI (the one we stored in <strong>abi.js</strong>), and contractAddress (the one we got from deploying our contract). Then, we call our smart contract’s getMessage() method by doing contract.methods.getMessage().call(). Finally, we return the message.</p><p>Now, on this next part:</p><pre>if (window.ethereum) {<br>  window.web3 = new Web3(ethereum);<br>  try {<br>    // Request account access if needed<br>    await ethereum.enable();<br>    var message = await contractMessage();<br>    var elm = document.getElementById(“message”);<br>    elm.innerHTML = message;<br>  } catch (error) {<br>    // User denied account access…<br>  }<br>} else { // Non-dapp browsers…<br>  console.log(‘Non-Ethereum browser detected. You should consider trying MetaMask!’);<br>}<br>```</pre><p>We first check if the browser being used supports Ethereum transactions. If not, we display a console message saying so, but if it does, then we do several commands.</p><p>Basically, we get the message by calling the async() call that we previously defined, named contractMessage(). And then, we set the text being displayed in the &lt;div&gt; tag with the ID, message.</p><p>Now, all that’s left is setting MetaMask to connect to our locally running Ethereum client with ganache-cli.</p><h4>MetaMask Connection</h4><p>First, open the Terminal/CMD that you used to run ganache-cli, and scroll up a bit until you see the part that shows a list of private keys. Ganache basically gives us 10 accounts with 100 ETH each, which we can use in MetaMask. The list of private keys looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/0*Pm6ha2SjXYnZbGR_.png" /></figure><p>Now copy any of them (just one), and open your browser (make sure you already have MetaMask installed). Open MetaMask, and change the Network to Localhost 8545.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/0*JZOvC7TvyK3fYUNu.png" /></figure><p>Then, click on the icon beside the Network dropdown, and click <strong>Import Account</strong>. You should now see that MetaMask will ask for a private key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/0*xNXbrcJe1e_y4WR0.png" /></figure><p>Now you’ll have an account in MetaMask with ~100 ETH. Time to open our simple web app!</p><h4>Starting the Web App</h4><p>Now, using the Terminal/CMD where you did truffle deploy, do the following:</p><pre>cd src<br>live-server</pre><p>We’re just navigating to our <strong>src</strong> folder, and using live-server to run our very basic web app. You’ll now notice that we got the message we put in our smart contract!</p><p>You might encounter a MetaMask pop-up window that asks for access permission though. You should just click the ‘Connect’ button right here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*EV4X0zSwPsDPVadQNXavHw.png" /></figure><p>We’re done! Easy! You should now be able to see the text from our smart contract, being displayed on the page like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/0*QszUE94hpR59W1tg.png" /></figure><h3>Conclusion</h3><p>We’ve only touched on the basic usage of Truffle for local development.</p><p>Perhaps the next steps you can take are either improving the current web app to also call setMessage(), or start using <a href="https://truffleframework.com/boxes">Truffle Boxes</a> for the development of your next dapp.</p><p>’til the next tutorial!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*lAb5iihB2SGv9NyKTrazDg.png" /></figure><p>openberry is a tutorial marketplace, designed to allow anyone to learn blockchain programming.</p><ul><li><a href="https://www.openberry.ac/">openberry | blockchain tutorial marktplace</a></li><li><a href="https://twitter.com/openberry_ac">openberry (@openberry_ac) | Twitter</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c056b452cde" width="1" height="1" alt=""><hr><p><a href="https://medium.com/openberry/deploying-smart-contracts-with-truffle-1c056b452cde">Deploying Smart Contracts with Truffle</a> was originally published in <a href="https://medium.com/openberry">openberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>