<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Wildcards</title>
    <description>The latest articles on Forem by Wildcards (@wildcards).</description>
    <link>https://forem.com/wildcards</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F2449%2Fe48e396e-765d-4b33-886f-f69e63ac8ca2.jpg</url>
      <title>Forem: Wildcards</title>
      <link>https://forem.com/wildcards</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/wildcards"/>
    <language>en</language>
    <item>
      <title>Build your first Harberger Tax App</title>
      <dc:creator>Jason Smythe</dc:creator>
      <pubDate>Wed, 27 May 2020 21:32:32 +0000</pubDate>
      <link>https://forem.com/wildcards/build-your-first-harberger-tax-app-part-1-3gdd</link>
      <guid>https://forem.com/wildcards/build-your-first-harberger-tax-app-part-1-3gdd</guid>
      <description>&lt;h1&gt;
  
  
  Build your first Harberger Tax App
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;If you get through this tutorial and are inspired to build something new you might consider participating in &lt;a href="https://gitcoin.co/issue/wildcards-world/ui/92/4374" rel="noopener noreferrer"&gt;this hackathon challenge&lt;/a&gt;, you can win 200USD :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Wildcards has been running in production for many months, and all the code is opensource. However, we are yet to see a flourishing of applications built with harberger tax. This article aims to make the code that is used to build wildcards easily accessible to the public. There are quite a few manual steps in this tutorial, but if you follow everything step by step you will be able to have a default working harberger tax application on Ethereum with a UI in under 15 minutes.&lt;/p&gt;

&lt;p&gt;There are more links and explanations marked with the heading &lt;strong&gt;&lt;em&gt;Extra&lt;/em&gt;&lt;/strong&gt;. We highly encourage you to go through these, but if you just want to get started they are not necessary (and they will cause you to take longer than 15 minutes). If something goes wrong check if there are any &lt;strong&gt;&lt;em&gt;NOTE&lt;/em&gt;&lt;/strong&gt; sections. Otherwise please create an issue on github&lt;/p&gt;

&lt;p&gt;Once you have completed the basic tutorial we will explore how to customize your application by modifying the contracts and extending the UI. This toolkit is designed to be easy to get started with, yet, (or so we hope) infinitely customizable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contents:
&lt;/h2&gt;

&lt;p&gt;This tutorial has 3 parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First part is to deploy the smart contracts.&lt;/li&gt;
&lt;li&gt;Second part is to create a subgraph that allows you to easily query data from the blockchain.&lt;/li&gt;
&lt;li&gt;The final step is to run a sample UI&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Aside&lt;/em&gt;&lt;/strong&gt;: While we truly love thegraph and the power it gives, it also adds quite a lot of config and complexity to an application. I wouldn't recommend using the graph for very small and quick projects, for that it is simpler to just query blockchain data directly from the blockchain via a provider such as &lt;a href="https://infura.io" rel="noopener noreferrer"&gt;infura.io&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Get the contracts and deploy them.
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Extra&lt;/em&gt;&lt;/strong&gt;: &lt;a href="https://youtu.be/LYm-cVuo0sg" rel="noopener noreferrer"&gt;Here&lt;/a&gt; is a full video presentation of how these smart contracts work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Extra&lt;/em&gt;&lt;/strong&gt;: These contracts use &lt;a href="https://github.com/OpenZeppelin/openzeppelin-sdk" rel="noopener noreferrer"&gt;Zeppelin-SDK&lt;/a&gt; to allow them to be up-gradable. Please go through their &lt;a href="https://openzeppelin.com/sdk/" rel="noopener noreferrer"&gt;docs&lt;/a&gt; carefully to understand what this means and the requirements if you wish to upgrade.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Clone the repository and install the dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/wildcards-world/harberger-base-contracts.git
&lt;span class="nb"&gt;cd &lt;/span&gt;harberger-base-contracts
yarn &lt;span class="c"&gt;# You can also use `npm install` but yarn is recommended.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then deploy the contracts to the goerli test network:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn migrate &lt;span class="nt"&gt;--network&lt;/span&gt; goerli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;NOTE&lt;/em&gt;&lt;/strong&gt;: This command will take a few minutes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;NOTE&lt;/em&gt;&lt;/strong&gt;: If there is an issue with this command it is likely that someone has used/stolen all the goerli testnet eth that is stored by the private key hardcoded in this repo. Another possibility is that the infura keys are exhausted (since they are on free tier). Generate new keys &lt;a href="https://iancoleman.io/bip39/" rel="noopener noreferrer"&gt;here&lt;/a&gt; and paste them into &lt;code&gt;./secrectsManager.example.js&lt;/code&gt; to replace the old private key. If you want to use your own infura keys, generate them &lt;a href="https://infura.io/" rel="noopener noreferrer"&gt;here&lt;/a&gt; and paste your keys into &lt;code&gt;./secrectsManager.example.js&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It should output something similar to this on completion.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FInsmRtH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FInsmRtH.png" alt="Expected Output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Extra&lt;/em&gt;&lt;/strong&gt;: these contracts currently use &lt;a href="https://www.trufflesuite.com/docs/truffle/reference/configuration" rel="noopener noreferrer"&gt;truffle&lt;/a&gt; + &lt;a href="https://www.trufflesuite.com/ganache" rel="noopener noreferrer"&gt;ganache&lt;/a&gt;, but over time the goal is to move it completely to &lt;a href="https://buidler.dev/" rel="noopener noreferrer"&gt;buidler&lt;/a&gt;. At the moment you will find traces of configuration for both in the repo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that the contract is deployed to the goerli testnet we need to get the contract addresses. It is found in the &lt;code&gt;./openzeppelin/goerli.json&lt;/code&gt; file near the bottom under &lt;code&gt;proxies &amp;gt; "the contract name" &amp;gt; address&lt;/code&gt; as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FGrASHKv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FGrASHKv.png" alt="where-to-find-contract-addresses"&gt;&lt;/a&gt;&lt;br&gt;
In our case the address for the &lt;em&gt;HarbergerSteward&lt;/em&gt; is &lt;code&gt;0x4bE0Eab8f41c8109AA134509086Cbcb18b10C0fB&lt;/code&gt; and for the &lt;em&gt;ERC721Patronage&lt;/em&gt; it is &lt;code&gt;0x48C12e1c5aBC5239FD6e2642C929E8FA8bE29999&lt;/code&gt; - we will use these in the next steps, so keep them somewhere for reference.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create a subgraph
&lt;/h2&gt;

&lt;p&gt;This repo allows us to read data from the ethereum blockchain.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Extra&lt;/em&gt;&lt;/strong&gt;: the subgraph is provided by thegraph.com . It uses graphQL which is a specification for how to structure data requests and it is a powerful tool because it allows you to fetch exactly the data you want from the graph. The UI library uses a library called &lt;a href="https://www.apollographql.com/" rel="noopener noreferrer"&gt;apollo&lt;/a&gt; to fetch the data from the subgraph.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Get the code and install the dependencies by running the following in a new terminal and folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/wildcards-world/harberger-base-subgraph.git
&lt;span class="nb"&gt;cd &lt;/span&gt;harberger-base-subgraph
yarn &lt;span class="c"&gt;# Once again, you can use `npm install` if you prefer.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next you will need to create an account with &lt;a href="https://thegraph.com" rel="noopener noreferrer"&gt;the Graph&lt;/a&gt;. Once you have an account go to your dashboard and click the button that says "Add Subgraph" in the top right corner:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FPsaZYQa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FPsaZYQa.png" alt="create-graph-button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fill in your preferred details for your new subgraph:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FDEnfDNu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FDEnfDNu.png" alt="create-graph"&gt;&lt;/a&gt;&lt;br&gt;
Once created it will present you with some default instructions. I have summarised them below.&lt;/p&gt;

&lt;p&gt;Install thegraph cli tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--global&lt;/span&gt; @graphprotocol/graph-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;NOTE&lt;/em&gt;&lt;/strong&gt;: this command will take some time, so feel free to continue in the meantime. You do need this command to run the &lt;code&gt;graph auth&lt;/code&gt; command below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Authenticate with thegraph. Copy the code in the top bar and run it in the following command:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FWlMCvdP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FWlMCvdP.png" alt="secret-graph-code"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;graph auth https://api.thegraph.com/deploy/ &amp;lt;ACCESS_TOKEN&amp;gt; &lt;span class="c"&gt;# find this access token as circled in the image above.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F9v6fsfP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F9v6fsfP.png" alt="success example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are ready to test deploying this graph. First change the &lt;em&gt;package.json&lt;/em&gt; to point to the correct subgraph:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FptkktvU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FptkktvU.png" alt="set-upstream-graph-endpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example if you github name is "jasoons" and your new subgraph is called "harberger-app" you should set this line to say &lt;code&gt;"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ jasoons/harberger-app",&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next you need to auto-generate some setup code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn codegen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Extra&lt;/em&gt;&lt;/strong&gt;: you will need to run this anytime you change the abi (which you will need to change anytime you change the interface of your contract) or your &lt;code&gt;subgraph.yaml&lt;/code&gt; file. It generates helper code based on the interface (abi) of your contracts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You are now ready to deploy this version of the subgraph, but will it deploy the correct subgraph for your contracts? The answer is no, you need to tell the graph to watch the contracts you deployed in the previous step. To do that edit the &lt;code&gt;subgraph.yaml&lt;/code&gt; file with the addresses that you deployed earlier:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F57uJWiN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F57uJWiN.png" alt="set-contracts-in-graph"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now run the deploy script with the correct contract addresses&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FyyIGV4S.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FyyIGV4S.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to back your graph, reload the page and check that everything is working. It should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FXUk7WyD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FXUk7WyD.png" alt="thegraph-playground"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Extra&lt;/em&gt;&lt;/strong&gt;: The docs for thegraph.com are excelent. Do yourself a favour and read through them thoroughly, thegraph will likely help you build on Ethereum for many future projects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Setup the basic UI
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/wildcards-world/harberger-ui.git
&lt;span class="nb"&gt;cd &lt;/span&gt;harberger-ui
yarn
yarn re:build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The UI is configured to run with a single simple command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;EXTRA&lt;/em&gt;&lt;/strong&gt;: You can do all your coding in Javascript or Typescript, however you can also use ReasonMl which is a new typesafe language which is being pioneered by facebook.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now you will need to set the contract address of the steward and the graph endpoint of your subgraph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F1sseS1J.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F1sseS1J.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should be able to now buy token #0 (the starter code has this value hardcoded) via the UI and set its price. To use the UI you will need to have the &lt;a href="https://metamask.io/" rel="noopener noreferrer"&gt;metamask&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To hit the ground running with your own custom UI code you will need to start with the &lt;code&gt;app.js&lt;/code&gt; file. The code should be easy to follow.&lt;/p&gt;

&lt;p&gt;For doing more advanced enhancements to this code, check out tutorial #2 of this series!&lt;/p&gt;




&lt;p&gt;Visit our website &lt;a href="https://wildcards.world" rel="noopener noreferrer"&gt;Wildcards&lt;/a&gt; where you can buy some wildcards and start contributing toward endangered animal conservation today! Follow our socials to learn more about our project and the conservation causes we are working towards.&lt;/p&gt;

&lt;p&gt;Follow us on twitter: &lt;a href="https://twitter.com/wildcards_world" rel="noopener noreferrer"&gt;@wildcards_world&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow us on Facebook: &lt;a href="https://www.facebook.com/wildcardscrypto" rel="noopener noreferrer"&gt;@wildcardscrypto&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow us on Telegram: &lt;a href="https://t.me/wildcardsworld" rel="noopener noreferrer"&gt;Telegram&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As always, stay cool, stay safe and stay tuned&lt;/p&gt;

&lt;p&gt;Team Wildcards&lt;/p&gt;

</description>
      <category>ethereum</category>
      <category>reason</category>
      <category>thegraph</category>
      <category>harbergertax</category>
    </item>
  </channel>
</rss>
