<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by GigaHierz on Medium]]></title>
        <description><![CDATA[Stories by GigaHierz on Medium]]></description>
        <link>https://medium.com/@hierzilena?source=rss-3a2a2750c335------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zw1zbwLfNohm1_1xt39wjg.png</url>
            <title>Stories by GigaHierz on Medium</title>
            <link>https://medium.com/@hierzilena?source=rss-3a2a2750c335------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:21:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hierzilena/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create a Toucan Dashboard on Dune]]></title>
            <link>https://medium.com/@hierzilena/create-a-toucan-dashboard-on-dune-e7fe83298bfc?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7fe83298bfc</guid>
            <category><![CDATA[climate-technology]]></category>
            <category><![CDATA[dune-analytics]]></category>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[toucan]]></category>
            <category><![CDATA[data-dashboard]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Mon, 30 Oct 2023 13:11:48 GMT</pubDate>
            <atom:updated>2023-10-31T12:48:34.365Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how to create your own queries in Dune to visualize data about carbon credits on Celo</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GsCnBazYITMrCcQ1NhofFg.png" /></figure><p><a href="https://celo.org/">Celo</a> is now on <a href="https://dune.com/docs/app/query-editor/query-window/">Dune</a> and as Toucan is on Celo, we have created a <a href="https://dune.com/toucanprotocol/toucan-protocol-nct-celo">board</a> for you to reflect carbon supply, redeems and retirements. And we now have a guide for you here in case you want to build your own little dashboards but you are not yet familiar with Dune.</p><p>This tutorial is for people with some basic knowledge in SQL. Or very good at reading and copying code. We will go through how to get the supply of <a href="https://blog.toucan.earth/toucan-9-faqs/#Toucan%20tokens">NCTs</a> on Celo.</p><p>Creating a Dashboard on Dune seems so easy, so I thought… But when I got the good news that Celo is finally deployed on Dune, and I was getting ready to create my boards, I realized that it is not that easy!</p><p>But eventually, I managed, so here you go: <a href="https://dune.com/toucanprotocol/toucan-protocol-nct-celo">The Board</a>. Read below how I got there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b1IRJM4my9N4rfuwdo15Tw.png" /><figcaption>Dune Dashboard of Toucan on Celp</figcaption></figure><p>For this tutorial, we will look into getting the total supply of NatureCarbonTonnes on Celo.</p><blockquote><strong>NCT:</strong> This carbon reference token represents credits developed with nature-based methodologies, like reforestation initiatives, with vintages from 2012 onwards. To generate one NCT, you can deposit suited TCO2s into the Nature Carbon Tonne pool.</blockquote><h4>Intro to Dune</h4><p>OKOKOK. So first, let’s look at how Dune works.</p><p>You can query different data in the <a href="https://dune.com/docs/app/query-editor/query-window/">Query Editor,</a> like</p><ul><li>“raw data” — Unedited, raw and encoded blockchain data.</li><li>“<a href="https://dune.com/docs/data-tables/decoded/">Decoded data</a>” — View the decoded calls and events made to smart contracts. This data is still unedited.</li><li>“<a href="https://dune.com/docs/data-tables/spellbook/">Spellbook</a>” — Easy to work with aggregated tables that are maintained by Dune and our community.</li><li>“<a href="https://dune.com/docs/data-tables/community/">Community</a>” — Enhanced tables that combine on-chain and off-chain data together.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*O0eD1-A5CfZ8f_z_Z-Cthg.png" /></figure><p>For our needs, we will use the<a href="https://medium.com/"> decoded projects</a> and search for toucan. You will find all of Toucan’s contracts that have been added to Dune under toucan_protocol. Below all of the search results, you will find the option to add more contracts in case the one you are looking for is not there yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*PJi-Yjl9AhDs2Wo74_adDw.png" /><figcaption>List of Toucan Contracts we can query on Dune</figcaption></figure><p>To get the total supply of NCTs on Celo, we will first choose the NatureCarbonTonne contract. Next, we will filter for events, as we will get our data from these events. You can also check out <a href="https://github.com/ToucanProtocol/contracts">Toucan’s contracts</a> to understand what kind of data is emitted with the events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*78dyhXeG6PZv2nDOgA3E0w.png" /><figcaption>List of events of the Nacture Carbon Pool Contract</figcaption></figure><p>One of the reasons why Dune is very cool is that all data and queries are publicly accessible. So, you can fork and copy queries from other projects or build upon them. So, why would we start from the beginning creating our query when we can also just copy stuff? I mean, we developers love copying stuff. For me, this is how I passed all my CS exams.</p><p>Anyway, I am joking (a bit). We are doing this to learn how to query Toucan data, so let’s write one.</p><p>When writing our query, we have to ask ourselves: How can we measure the amount of NCTs on Celo? What kind of data do we have on hand? <br>In case you are new to Toucan, let me explain quickly how it works. In case you know all about it, skip to the “start building queries” part. If you want to learn more, check out <a href="https://blog.toucan.earth/toucan-9-faqs/#infrastructure">Toucan’s blog</a> as well.</p><h4>Overview of Toucan’s Infrastructure Tools</h4><p><strong>Toucan Carbon Bridge</strong>: Carbon credits are tokenized via “<a href="https://docs.toucan.earth/toucan/bridge/carbon-bridge?ref=blog.toucan.earth">Carbon Bridges</a>”. These bridges are connected to conventional registries, like <a href="https://verra.org/?ref=blog.toucan.earth">Verra</a> and <a href="https://www.goldstandard.org/?ref=blog.toucan.earth">Gold Standard</a>. Once bridged, tokenized carbon credits can be sold, transferred, retired or held in private, blockchain-based accounts.</p><p><strong>Toucan Carbon Pools:</strong> These <a href="https://docs.toucan.earth/toucan/pool/pools?ref=blog.toucan.earth">pools</a> solve liquidity issues with carbon markets. They hold tokenized carbon credits with similar attributes (like methodology or vintage), and pay out a liquid and easily tradable reference token in return. Everyone can deposit their tokenized carbon credits into a carbon pool — provided that the attributes match the pool filtering criteria!</p><p><strong>Open Climate Registry (OCR):</strong> The Toucan OCR is a transparent and neutral database that stores information on all carbon credits that have been tokenized or exist only as carbon tokens. The OCR addresses key issues of carbon markets, for example data silos and fragmentation across standards and registries. Individuals and organizations can freely browse the Open Climate Registry and view information and trading history of all recorded carbon credits.</p><p>Now that you have the basics, let’s start writing our first query.</p><h4>Get Amount of Pool Token Supply</h4><p>To determine the total supply of NCT tokens, you have a couple of options. You could visit Celoscan and directly check the overall <a href="https://celoscan.io/address/0x02De4766C272abc10Bc88c220D214A26960a7e92#readProxyContract#F45">NCT token supply</a> there, this is not that easy for most of the queries but for our query right now, this is useful to check that we didn’t forget anything. Alternatively, you can delve into <a href="https://medium.com/@hierzilena/a-comprehensive-guide-to-accessing-carbon-credit-data-3a946e54895e">Toucan’s underlying architecture</a> and calculate the supply programmatically.</p><h4>Finding the Right Events/Calls</h4><p>As I said before, I imagined it to be easier. It seemed straightforward to track the NCT token supply by examining minted and burned events, observing transfers between the NCT address and 0x00 (a common address for burning tokens). However, the reality is a bit more complex. We have to understand Toucan’s architecture before we can design it. Before Toucan was deployed on the Celo blockchain, you could estimate the supply on Polygon by monitoring “in” transfers through the Deposited event and “out” transfers by scrutinizing the Redeemed event. On Celo, though, pool tokens are added not only by depositing TCO but also by bridging NCT from other blockchains like Polygon.</p><p>Also, be aware that contracts can be upgraded and queries might havto be updated. Before Toucan was deployed on Celo, you would get the supply on Polygon for “in” transfers by checking the Deposited event and “out” by checking for the Redeemed event. The new bridge deployed between Polygon and Celo (using Hyperlane) makes it possible to bridge NCT to Celo. So now, you will have to check the amount of tokens transferred through the bridge from Polygon to Celo by getting the sum of the amounts in all calls to bridgeMint and also the other direction bridgeBurn.</p><p>Summarizing this, we have four calls/events we will have to query.</p><ul><li>Tokens minted: NCTs on Celo have been bridged from Polygon</li><li>Tokens burned: NCTs on Celo have been bridged to Polygon</li><li>Tokens redeemed: tokens that have been redeemed for TCO2s. When a NCT is redeemed for a TCO2 it is sent to 0x00.</li><li>Tokens deposited: TCO2 tokens that have been deposited in the NCT pool. For every token that is deposited, an NCT is minted.</li></ul><h4>Overview of Available Data</h4><ol><li>First, we will browse the “decoded projects” for the contract that we need. Here, we search for toucan_protocol.</li><li>Then, we have to choose the contract and the chain. In this case, we choose the NatureCarbonTonne contract on Celo, and we filter for events.</li><li>You can hover over the 👀 icon to get a preview of the return values. Let’s choose the Depostit event and check the data.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*rZzT1Ffzvvh0j1TvzJOzFA.png" /></figure><p>You can also return all data to browse and understand which one you will need. By clicking the arrow Icon next to the event, the whole data source will be added to your file. If you enter the query below, you will get all the data you can see in the preview.</p><pre>Select <br>  *<br>FROM<br>  toucan_protocol_celo.NatureCarbonTonne_evt_Deposited</pre><h4><strong>Sum up Amounts</strong></h4><p>Get the deposited amount of TCO2s. To sum up the amount, we need to use the CAST(1e18 AS DOUBLE) because it’s a big number, and we want a readable number.</p><pre>SELECT<br>  SUM(amount) / CAST(1e18 AS DOUBLE) AS amount_deposited_tco2<br>FROM<br>    toucan_protocol_celo.NatureCarbonTonne_evt_Deposited</pre><h4>Get Redeemed Amount</h4><p>Get the redeemed amount of NCTs:</p><pre>SELECT<br>  SUM(amount) / CAST(1e18 AS DOUBLE) AS amount_redeemed_ncts<br>FROM<br>  toucan_protocol_celo.NatureCarbonTonne_evt_Redeemed</pre><p>Okay. If we run this, it’s a very smoll amount. And now we realize. Aha. How else do NCTs get on Celo? As introduced above, there is also the bridge that we have to consider. So, let’s take a closer look at that.</p><h4>Get the Amount of Bridged NCTs</h4><p>In August 2022 <a href="https://blog.toucan.earth/blog-toucan-earth-toucan-live-on-celo/">Toucan deployed on Celo</a>, and since March 2023, Toucan’s <a href="https://blog.toucan.earth/carbon-retirements-on-celo/">Carbon Retirement</a> is available on Celo. To bring tokens onto Celo, they have been bridged from Polygon. In the future, TCO2s will also be bridged from registries directly onto Celo. But for now, these are the events we have to count in. <br>So, let’s look at how many NCTs have been bridged so far. From the NCT contract, we want to get all call data of the functions bridgeMint and bridgeBurn.</p><pre>SELECT<br>  SUM(_amount) / CAST(1e18 AS DOUBLE) AS amount_minted_nct<br>FROM<br>  toucan_protocol_celo.NatureCarbonTonne_call_bridgeMint</pre><p>Great, now we have all NCTs that have been bridged to Celo. Now, let’s get the amount of tokens bridged from Celo to Polygon.</p><pre>SELECT<br>  SUM(_amount) / CAST(1e18 AS DOUBLE) AS amount_burned_nct<br>FROM<br>  toucan_protocol_celo.NatureCarbonTonne_call_bridgeBurn</pre><p>Finally, we will add up all of these amounts like this:</p><ul><li>deposited calculates the sum of the amount from the NatureCarbonTonne_evt_Deposited events and converts it to a readable format by dividing by 1e18.</li><li>minted calculates the sum of the _amount from the NatureCarbonTonne_call_bridgeMint calls and also converts it to a readable format.</li><li>burned calculates the sum of the _amount from the NatureCarbonTonne_call_bridgeBurn calls and converts it similarly.</li><li>redeemed calculates the sum of the amount from the NatureCarbonTonne_evt_Redeemed events and converts it to a readable format.</li></ul><p>After calculating these individual components, the main query combines them to calculate the market capitalization of NCT tokens:</p><ul><li>It subtracts the amount_burned_nct, amount_redeemed_ncts, and amount_minted_nct from the amount_deposited_tco2.</li><li>The result is stored as market_cap_nct.</li></ul><pre>WITH<br>  deposited AS (<br>    SELECT<br>      SUM(amount) / CAST(1e18 AS DOUBLE) AS amount_deposited_tco2<br>    FROM<br>      toucan_protocol_celo.NatureCarbonTonne_evt_Deposited<br>  ),<br>  minted AS (<br>    SELECT<br>      SUM(_amount) / CAST(1e18 AS DOUBLE) AS amount_minted_nct<br>    FROM<br>      toucan_protocol_celo.NatureCarbonTonne_call_bridgeMint<br>  ),<br>  burned AS (<br>    SELECT<br>      SUM(_amount) / CAST(1e18 AS DOUBLE) AS amount_burned_nct<br>    FROM<br>      toucan_protocol_celo.NatureCarbonTonne_call_bridgeBurn<br>  ),<br>  redeemed AS (<br>    SELECT<br>      SUM(amount) / CAST(1e18 AS DOUBLE) AS amount_redeemed_ncts<br>    FROM<br>      toucan_protocol_celo.NatureCarbonTonne_evt_Redeemed<br>  )<br>SELECT<br>  m.amount_minted_nct - b.amount_burned_nct - r.amount_redeemed_ncts + d.amount_deposited_tco2 AS market_cap_nct<br>FROM<br>  deposited AS d<br>  CROSS JOIN minted AS m<br>  CROSS JOIN burned AS b<br>  CROSS JOIN redeemed AS r</pre><h4>Visualizing the Data</h4><p>As we are only getting one number as output, we don’t have so much to visualize here.</p><p>But I still want to explain how you get a visualization and add that to a dashboard. <br>Below your query, you can choose between seeing the query results, the Counter, or creating another type of visualization. <br>As I said, we only have a number, so the Counter is enough for this. We have to prepare what the counter should show. If no column is chosen automatically, you will have to choose the one you want to be shown; we are choosing market_cap_nct. Additionally, we are adding two decimals and “NCT” as Suffix. Then, we can add that visualization to as many Data Dashboards as we want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3V1_mbrW7TPIyyckIjrS8g.png" /><figcaption>adding decimals and a Suffix to the counter</figcaption></figure><h4>Build Your Data Dashboard</h4><p>Now, we can not only build one board out of this but so many. And for designing your board, you can go crazy! Move everything around, make it bigger and smaller. I mean, look at that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfj-u6WJuKizNnPeFC8pzg.png" /><figcaption>Toucan on Celo Dashboard on Dune</figcaption></figure><p>Okay, so that was it for today. I hope you enjoyed it.</p><h3>Let’s build!</h3><p>Well, let’s get your hands dirty and build your own queries.</p><ul><li><a href="https://medium.com/@hierzilena/a-comprehensive-guide-to-accessing-carbon-credit-data-3a946e54895e?source=your_stories_page-------------------------------------">A Comprehensive Guide to Accessing Carbon Credit Data</a></li><li>Toucan’s <a href="https://docs.toucan.earth/toucan/dev-resources/toucan-developer-resources">docs</a></li><li>Toucan’s <a href="https://github.com/ToucanProtocol/toucan-sdk">SDK</a></li><li>Toucan’s <a href="https://blog.toucan.earth/">blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7fe83298bfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retiring Carbon Credits on Celo from any EVM-chain]]></title>
            <link>https://medium.com/@hierzilena/retiring-carbon-credits-on-celo-from-any-evm-chain-e4966add6bd0?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4966add6bd0</guid>
            <category><![CDATA[hyperlane]]></category>
            <category><![CDATA[toucan]]></category>
            <category><![CDATA[climate-technology]]></category>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Fri, 27 Oct 2023 01:12:23 GMT</pubDate>
            <atom:updated>2023-10-27T10:04:57.090Z</atom:updated>
            <content:encoded><![CDATA[<p>Make your dApp carbon neutral and retire carbon credits on THE climate-positive chain Celo using Hyperlane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yudONEtbutusVJbiebjw1w.png" /></figure><p>Make your dApp carbon neutral and <a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-with-toucan-protocol-an-overview-b3af044a5b59">retire carbon credits</a> on the climate-positive chain <a href="https://celo.org/">Celo</a> using <a href="https://www.hyperlane.xyz/">Hyperlane</a>.</p><p>Creating a carbon-neutral dApp is increasingly common, and it should be as seamless as possible. We’ve received numerous requests from developers looking to integrate carbon offsetting into their applications. However, some face the challenge of deploying their dApps on chains where Toucan Protocol isn’t available. Currently, Toucan Protocol is deployed on Celo and Polygon.</p><p>In this tutorial, we will explore how to retire carbon credits on Celo, a carbon-neutral chain and a leader in advocating for the ReFi movement. By the end of this tutorial, you’ll be able to implement carbon retirement into your dApp, regardless of the EVM-compatible chain it’s deployed on. Additionally, Hyperlane offers bridging capabilities for non-EVM-compatible chains; consult their documentation for further details. All code to this tutorial can be found in the <a href="https://github.com/GigaHierz/bridge-retirement-tutorial">bridge-retirement-tutorial</a> repository.</p><p>In case you are new to retiring carbon credits with Toucan, please refer to these articles.</p><ul><li><a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-with-toucan-protocol-an-overview-b3af044a5b59"><em>How to Retire Carbon Credits with Toucan Protocol — An Overview</em></a></li><li><a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-using-the-offsethelper-8bc02a61f48a"><em>How to retire Carbon Credits using the OffsetHelper</em></a></li></ul><h3>What’s the Process in Detail?</h3><p>This tutorial will use the following tools:</p><ul><li><a href="https://docs.hyperlane.xyz/docs/introduction/readme">Hyperlane</a> V3</li><li><a href="https://github.com/GigaHierz?tab=repositories">Toucan Quickstarter</a></li></ul><p>Now, let’s delve into the specifics of this tutorial. We’ll guide you through these key steps:</p><p>1. <strong>Using </strong><a href="https://docs.hyperlane.xyz/docs/apis-and-sdks/accounts#overhead-gas-amounts"><strong>Hyperlane’s Accounts API</strong></a>: You’ll learn how to employ Hyperlane’s Accounts API to execute a function on a remote chain.</p><p>2.<strong> Deploying a </strong><a href="https://docs.hyperlane.xyz/docs/deploy/deploy-warp-route/deploy-a-warp-route"><strong>Warp Route</strong></a><strong> with Hyperlane</strong>: This section will walk you through the process of setting up a Warp Route with Hyperlane. This is a critical step to pre-fund the account on the remote chain.</p><p>3. <strong>Calling a Function to Retire Carbon Credits from another address</strong>: You’ll gain the knowledge and tools needed to call a function for retiring carbon credits on Celo from another address.</p><p>By following these steps, you’ll be well-prepared to implement carbon offsetting and retirement of carbon credits for your dApp on various EVM-compatible chains, ensuring it aligns with your sustainability goals.</p><p>We will use the <a href="https://github.com/GigaHierz/toucan-quickstart">Toucan Quickstarter</a>, which is based on the <a href="https://github.com/celo-org/celo-composer">Celo-Composer</a>, as our starter template for this tutorial. Create a fork of the Toucan Quickstarter, and let’s get started with cloning it to your local machine.</p><pre>git clone git@github.com:GigaHierz/toucan-quickstart.git</pre><h3>Step 1: Utilize Hyperlane’s Account API</h3><p>When it comes to invoking a payable function on a different blockchain, you use <a href="https://docs.hyperlane.xyz/docs/apis-and-sdks/accounts">Hyperlane’s Accounts API</a>. It enables you to:</p><ul><li><strong>Create Interchain Accounts:</strong> Set up Interchain Accounts, a fundamental requirement for executing cross-chain transactions.</li><li><strong>Create a Warp route:</strong> Ensuring that your Interchain Accounts are adequately funded is necessary to facilitate seamless cross-chain operations. As we call a function on a remote chain, we need to fund the account that will be calling the function on the remote chain.</li><li><strong>Call Functions Across Chains:</strong> Once you’ve established and pre-funded your Interchain Accounts, you can confidently call functions on remote chains as needed.</li></ul><p>Read more about Hyperlanes account API in their <a href="https://docs.hyperlane.xyz/docs/apis-and-sdks/accounts">documentation</a>.</p><h4>Configuring Interchain Account Addresses</h4><p>To initiate a function call on a remote blockchain using Hyperlane, you’ll work with the InterchainAccountRouter. It serves as the bridge to perform cross-chain functions. This key component consists of the following elements:</p><ul><li><strong>The Interface of the Router: </strong>You’ll define your interactions with the InterchainAccountRouter through its interface, specifying how data is exchanged between the chains.</li><li><strong>The Call Struct: </strong>In the context of cross-chain calls, the Call struct includes essential information, such as the destination address and the function data, necessary to execute functions on a remote blockchain.</li></ul><h4>Interface</h4><p>Add a file to your packages/hardhat/contracts/interfaces folder, called IInterchainAccountRouter.sol . In this file, we add the interface of the IInterchainAccountRouter .</p><p>We are also defining the Call struct here, where we define our call to the remote function. As input, it takes:</p><ul><li>address : the address of the contract we want to call</li><li>data: takes the encoded function name and function input</li></ul><pre>// SPDX-License-Identifier: Apache-2.0<br>pragma solidity ^0.8.13;<br><br>struct Call {<br>    // not supporting non-EVM targets<br>    address to;<br>    bytes data;<br>}<br><br>interface IInterchainAccountRouter {<br>    function callRemote(<br>        uint32 _destinationDomain,<br>        Call[] calldata calls<br>    ) external returns (bytes32);<br><br>    function getRemoteInterchainAccount(<br>        uint32 _destination,<br>        address _owner<br>    ) external view returns (address);<br>}</pre><h4>Getting the Remote Interchain Account Addresses</h4><p>Next, we will start writing our smart contract. Create a file called CarbonRetirementBridge.sol in packages/hardhat/contracts/.</p><p>As mentioned before, we will need to call callRemote() from the Interchain Account Router instance to call a function on a remote chain. But before we can do that, we need to pre-fund the remote Interchain Account (ICA). We can call getRemoteInterchainAccount() to get the address of the remote ICA to pre-fund so we can pay for the transaction on the remote chain.</p><p>Inputs are:</p><ul><li><a href="https://docs.hyperlane.xyz/docs/resources/domains">interchainAccountAddress</a>: address of the API to create and control an account on a remote chain from their local chain</li><li><a href="https://docs.hyperlane.xyz/docs/resources/domains">destinationDomain</a> : reference Hyperlane supported chains</li></ul><pre><br>contract CarbonRetirementBridge {<br>  <br>  // InterchainAccountRouter Addresses<br>  address interchainAccountAddress =<br>      0x6f393F8Dfb327d99c946e0Dd2f39F51B1aB446bf;<br>  // DomainIdentifier<br>  uint32 destinationDomain = 44787; // alfajores<br><br>  // init Router instance. this should be done in the constructor<br>  IInterchainAccountRouter public router;<br>  router = IInterchainAccountRouter(interchainAccountAddress);<br>  <br>  // get interchain Account to be able to prefund it<br>  function getRemoteInterchainAccount()<br>      public<br>      view<br>      returns (address _remoteAccount)<br>  {<br>      _remoteAccount = router.getRemoteInterchainAccount(<br>          destinationDomain, // destination<br>          address(this)<br>      );<br>  }<br>}</pre><h3>Step 2: Create Warp Route to Pre-Fund Remote ICA</h3><p>Now that we have the address of the remote ICA, we will have to set up a warp route to pre-fund it. For this part, we are following the “<a href="https://docs.hyperlane.xyz/docs/deploy/deploy-warp-route/deploy-a-warp-route">Deploy a Warp Route</a>” tutorial.</p><p>First of all, we need to get some test tokens:</p><ol><li>Get test ETH from an <a href="https://community.optimism.io/docs/useful-tools/faucets/">Optimism Faucet</a> to pay for gas fees.</li><li>Get WETH from a <a href="https://community.optimism.io/docs/useful-tools/faucets/">faucet contract</a> to bridge from OptimismGoerli to Alfajores.</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F12pJ8OxSWwO86Y%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F12pJ8OxSWwO86Y%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F12pJ8OxSWwO86Y%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b919deb540892c7af871582bacc55d9/href">https://medium.com/media/7b919deb540892c7af871582bacc55d9/href</a></iframe><p>To deploy the warp route, we use the <a href="https://github.com/hyperlane-xyz/hyperlane-deploy">hyperlane-deploy</a> repository provided by Hyperlane. It includes a script to configure and deploy a Warp Route for your desired token. It is super easy to use, but don’t follow the docs in GitHub, as they are not up to date. Start by forking the repository and cloning it to your local machine:</p><pre>git clone git@github.com:hyperlane-xyz/hyperlane-deploy.git</pre><p>In the <a href="https://github.com/hyperlane-xyz/hyperlane-deploy/blob/main/config/warp_tokens.ts">hyperlane-deploy/config/warp_tokens.ts</a> add the following info:</p><h4>Base</h4><p>Your WarpRouteConfig must have exactly one base entry. Here, you will configure details about the token for which you create the warp route.</p><ul><li>chainName: Set this equal to the chain on which your token exists</li><li>type: Set this to TokenType.collateral to create a warp route for an ERC20/ERC721 token, or TokenType.native to create a warp route for a native token (e.g., Ether)</li><li>address<strong>:</strong> If using TokenType.collateral, the address of the ERC20/ERC721 contract for which to create a route</li><li>isNft<strong>: </strong>If using TokenType.collateral for an ERC721 contract set to true</li></ul><h4>Synthetics</h4><p>Your WarpRouteConfig must have at least one synthetics entry. Here, you will configure details about the remote chains supported by your warp route.</p><ul><li>chainName<strong>:</strong> Set this equal to the chain on which you want a wrapped version of your token</li></ul><pre>import { TokenType } from &#39;@hyperlane-xyz/hyperlane-token&#39;;<br><br>import type { WarpRouteConfig } from &#39;../src/warp/config&#39;;<br><br>// A config for deploying Warp Routes to a set of chains<br>// Not required for Hyperlane core deployments<br>export const warpRouteConfig: WarpRouteConfig = {<br>  base: {<br>    // Chain name must be in the Hyperlane SDK or in the chains.ts config<br>    chainName: &#39;optimismgoerli&#39;,<br>    type: TokenType.collateral, //  TokenType.native or TokenType.collateral<br>    // If type is collateral, a token address is required:<br>    address: &#39;0x32307adfFE088e383AFAa721b06436aDaBA47DBE&#39;, // weth - optimism<br><br>    // If the token is an NFT (ERC721), set to true:<br>    // isNft: boolean<br><br>    // Optionally, specify owner, mailbox, and interchainGasPaymaster addresses<br>    // If not specified, the Permissionless Deployment artifacts or the SDK&#39;s defaults will be used<br>  },<br>  synthetics: [<br>    {<br>      chainName: &#39;alfajores&#39;,<br><br>      // Optionally specify a name, symbol, and totalSupply<br>      // If not specified, the base token&#39;s properties will be used<br><br>      // Optionally, specify owner, mailbox, and interchainGasPaymaster addresses<br>      // If not specified, the Permissionless Deployment artifacts or the SDK&#39;s defaults will be used<br>    },<br>  ],<br>};</pre><p>This is all the information that we need to add. Now, we can deploy our warp route.</p><h4>Deployment of Core Contracts</h4><p>We start by deploying all core contracts</p><ul><li>local: The local chain on which Hyperlane is being deployed</li><li>remotes: The chains with which &#39;local&#39; will be able to send and receive messages</li><li>key: A hexadecimal private key for transaction signing</li></ul><pre>yarn ts-node scripts/deploy-hyperlane.ts --local optimismgoerli \<br>  --remotes  alfajores \<br>  --key &lt;PRIVATE_KEY&gt;</pre><p>When the command finishes, it will output the list of contract addresses to hyperlane-deploy/artifacts/warp-token-addresses.json.</p><p>The deployer will also output a token list file to hyperlane-deploy/artifacts/warp-ui-token-list.ts which can be used to <a href="https://medium.com/docs/deploy/deploy-warp-route/deploy-the-ui-for-your-warp-route">Deploy a UI for your Warp Route</a>.</p><h4>Deploy the Warp Route</h4><p>Now, we are ready to deploy the warp route by running the deploy-warp-route.ts script:</p><ul><li>key: A hexadecimal private key for transaction signing</li></ul><pre>yarn ts-node scripts/deploy-warp-routes.ts \<br>  --key &lt;PRIVATE_KEY&gt;</pre><p>Next, we can send funds to the remote Interchain Account.</p><ul><li>origin: The name of the chain that you are sending tokens from</li><li>destination: The name of the chain that you are sending tokens to</li><li>wei: The value of tokens to transfer, in wei</li><li>recipient: The address to send the tokens to on the destination chain, in our case, the remote Interchain Account</li><li>key: A hexadecimal private key for transaction signing</li></ul><pre>yarn ts-node scripts/test-warp-transfer.ts \<br>  --origin optimismgoerli --destination alfajores --wei 1 \<br>  --recipient 0x8a89B5fBDfE08A9EDEEA422114F2492e58e3804a \ <br>  --key &lt;PRIVATE_KEY&gt;</pre><h3>Step 3: Create a Retirement Contract</h3><p>One important part of retiring carbon credits is that you want to have the retirement related to your address to claim the retirement.</p><p>We are using the <a href="https://github.com/GigaHierz/toucan-quickstart">Toucan Quickstart Repo</a> to create our function. There, we will have to create two new functions.</p><ol><li>Call a swapper function so we can pay with an ERC20 token.</li><li>Create an auto-redeem function to redeem pool tokens for TCO2s</li><li>Create a retirement function that retires for another address.</li></ol><h4>Carbon Credit Retirement</h4><p>In the receiver contract, we will</p><ol><li>Swap ERC20 tokens: exchange WETH for NCT</li><li>Redeem pool tokens for TCO2s: redeem NCT for TCO2</li><li>Retire from another address: retire TCO2 from our sender address</li></ol><p>We are not using the <a href="https://github.com/ToucanProtocol/OffsetHelper">OffsetHelper</a>, but the function we are writing is almost identical, except that we add the user&#39;s address to link it to the retirement.</p><p>This function also allows users to offset carbon emissions using specific ERC20 tokens (WETH). It swaps the provided ERC20 token for a Toucan pool token (NCT), redeems the pool token for TCO2 tokens, and retires the TCO2 tokens. Okay okay okay. This sounds maybe new to you. Check out this <a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-using-the-offsethelper-8bc02a61f48a">article</a> that goes into detail on how the OffsetHelper works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*92W8uWLcc9WmIHhp8TEmJQ.png" /></figure><h4>Swap ERC20 Tokens</h4><p>The swapExactInToken() function, that you can find in the Toucan Quickstarter under packages/hardhat/contracts/Swapper.sol, allows swapping eligible ERC20 tokens for pool tokens (NCT) on <a href="https://ubeswap.org/">Ubeswap</a> for Celo and <a href="https://www.sushi.com/swap">Suhsiswap</a> for Polygon. Prior approval on the client side is required to use this function. It takes the following parameters:</p><ul><li>_path: An array of token addresses that describe the swap path, indicating the tokens involved in the exchange.</li><li>_fromAmount: The amount of ERC20 tokens to swap</li></ul><pre><br>import &quot;@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol&quot;;<br>import &quot;@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol&quot;;<br><br>contract Swapper {<br>    using SafeERC20 for IERC20;<br><br>    // Dex Router Address<br>    address public dexRouterAddress;<br><br>    function swapExactInToken(<br>        address[] memory _path,<br>        uint256 _fromAmount<br>    ) public returns (uint256 amountOut) {<br>        uint256 len = _path.length;<br><br>        // transfer tokens<br>        IERC20(_path[0]).safeTransferFrom(<br>            msg.sender,<br>            address(this),<br>            _fromAmount<br>        );<br><br>        // approve router<br>        IERC20(_path[0]).approve(dexRouterAddress, _fromAmount);<br><br>        // swap<br>        uint256[] memory amounts = IUniswapV2Router02(dexRouterAddress)<br>            .swapExactTokensForTokens(<br>                _fromAmount,<br>                0, // min. output amount<br>                _path,<br>                address(this),<br>                block.timestamp<br>            );<br>        amountOut = amounts[len - 1];<br>    }<br>}</pre><h4><strong>Redeem Pool Tokens for TCO2s</strong></h4><p>The autoRedeem() function is responsible for redeeming a specified amount of NCT (or BCT) for TCO2 tokens. It requires prior approval on the client side. The function takes the following parameters:</p><ul><li>_fromToken: The pool token address to be used for redemption, like NCT.</li><li>_amount: The amount of tokens to be redeemed.</li><li>The function returns two arrays: tco2s, which contains the TCO2 addresses that were redeemed, and amounts , an array specifying the amounts of each TCO2 token that was redeemed.</li></ul><pre>   function autoRedeem(<br>        address _fromToken,<br>        uint256 _amount<br>    ) public returns (address[] memory tco2s, uint256[] memory amounts) {<br>        require(<br>            IERC20(_fromToken).balanceOf(address(this)) &gt;= _amount,<br>            &quot;Insufficient NCT/BCT balance&quot;<br>        );<br><br>        // instantiate pool token (NCT)<br>        IToucanPoolToken PoolTokenImplementation = IToucanPoolToken(_fromToken);<br><br>        // auto redeem pool token for TCO2; will transfer automatically picked TCO2 to this contract<br>        (tco2s, amounts) = PoolTokenImplementation.redeemAuto2(_amount);<br>    }</pre><h4>Retire from another address</h4><p>We want the remote ICA to call the function and use our wallet address as the retirement address. This can be done with <a href="http://1. Create a retirement function that retires for another address.">retireFrom()</a> from the ToucanCarbonOffset contract.</p><p>The function enables users to retire TCO2 tokens from another address. It takes the following parameters:</p><ul><li>_tco2s: An array containing the addresses of the TCO2 tokens that the user intends to retire. This will be a return value of autoRedeem() .</li><li>_amounts: An array specifying the amounts of ERC20 tokens to be swapped into the Toucan pool. This will be a return value of autoRedeem() .</li><li>_account: The address with which the retirement is associated, related to the TCO2 addresses provided.</li></ul><pre>  function retireFrom(<br>        address[] memory _tco2s,<br>        uint256[] memory _amounts,<br>        address _account<br>    ) internal {<br>        uint256 tco2sLen = _tco2s.length;<br>        require(tco2sLen != 0, &quot;Array empty&quot;);<br><br>        require(tco2sLen == _amounts.length, &quot;Arrays unequal&quot;);<br><br>        for (uint i = 0; i &lt; tco2sLen; i++) {<br>            if (_amounts[i] == 0) {<br>                continue;<br>            }<br>            require(<br>                IERC20(_tco2s[i]).balanceOf(address(this)) &gt;= _amounts[i],<br>                &quot;Insufficient TCO2 balance&quot;<br>            );<br><br>            IToucanCarbonOffsets(_tco2s[i]).retireFrom(_account, _amounts[i]);<br>        }<br>    }</pre><p>This function ensures that the specified TCO2 tokens are retired on behalf of the provided address, allowing for carbon credit retirement from another wallet.</p><p><strong>Create the Function With a Swap and Retire For Another Entity</strong></p><p>Okay. Now we have everything together, and we can create our function, retireFromAddress() , which allows users to retire carbon credits and associate a specific address with the retirement. It follows these steps:</p><ol><li>Acquire a pool token, for example, NCT, by performing a token swap on a decentralized exchange (DEX).</li><li>Redeem the obtained pool token for the oldest TCO2 tokens.</li><li>Retire the TCO2 tokens on behalf of a specified address.</li></ol><p>Parameters:</p><ul><li>_amount: The amount of ERC20 tokens to swap into the Toucan pool.</li><li>_path: An array of token addresses that outlines the swap path, e.g., [&lt;WETH.address, cUSD.address, NCT.address&gt;].</li><li>_account: The address that should be associated with the retirement.</li><li>_dexRouter: The address of the DEX Router used for the token swap.</li></ul><p>Returns:</p><ul><li>tco2s: An array of the TCO2 token addresses that were redeemed.</li><li>amounts: An array indicating the amounts of each TCO2 token that were redeemed.</li></ul><pre>import &quot;./Swapper.sol&quot;;    <br><br>function retireFromAddress(<br>      uint256 _amount,<br>      address[] memory _path,<br>      address _account,<br>      address _dexRouter<br>  ) public returns (address[] memory tco2s, uint256[] memory amounts) {<br>      // deposit pool token from user to this contract<br>      Swapper(_dexRouter).swapExactInToken(_path, _amount);<br><br>      // redeem NCT for a sepcific TCO2<br>      (tco2s, amounts) = autoRedeem(_path[0], _amount);<br><br>      // retire the TCO2s to achieve offset from a different address<br>      retireFrom(tco2s, amounts, _account);<br>  }</pre><h3>Step 4: Create the remote call function</h3><p>We now have everything to call a function on a remote chain. In packages/hardhat/contracts/CarbonRetirementBridge.sol we call RetirementHelper.retireFromAddress() on Celo with the Account API from Optimism. We additionally need to create a new function called addressToBytes32() because the to value of the Call takes bytes32 as input, so we need to cast the type of the RetirementHelper address to bytes32.</p><ul><li>_retirementHelper: The address of the RetirementHelper on the destination chain that you want to call a function from</li><li>_depositedToken: The address of the ERC20 token that the user sends<br> (e.g., WETH)</li><li>_poolAddress: The address of the pool that the user wants to retire tokens from, e.g., NCT</li><li>_amount: The amount of ERC20 token to swap into pool token. The full amount will be used for the retirement.</li></ul><pre>import &quot;./RetirementHelper.sol&quot;;<br><br> function getRemoteInterchainAccount()<br>      public<br>      view<br>      returns (address _remoteAccount) {<br>      _remoteAccount = router.getRemoteInterchainAccount(<br>          destinationDomain, // destination<br>          address(this)<br>      );<br>  }<br><br>function bridgeRetirement(<br>    address _retirementHelper,<br>    uint256 _amount,<br>    address[] memory _path,<br>    address _account,<br>    address _dexRouter<br>) public payable {<br>    // init instance of RetirementHelper<br>    RetirementHelper retirementHelper = RetirementHelper(_retirementHelper);<br><br>    // create function that you want to call in the destination<br>    Call[] memory offsetCall = new Call[](1);<br>    offsetCall[0] = Call({<br>        to: addressToBytes32(address(_retirementHelper)),<br>        data: abi.encodeWithSignature(<br>            &quot;retireFromAddress(uint256,address[],address,address)&quot;,<br>            _amount,<br>            _path,<br>            _account,<br>            _dexRouter<br>        )<br>    });<br><br>    // call function on remote chain<br>    router.callRemote(<br>        destinationDomain, // destination<br>        offsetCall<br>    );<br>}<br><br>function addressToBytes32(<br>   address _address<br> ) internal pure returns (bytes32) {<br>      bytes32 result;<br>      assembly {<br>        mstore(result, _address)<br>  }<br>  return result;<br>}</pre><h4>Pay for bridging with the InterchainGasPaymaster</h4><p>To complete the process, you’ll need to pay for gas during the bridging step. This involves adding the IInterchainGasPaymaster interface.</p><p>Create a new file called interfaces/InterchainGasPaymaster.sol and add this code:</p><pre>// SPDX-License-Identifier: Apache-2.0<br>pragma solidity ^0.8.13;<br><br>interface IInterchainGasPaymaster {<br>    function payForGas(<br>        bytes32 messageId,<br>        uint32 _destination,<br>        uint32 gasAmount,<br>        address sender<br>    ) external payable returns (address);<br>}</pre><p>In our bridgeRetirement function, we will have to store the return value of the remote call in a value that we call messageId. Then, we initialize an instance of the IInterchainGasPaymaster with the <a href="https://docs.hyperlane.xyz/docs/resources/addresses#defaultisminterchaingaspaymaster-1">DefaultIsmInterchainGasPaymaster</a> Address.</p><ul><li>messageId: The return value of the remote function call</li><li>destinationDomain: The domain ID of the chain that you are sending tokens to</li><li>gasAmount: The total gas amount. This should be the overhead gas amount + gas used by the call being made. The <a href="https://docs.hyperlane.xyz/docs/apis-and-sdks/accounts#overhead-gas-amounts">Overhead Gas Amount </a>should be 150.000 if the ICA doesn’t exist yet and 30.000 if it does.</li><li>sender: Refund the msg.sender</li></ul><pre>// SPDX-License-Identifier: Apache-2.0<br>pragma solidity ^0.8.13;<br><br>import {IInterchainGasPaymaster} from &quot;./interfaces/IInterchainGasPaymaster.sol&quot;;<br><br><br>contract CarbonRetirementBridge {<br><br>    uint32 destinationDomain = 44787; // alfajores<br>  <br>  <br>    function bridgeRetirement(<br>        address _offsetter,<br>        address _depositedToken,<br>        address _poolAddress,<br>        uint256 _amount<br>    ) public payable {<br>      <br>      // call function on remote chain<br>      bytes32 messageId = router.callRemote(<br>          destinationDomain, // destination<br>          offsetCall<br>      );<br><br>      // Then, pay for gas...<br>      uint32 gasAmount = 150000;<br><br>      // The InterchainGasPaymaster<br>      IInterchainGasPaymaster igp = IInterchainGasPaymaster(<br>          0x8f9C3888bFC8a5B25AED115A82eCbb788b196d2a<br>      );<br>      // Pay with the msg.value<br>      igp.payForGas{value: msg.value}(<br>          // The ID of the message<br>          messageId,<br>          // Destination domain<br>          destinationDomain,<br>          // The total gas amount. This should be the<br>          // overhead gas amount + gas used by the call being made<br>          gasAmount,<br>          // Refund the msg.sender<br>          msg.sender<br>      );<br>  }<br>}<br></pre><p>Now, deploy the contract, and you can finally retire carbon credits from any EVM chain you can think of. The whole code should now look like this:</p><pre>// SPDX-License-Identifier: Apache-2.0<br>pragma solidity ^0.8.13;<br><br>import &quot;./interfaces/IInterchainGasPaymaster.sol&quot;;<br>import &quot;./interfaces/IInterchainAccountRouter.sol&quot;;<br>import &quot;./RetirementHelper.sol&quot;;<br><br>contract CarbonRetirementBridge {<br>    // InterchainAccountRouter Addresses<br>    address interchainAccountAddress =<br>        0x6f393F8Dfb327d99c946e0Dd2f39F51B1aB446bf;<br>    // DomainIdentifier<br>    uint32 destinationDomain = 44787; // alfajores<br><br>    // init Router instance. this should be done in the constructor<br>    IInterchainAccountRouter public router =<br>        IInterchainAccountRouter(interchainAccountAddress);<br><br>    // get interchain Account to be able to prefund it<br>    function getRemoteInterchainAccount()<br>        public<br>        view<br>        returns (address _remoteAccount)<br>    {<br>        _remoteAccount = router.getRemoteInterchainAccount(<br>            destinationDomain, // destination<br>            address(this)<br>        );<br>    }<br><br>    function bridgeRetirement(<br>        address _retirementHelper,<br>        uint256 _amount,<br>        address[] memory _path,<br>        address _account,<br>        address _dexRouter<br>    ) public payable {<br>        // init instance of RetirementHelper<br>        RetirementHelper retirementHelper = RetirementHelper(_retirementHelper);<br><br>        // create function that you want to call in the destination<br>        Call[] memory offsetCall = new Call[](1);<br>        offsetCall[0] = Call({<br>            to: addressToBytes32(address(_retirementHelper)),<br>            data: abi.encodeWithSignature(<br>                &quot;retireFromAddress(uint256,address[],address,address)&quot;,<br>                _amount,<br>                _path,<br>                _account,<br>                _dexRouter<br>            ),<br>            value: 0<br>        });<br><br>        // call function on remote chain<br>        bytes32 messageId = router.callRemote(<br>            destinationDomain, // destination<br>            offsetCall<br>        );<br><br>        uint32 gasAmount = 150000;<br><br>        // The InterchainGasPaymaster<br>        IInterchainGasPaymaster igp = IInterchainGasPaymaster(<br>            0x8f9C3888bFC8a5B25AED115A82eCbb788b196d2a<br>        );<br>        // Pay with the msg.value<br>        igp.payForGas{value: msg.value}(<br>            // The ID of the message<br>            messageId,<br>            // Destination domain<br>            destinationDomain,<br>            // The total gas amount. This should be the<br>            // overhead gas amount + gas used by the call being made<br>            gasAmount,<br>            // Refund the msg.sender<br>            msg.sender<br>        );<br>    }<br><br>    function addressToBytes32(<br>        address _address<br>    ) internal pure returns (bytes32) {<br>        bytes32 result;<br>        assembly {<br>            mstore(result, _address)<br>        }<br>        return result;<br>    }<br>}</pre><h4>Implementing a Frontend</h4><p>Hyperlane already comes with a <a href="https://github.com/hyperlane-xyz/hyperlane-warp-ui-template">UI</a> for Warp Routes that you can use.</p><h4>Congratulations! You’ve successfully learned how to retire carbon credits from another EVM chain.</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3oz9ZE2Oo9zRC%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3oz9ZE2Oo9zRC%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3oz9ZE2Oo9zRC%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="195" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c97920c676e2b8d1b1e450eece58d77/href">https://medium.com/media/5c97920c676e2b8d1b1e450eece58d77/href</a></iframe><h3>Let’s build!</h3><p>Well, let’s get your hands dirty and start building with Toucan</p><ul><li>Toucan’s <a href="https://github.com/GigaHierz/toucan-quickstart">Quickstart</a>er</li><li>Toucan’s <a href="https://docs.toucan.earth/toucan/dev-resources/toucan-developer-resources">docs</a></li><li>Toucan’s <a href="https://github.com/ToucanProtocol/toucan-sdk">SDK</a></li><li>Toucan’s <a href="https://blog.toucan.earth/">blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4966add6bd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retire Credits From a Specific Carbon Credit Project]]></title>
            <link>https://medium.com/@hierzilena/retire-credits-from-a-specific-carbon-credit-project-f58a997dcf3?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/f58a997dcf3</guid>
            <category><![CDATA[celo-blockchain]]></category>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[carbon-emissions]]></category>
            <category><![CDATA[climate-action]]></category>
            <category><![CDATA[toucan]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Wed, 25 Oct 2023 01:44:03 GMT</pubDate>
            <atom:updated>2023-10-25T01:51:11.519Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn how to retire carbon credits from a specific region (maybe your country?)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olyBcTZ5-RD0duHfGisJ0w.png" /></figure><p>In the last two parts of our 5 part series, we have learned what it means to retire carbon credits using Toucan’s tooling on a high level and then looked at the OffsetHelper that abstracts interactions with Toucan’s main contracts.</p><p>In this part of the Toucan Developer Toolings Series by GigaHierz (me), you will learn how to retire carbon credits from a specific project. We will use our knowledge from the last two articles to create customized functions. After going through this tutorial, you will be able to create a function that retires carbon credits from a specific project. You can find all of the code in the <a href="https://github.com/GigaHierz/toucan-quickstart">Toucan Quickstart Repo</a>.</p><p>Okay, let’s start by defining our main function that we will call retireSpecificProject() and will cover the following steps:</p><ul><li>Redeem the pool token for a specific TCO2 token</li><li>Retire the TCO2 token</li></ul><p>To find more information on the projects that are available, their methodology, region and supply, you can check out <a href="https://www.footprint.network/chart/Toucan-TCO2-token-breakdown-by-project-id-and-supply-fp-44860">this board</a> on Footprint. If you want to learn even more about the project, you can look it up on <a href="https://registry.verra.org/app/search/VCS">Verra</a> using the projectId. If a project is called “VCS-191” the projected would be “191”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATHCfqee-BUT9IIKPSMMUA.png" /><figcaption>Footprint board on projects by ID and supply</figcaption></figure><p>In case you are new to retiring carbon credits with Toucan, please refer to these articles.</p><ul><li><a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-with-toucan-protocol-an-overview-b3af044a5b59"><em>How to Retire Carbon Credits with Toucan Protocol — An Overview</em></a></li><li><a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-using-the-offsethelper-8bc02a61f48a"><em>How to retire Carbon Credits using the OffsetHelper</em></a></li></ul><p>A little reminder here: The following steps are combined in each of the following “auto offset” methods implemented in OffsetHelper to allow a retirement within one transaction.</p><ol><li>Buy pool tokens (on a DEX) with any ERC20 token, e.g., cUSD on <a href="https://celo.org/">Celo</a>.</li><li>Redeem the pool token for a TCO2, a token that holds a direct reference to a real-world asset.</li><li>Retire that TCO2 token.</li></ol><blockquote>Disclaimer: if you are working on testnet, the transaction may revert without a clear error message. This is likely related to the low liquidity of the pools. But no worries, you can fork the mainnet for testing.</blockquote><h3>Swapping</h3><p>The swapping won&#39;t be an official part of this tutorial, but if you want to create a better user experience, you should check out the <a href="https://docs.uniswap.org/contracts/v3/guides/swaps/single-swaps">SingleSwap</a> from <a href="https://uniswap.org/developers">Uniswap</a>, and follow the very easy tutorial to implement a swap. And feel free to create a PR once you do that.</p><h3>Redeeming pool tokens for TCO2</h3><p>As mentioned above, you can use <a href="https://thegraph.com/">The Graph</a> or a <a href="https://www.footprint.network/chart/Toucan-TCO2-token-breakdown-by-project-id-and-supply-fp-44860">Data Dashboard</a>, e.g., on Footprint to find out about the projects and their supply on-chain. Once you&#39;ve got the address of that project, let’s get ready. You can use the <a href="https://github.com/GigaHierz/toucan-quickstart">Toucan Quickstart Repo</a> which already comes with an interface to call functions from Toucan’s contracts.</p><p>For our redeemProject() function, we call redeemMany() from the pool token contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*4ZlFjE0w55mZDXv-xPA7Ng.jpeg" /></figure><ul><li>This function allows users to redeem Toucan pool tokens for TCO2 tokens.</li><li>Users need to <strong>approve</strong> the pool token before calling this function.</li></ul><pre>import &quot;./interfaces/IToucanPoolToken.sol&quot;;<br>import &quot;@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol&quot;;<br><br>contract RetireSpecificProject {<br>    using SafeERC20 for IERC20;<br><br>  function redeemProject(<br>        address _poolToken,<br>         address[] memory _tco2s,<br>        uint256[] memory _amounts<br>    ) public returns (address[] memory tco2s, uint256[] memory amounts) {<br>        // instantiate pool token (NCT or BCT)<br>        IToucanPoolToken PoolTokenImplementation = IToucanPoolToken(_poolToken);<br><br><br>      // sends pool tokens to the contract <br>       IERC20(_poolToken).safeTransferFrom(<br>            msg.sender,<br>            address(this),<br>            _amount<br>        );<br><br>        tco2s = _tco2s;<br>        amounts = _amounts;<br><br>        // redeem pool token for TCO2 with that address; will transfer the TCO2 to this contract<br>        PoolTokenImplementation.redeemMany(tco2s, amounts);<br>    }</pre><p>First, we are creating our instance of the pool contract. We need to transfer the amount of pool tokens to the contract so they can be redeemed in the contract. When implementing the function, you need to approve the token spending before that. When calling redeemMany() , we need an array of TCO2s and the corresponding amounts. This means you can retire tokens from different projects in one transaction. Finally, we return the amounts and the TCO2 amounts to use these variables in the retirement step.</p><p>Important here to know is that Toucan takes <a href="https://docs.toucan.earth/toucan/pool/protocol-fees">fees</a> if you redeem your pool tokens for specific carbon credits. for NCTs that would be a fee of 10%. In the <a href="https://github.com/ToucanProtocol/OffsetHelper">OffsetHelper</a> we are using autoRedeem() to redeem pool tokens for TCO2. This won’t cost us a fee, but you will automatically redeem for the oldest TCO2. If you want to redeem for a specific project, you have to pay a <a href="https://docs.toucan.earth/toucan/pool/protocol-fees">fee</a>. For NCTs, this will 10% of their token price. To properly calculate how many NCTs we will receive, we will have to call IToucanPoolToken.calculateRedeemFees().</p><pre>import &quot;./interfaces/IToucanPoolToken.sol&quot;;   <br><br><br>contract RetireSpecificProject {         <br><br>  function redeemProject() {<br>    // redeem functions<br><br>    // to calculate the amount you will be able to retire<br>    IToucanPoolToken(_poolToken).calculateRedeemFees(tco2s, amounts);<br>  }<br>}</pre><p>Before we can start with the retirement process, we need to subtract the amount of the calculated protocol fees from the amount of pool tokens that we’ve got from the redeeming process. Below, you can see the whole function. In this function, we have now removed the transfer function, as we used it for testing the function.</p><pre>    function redeemProject(<br>        address _poolToken,<br>        address[] memory _tco2s,<br>        uint256[] memory _amounts<br>    ) internal returns (address[] memory tco2s, uint256[] memory amounts) {<br>        require(<br>            IERC20(_poolToken).balanceOf(address(this)) &gt;= _amounts[0],<br>            &quot;Insufficient NCT/BCT balance&quot;<br>        );<br><br>        // instantiate pool token (NCT or BCT)<br>        IToucanPoolToken PoolTokenImplementation = IToucanPoolToken(_poolToken);<br><br>        tco2s = _tco2s;<br>        amounts = _amounts;<br><br>        // redeem pool token for TCO2 with that address; will transfer the TCO2 to this contract<br>        PoolTokenImplementation.redeemMany(tco2s, amounts);<br><br>        // the amount that we return needs to be the actuall amount of TCO2s that<br>        // is received after taking away the reddem fee<br>        amounts[0] =<br>            amounts[0] -<br>            PoolTokenImplementation.calculateRedeemFees(tco2s, amounts);<br>    }</pre><p>Amazing. Now, you are the proud holder of a TCO2, an on-chain carbon credit that references a real-life asset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*lW4KQXwYZjlR4tLwSCZtZw.jpeg" /></figure><p>The last step will be to retire that carbon credit on-chain. One of the benefits of using the blockchain is how we can relate every person directly to retirement (including all the information on the projects. This will bring new opportunities for transparency to the VCM (Voluntary Carbon Market).</p><h3>Retire Carbon Credits</h3><p>This part is pretty straightforward. To retire the carbon credits, we create a retireProjects() function.</p><ol><li>retireProjects():</li></ol><ul><li>This function is responsible for retiring TCO2 tokens to achieve carbon offsetting.</li><li>It retires the specified amount of TCO2 tokens</li></ul><p>We will call the retire() function from the ToucanCarbonOffset contract, which burns the TCO2 and creates the retirements with a reference to your address. For this step, we need the TCO2 addresses and the amounts we want to retire.</p><pre>import &quot;./interfaces/IToucanCarbonOffsets.sol&quot;;<br><br>function retire(address[] memory _tco2s, uint256[] memory _amounts) public {<br>        IToucanCarbonOffsets(_tco2s[0]).retire(_amounts[0]);<br> }</pre><p>Let’s add some checks and a loop for the arrays to the function. We also have to transfer the TCO2s to the smart contract so it can retire them for us. Again, this is for testing the function and will be removed, when we bring all of the functions together.</p><pre>import &quot;./interfaces/IToucanCarbonOffsets.sol&quot;;<br>import &quot;@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol&quot;;<br><br>contract RetireSpecificProject {<br>    using SafeERC20 for IERC20;   <br><br>    function retire(address[] memory _tco2s, uint256[] memory _amounts) public {<br>        uint256 tco2sLen = _tco2s.length;<br>        require(tco2sLen != 0, &quot;Array empty&quot;);<br>        require(tco2sLen == _amounts.length, &quot;Arrays unequal&quot;);<br><br>      <br><br>        for (uint i = 0; i &lt; tco2sLen; i++) {<br>            if (_amounts[i] == 0) {<br>                continue;<br>            }<br>          // sends tco2s tokens to the contract <br>          IERC20(_tco2s[i]).safeTransferFrom(<br>              msg.sender,<br>              address(this),<br>              _amount<br>          );<br><br>            IToucanCarbonOffsets(_tco2s[i]).retire(_amounts[i]);<br>        }<br>    }<br>}</pre><p>Congratulations, you have retired your first carbon credits on chain for the project of your choice! ✨</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*TUvkiMzPFyPtpQOMgprVgA.jpeg" /></figure><p>Okay, now that we have all the pieces, let’s bring them together in our <br> retireSpecificProjectInToken(). Make sure you remove the transfer functions from the redeemProject() as well as the retire() function, as the first transfer of tokens is happening in this function.</p><pre>  function retireSpecificProject(<br>        address _poolToken,<br>        address _tco2,<br>        uint256 _amountToSwap<br>    ) public returns (address[] memory tco2s, uint256[] memory amounts) {<br>        // deposit pool token from user to this contract<br>        IERC20(_poolToken).safeTransferFrom(<br>            msg.sender,<br>            address(this),<br>            _amounts[0]<br>        );<br><br>        // redeem BCT / NCT for a sepcific TCO2<br>        (tco2s, amounts) = redeemProject(_poolToken, _tco2, amountToOffset);<br><br>        // retire the TCO2s to achieve offset<br>        retire(tco2s, amounts);<br>    }</pre><p>And that’s it. Now after deploying the smart contract, we can call the function in our frontend. Check the full code in the toucan-quickstartrepository.</p><h4>Step 5: Interacting with the Contract</h4><p>Once deployed, users can interact with the contract functions. In the react-app folder of the toucan-quickstartrepository, find the index.tsx file and call the function.</p><ul><li>Approve the spending of pool tokens for the contract.</li><li>Call retireSpecificProject() to offset carbon emissions</li></ul><pre> const retire = async () =&gt; {<br>    // approve the spending of the ERC20 tokens, e.g. cUSD<br>    await (await poolContract.approve(retirementHelperAddress, amount)).wait();<br><br>    await retirementHelper.retireSpecificProject(<br>      poolAddress,<br>      tco2Address,<br>      amount,<br>      {<br>        gasLimit: 5000000,<br>      }<br>    );<br>  };</pre><p>That was fun. Now, you have the tools to explore the tools that Toucan provides and build the most fun things.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Ff7b9ltJ4FrhnsKjYx2%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Ff7b9ltJ4FrhnsKjYx2%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Ff7b9ltJ4FrhnsKjYx2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/28b11428436dad4298b58f240e5e19cb/href">https://medium.com/media/28b11428436dad4298b58f240e5e19cb/href</a></iframe><h3>Let’s build!</h3><p>Well, let’s get your hands dirty and start building with Toucan</p><ul><li>Toucan’s <a href="https://github.com/GigaHierz/toucan-quickstart">Quickstart Repo</a></li><li>Toucan’s <a href="https://docs.toucan.earth/toucan/dev-resources/toucan-developer-resources">docs</a></li><li>Toucan’s <a href="https://github.com/ToucanProtocol/toucan-sdk">SDK</a></li><li>Toucan’s <a href="https://blog.toucan.earth/">blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f58a997dcf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Retire Carbon Credits Using the OffsetHelper]]></title>
            <link>https://medium.com/@hierzilena/how-to-retire-carbon-credits-using-the-offsethelper-8bc02a61f48a?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bc02a61f48a</guid>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[climate-technology]]></category>
            <category><![CDATA[climatetech]]></category>
            <category><![CDATA[tokenized-carbon]]></category>
            <category><![CDATA[toucan]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Wed, 18 Oct 2023 03:52:23 GMT</pubDate>
            <atom:updated>2023-10-18T14:28:26.273Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Toucans OffsetHelper has been deployed on </strong><a href="https://celo.org/"><strong>Celo</strong></a><strong>. And also got a pretty update. That’s why I want to give you an update on your knowledge on the OffsetHelper and or provide you with a deep dive into how it works.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*512aWBdspfe1BGIRwGdIbg.png" /></figure><blockquote>This article is the second of 5 articles exploring how to use Toucan’s toolings to implement carbon retirement into your application. It is assumed that you have knowledge about Toucan’s technology and understand the process of <a href="https://blog.toucan.earth/toucan-9-faqs/">tokenizing, redeeming and retiring</a>.<br>Read “<a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-with-toucan-protocol-an-overview-b3af044a5b59">How to retire Carbon Credits with Toucan Protocol — An overview</a>” for a high-level overview on how carbon credit retirement actually works.</blockquote><p>After reading this, you will have an overview of how Toucans <a href="https://github.com/ToucanProtocol/OffsetHelper">OffsetHelper</a> works so you can build similar functions for your personal needs.<br>It is aimed at all the builders and developers who want to make offsetting your emissions a standard and support us in the fight against climate change. To completely benefit from the article, you should have a basic understanding of Solidity. Otherwise, Toucan’s <a href="https://blog.toucan.earth/">blog</a> or their <a href="https://docs.toucan.earth/toucan/introduction/readme">docs</a> would be a better place for you to start.</p><h3>What is the OffsetHelper?</h3><p>So, let’s get started by exploring what the <a href="https://docs.toucan.earth/toucan/dev-resources/offset-helper">OffsetHelper</a> actually is. The OffsetHelper is a tool Toucan developed for their users to retire carbon credits easily. As you might have noticed when going through the documentation and the first <a href="https://medium.com/@hierzilena/how-to-retire-carbon-credits-with-toucan-protocol-an-overview-b3af044a5b59">article</a> of this series, carbon credit retirement is still a bit clunky, and you still have to call lots of different functions to retire them. The OffsetHelper solves this issue by abstracting all of that into one (or two) simple function.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FB3ETOq2MtxqOQ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FB3ETOq2MtxqOQ%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FB3ETOq2MtxqOQ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="231" frameborder="0" scrolling="no"><a href="https://medium.com/media/79caa500325ecfdf8344e49f1d85511a/href">https://medium.com/media/79caa500325ecfdf8344e49f1d85511a/href</a></iframe><p>So, what would be the normal process to retire carbon credits on-chain?</p><ol><li>Buy pool tokens (on a DEX) with any ERC20 token, e.g., cUSD on <a href="https://celo.org/">Celo</a>.</li><li>Redeem the pool token for a TCO2, a token that holds a direct reference to a real-world asset.</li><li>Retire that TCO2 token.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*92W8uWLcc9WmIHhp8TEmJQ.png" /><figcaption>The Grafik shows Step 2 and Step 3</figcaption></figure><h3>Retirement Functions</h3><p>The three steps mentioned above are combined in the following &quot;auto offset&quot; methods implemented in the OffsetHelper to allow a retirement within one transaction, except the first one, as it doesn’t need the swap. For information on what ERC20 tokens you can use to swap, what other functions are available, and the exact out and inputs, check the <a href="https://docs.toucan.earth/toucan/dev-resources/offset-helper">Toucan documentation</a>:</p><ul><li><strong>autoOffsetPoolToken() </strong>if the user already owns a Toucan pool token such as BCT or NCT (the only function that doesn’t include a swap),</li><li><strong>autoOffsetExactOutETH()</strong>if the user would like to perform a retirement using MATIC, specifying the exact amount of TCO2s to retire,</li><li><strong>autoOffsetExactInETH() </strong>if the user would like to perform a retirement using MATIC, retiring the amount of pool tokens, e.g., NCT, that the user gets for the input amount of native tokens, e.g., MATIC,</li><li><strong>autoOffsetExactOutToken() </strong>if the user would like to perform a retirement using an ERC20 token (USDC, WETH, or WMATIC), specifying the exact amount of TCO2s to retire,</li><li><strong>autoOffsetExactInToken() </strong>if the user would like to perform a retirement, retiring the amount of pool tokens, e.g., NCT, that the user gets for the input amount of ERC20 token (USDC, WETH, or WMATIC)</li></ul><h3>Retire Carbon Credit for a specific amount of ERC20 tokens</h3><p>Okay, now let’s look at the specific functions:</p><p>Let’s assume you have vowed to spend 10 cUSD monthly on retiring carbon credits to account for your emissions. The autoOffsetExactInToken() function executes all of the following actions:</p><ul><li>it allows users to offset carbon emissions using specific ERC20 tokens (cUSD, USDC, WMATIC, WETH). Find a list of tokens per chain in the <a href="https://giphy.com/clips/studiosoriginals-rooting-for-you-youre-doing-great-amazing-sweetie-vTs0mgWdnzWiJ7Uqn2">documentation</a>,</li><li>it swaps the provided ERC20 token for a Toucan pool token,</li><li>redeems the pool token for TCO2 tokens,</li><li>and retires the TCO2 tokens.</li></ul><blockquote>When calling this function in the frontend or another contract you will have to approve the amount being sent to the contract beforehand.</blockquote><pre>      function autoOffsetExactInToken(<br>        address _fromToken,<br>        address _poolToken,<br>        uint256 _amountToSwap<br>    ) public returns (address[] memory tco2s, uint256[] memory amounts) {<br>        // swap input token for BCT / NCT<br>        uint256 amountToOffset = swapExactInToken(<br>            _fromToken,<br>            _poolToken,<br>            _amountToSwap<br>        );<br><br>        // redeem BCT / NCT for TCO2s<br>        (tco2s, amounts) = autoRedeem(_poolToken, amountToOffset);<br><br>        // retire the TCO2s to achieve offset<br>        autoRetire(tco2s, amounts);<br>    }</pre><p>We have a swapping, a redeem, and a retire function that are being called. But let’s take a closer look into these functions that we call to understand what is happening:</p><pre>function swapExactInToken(<br>        address _fromToken,<br>        address _poolToken,<br>        uint256 _fromAmount<br>    )<br>        public<br>        onlySwappable(_fromToken)<br>        onlyRedeemable(_poolToken)<br>        returns (uint256 amountOut)<br>    {<br>        // calculate path &amp; amounts<br>        address[] memory path = generatePath(_fromToken, _poolToken);<br><br>        uint256 len = path.length;<br><br>        // transfer tokens<br>        IERC20(_fromToken).safeTransferFrom(<br>            msg.sender,<br>            address(this),<br>            _fromAmount<br>        );<br><br>        // approve router<br>        IERC20(_fromToken).safeApprove(dexRouterAddress, _fromAmount);<br><br>        // swap<br>        uint256[] memory amounts = dexRouter().swapExactTokensForTokens(<br>            _fromAmount,<br>            0, // min. output amount<br>            path,<br>            address(this),<br>            block.timestamp<br>        );<br>        amountOut = amounts[len - 1];<br>    }</pre><p>First, we want to get the path that is needed in the Uniswap V2 Router to let the router know which tokens have to be exchanged until you get NCT for cUSD. There are currently a few pre-defined paths, and more could be added by the contract owner on request. You can find all ERC20 tokens that are currently eligible in the <a href="https://docs.toucan.earth/toucan/dev-resources/offset-helper">docs</a>, or you can check that in the OffsetHelper with isERC20AddressEligible(address tokenAddress) . Then, the amount is transferred to the contract, and the OffsetHelper needs to approve the token swap through the dexRouter . Finally, the tokens are swapped for the pool tokens, e.g., NCTs, and the amount of the pool tokens that we can now redeem is returned.</p><p>In the next step, we call theautoRedeem() function with that amount.</p><pre>   function autoRedeem(address _fromToken, uint256 _amount)<br>        public<br>        onlyRedeemable(_fromToken)<br>        returns (address[] memory tco2s, uint256[] memory amounts)<br>    {<br>        require(<br>            IERC20(_fromToken).balanceOf(address(this)) &gt;= _amount,<br>            &quot;Insufficient NCT/BCT balance&quot;<br>        );<br><br>        // instantiate pool token (NCT or BCT)<br>        IToucanPoolToken PoolTokenImplementation = IToucanPoolToken(_fromToken);<br><br>        // auto redeem pool token for TCO2; will transfer automatically picked TCO2 to this contract<br>        (tco2s, amounts) = PoolTokenImplementation.redeemAuto(_amount);<br><br>        emit Redeemed(msg.sender, _fromToken, tco2s, amounts);<br>    }</pre><p>In this function, we call the redeemAuto() function of the pool token contract, which redeems the pool token for a TCO2 token, which holds a direct reference to a carbon credit (including information about the project like methodology, country, etc.).</p><p>The last step we are doing here is retiring the carbon credits. This function burns the TCO2 token and registers the retirement event in the certificate contract.</p><pre>function autoRetire(address[] memory _tco2s, uint256[] memory _amounts)<br>        public<br>    {<br>        uint256 tco2sLen = _tco2s.length;<br>        require(tco2sLen != 0, &quot;Array empty&quot;);<br><br>        require(tco2sLen == _amounts.length, &quot;Arrays unequal&quot;);<br><br>        for (uint i = 0; i &lt; tco2sLen; i++) {<br>            if (_amounts[i] == 0) {<br>                continue;<br>            }<br>            require(<br>                IERC20(_tco2s[i]).balanceOf(address(this)) &gt;= _amounts[i],<br>                &quot;Insufficient TCO2 balance&quot;<br>            );<br><br>            IToucanCarbonOffsets(_tco2s[i]).retire(_amounts[i]);<br>        }<br>    }</pre><p>In order to estimate the expected amount of Toucan Pool tokens that can be acquired by swapping the provided amount of ERC20 tokens, you can call calculateExpectedPoolTokenForToken().</p><p>The function <strong>autoOffsetExactInETH() </strong>works almost the same. It differs in the following points, though. You won’t have to call the approve function before, and as you are sending the amount as msg.value , you won’t have to add that as input. And as Celo is offering gas payments in different currencies, the swap functions for native functions are not available, e.g.,<strong> </strong>swapETHForExactTokens() on Ubeswap (Disclaimer: the liquidity has been moved to Uniswap, as the support for Ubeswap is being discontinued). This means that this function is only available on Polygon and not on Celo.</p><p>Okay. This was the hardest part. Everything else that follows is just “change the swap function, and keep the rest”. So, stay with me.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FvTs0mgWdnzWiJ7Uqn2%2Fvideo&amp;display_name=GIPHY&amp;url=https%3A%2F%2Fgiphy.com%2Fclips%2Fstudiosoriginals-rooting-for-you-youre-doing-great-amazing-sweetie-vTs0mgWdnzWiJ7Uqn2&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2FvTs0mgWdnzWiJ7Uqn2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="480" height="270" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba6dfa69b37d0e1593f6170060446470/href">https://medium.com/media/ba6dfa69b37d0e1593f6170060446470/href</a></iframe><h3>Retire a specific amount of Carbon Credits</h3><p>We of course also have functions for you in case you used a calculator to estimate your emissions and want to retire a specific amount of carbon credits. In that case, you would call the autoOffsetExactOutToken() function.</p><p>Before you can call that function, though, you will have to first call thecalculateNeededTokenAmount() and use that output as the _amountToOffset() in the autoOffsetExactOutToken() function.</p><pre>function calculateNeededTokenAmount(<br>        address _fromToken,<br>        address _toToken,<br>        uint256 _toAmount<br>    ) public view onlySwappable(_fromToken) onlyRedeemable(_toToken) returns (uint256) {<br>        (, uint256[] memory amounts) =<br>            calculateExactOutSwap(_fromToken, _toToken, _toAmount);<br>        return amounts[0];<br>    }</pre><p>Then, you use that amount for the autoOffsetExactOutToken() function, which executes all of the following actions:</p><ul><li>it allows users to offset carbon emissions using specific ERC20 tokens (cUSD, USDC, WMATIC, WETH). Find a list of tokens per chain in the <a href="https://giphy.com/clips/studiosoriginals-rooting-for-you-youre-doing-great-amazing-sweetie-vTs0mgWdnzWiJ7Uqn2">documentation</a>,</li><li>it swaps the provided ERC20 token for a Toucan pool token, e.g., cUSD on <a href="https://celo.org/">Celo</a></li><li>redeems the pool token for TCO2 tokens,</li><li>and retires the TCO2 tokens.</li></ul><pre>    function autoOffsetExactOutToken(<br>        address _fromToken,<br>        address _poolToken,<br>        uint256 _amountToOffset<br>    ) public returns (address[] memory tco2s, uint256[] memory amounts) {<br>        // swap input token for BCT / NCT<br>        swapExactOutToken(_fromToken, _poolToken, _amountToOffset);<br><br>        // redeem BCT / NCT for TCO2s<br>        (tco2s, amounts) = autoRedeem(_poolToken, _amountToOffset);<br><br>        // retire the TCO2s to achieve offset<br>        autoRetire(tco2s, amounts);<br>    }</pre><p>Except for the swap function swapTokensForExactTokens() , the process is the same as for the autoOffsetExactInToken() function.</p><p>The autoOffsetExactOutETH() works the same way, except for using the swapETHForExactTokens() for the swap and that you pay in the native currency. To calculate the needed amount, you can calculateNeededETHAmount() . Same as with, autoOffsetExactInETH() this function is only available on Polygon.</p><h3>More Ressources</h3><p>To help you understand how to implement the OffsetHelper in your front end, there is now an example repository inside of the OffsetHelper. There, you will find <a href="https://github.com/ToucanProtocol/OffsetHelper/tree/main/example-frontend/pages">example implementations</a> of each of these functions:</p><ul><li><a href="https://github.com/ToucanProtocol/OffsetHelper/blob/main/example-frontend/pages/autoOffsetPoolToken.tsx"><strong>autoOffsetPoolToken()</strong></a></li><li><a href="https://github.com/ToucanProtocol/OffsetHelper/blob/main/example-frontend/pages/autoOffsetExactOutETH.tsx"><strong>autoOffsetExactOutETH()</strong></a></li><li><a href="https://github.com/ToucanProtocol/OffsetHelper/blob/main/example-frontend/pages/autoOffsetExactInETH.tsx"><strong>autoOffsetExactInETH()</strong></a></li><li><a href="https://github.com/ToucanProtocol/OffsetHelper/blob/main/example-frontend/pages/autoOffsetExactOutToken.tsx"><strong>autoOffsetExactOutToken()</strong></a></li><li><a href="https://github.com/ToucanProtocol/OffsetHelper/blob/main/example-frontend/pages/autoOffsetExactInToken.tsx"><strong>autoOffsetExactInToken()</strong></a></li></ul><p>We also added the OffsetHelper to the <a href="https://github.com/GigaHierz/toucan-sdk">Toucan SDK</a>. So, check out the <a href="http://lila-5570-add-offsethelper-to-sdk-docs/">Toucan docs</a> for more information on the SDK and how to implement it into your project.</p><h3>Write your own contract</h3><p>Now that you’ve seen how the OffsetHelper works you can either call one of these functions or you, for example, want to Offset carbon credits from a specific project and or create a certificate at the time of retirement.</p><p>And as I am amazing, I have already prepared that for you in the next part of this series called <a href="https://medium.com/@hierzilena/retire-carbon-credits-for-a-specific-project-f58a997dcf3">“Retire Carbon Credits For a Specific Project”</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F9MIIjUe8fNZfVRQfNP%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F9MIIjUe8fNZfVRQfNP%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F9MIIjUe8fNZfVRQfNP%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/90433826529e52baec2ad99a98535031/href">https://medium.com/media/90433826529e52baec2ad99a98535031/href</a></iframe><h3>What now?</h3><p>Well, let’s get your hands dirty and start building with Toucan</p><ul><li>Toucan’s <a href="https://docs.toucan.earth/toucan/dev-resources/toucan-developer-resources">docs</a></li><li>Toucan’s <a href="https://github.com/ToucanProtocol/toucan-sdk">SDK</a></li><li>Toucan’s <a href="https://blog.toucan.earth/">blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bc02a61f48a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to retire Carbon Credits with Toucan Protocol — An overview]]></title>
            <link>https://medium.com/@hierzilena/how-to-retire-carbon-credits-with-toucan-protocol-an-overview-b3af044a5b59?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3af044a5b59</guid>
            <category><![CDATA[tokenized-assets]]></category>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[toucan]]></category>
            <category><![CDATA[climatetech]]></category>
            <category><![CDATA[carbon-offsetting]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Mon, 16 Oct 2023 15:21:09 GMT</pubDate>
            <atom:updated>2023-10-18T14:28:43.609Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>How to retire Carbon Credits with Toucan Protocol — An overview</strong></h3><h4><strong>This article is a high-level guide focusing on where to find the tools you need for your specific </strong><a href="https://blog.toucan.earth/carbon-credit-retirement/"><strong>carbon retirement</strong></a><strong> requirements. In this tutorial, you won’t learn the technical details but rather where to find the tools for your specific needs.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZESpYI6lomQs5sO4m9ikKA.png" /></figure><p>To start off though we need to do one important clarification on a common misconception: Toucan Protocol does not currently support the tokenization of projects or carbon credits from arbitrary sources. The primary focus is to secure a reliable supply of <a href="https://blog.toucan.earth/scaling-vcm-integrity-pt-1-quality-of-supply/"><strong>high-quality carbon credits</strong></a> for its users. Toucan offers you to retire carbon credits in two different ways. Either you choose the project from which you want to retire a carbon credit and pay a fee, or you choose to automatically retire a token, which would be the oldest token in the pool.</p><h3>Toucan’s Tools</h3><p>In case you are new to Toucan tools, let me explain how you can retire carbon credits. This is a bit of an explanation, but it is important to understand when you want to implement carbon credits into your project. As of now, Toucan has developed two tools. The <a href="https://blog.toucan.earth/tokenization-of-carbon-credits-explained/"><strong>Tokenizer</strong></a> and the <a href="https://docs.toucan.earth/toucan/pool/pools?ref=blog.toucan.earth"><strong>Pools</strong></a>.</p><p>The <strong>Tokenizer</strong> is designed to tokenize existing carbon credits that were created off-chain. By bringing them onto the blockchain, Toucan enhances transparency and accessibility in the voluntary carbon markets. Tokenization fosters greater transparency, price discovery, and direct trading options, addressing the issue where a significant portion of revenue often goes to brokers.</p><p>The second tool is the <strong>Pools</strong>. Toucan has established various pools. These pools facilitate the exchange of tokenized carbon credits (TCO2) for pool tokens like NCT, provided the credits meet specific criteria, such as being nature-based and created after 2012. TCO2 tokens can be obtained through marketplaces like Atem, or you can purchase pool tokens such as NCT on decentralized exchanges (DEXes) like Uniswap or Sushiswap.</p><p>Okay, to summarize: Carbon credits are being tokenized. Then, they can be exchanged for a pool token like NCT. These pool tokens can be traded easily on DEXes. Keep this in mind as will be important for the next part.</p><h3>Retiring Carbon Credits</h3><p>When a carbon credit is retired, the carbon retirement it represents is permanently removed from market circulation. This means that only the person retiring the credit can claim reduced emissions, as they have released the credit’s positive impacts. Therefore, retiring a carbon credit is <em>the </em>critical step to achieving net-zero emissions.</p><p><em>Important to understand when dealing with Toucan’s different tokens: To retire carbon credits, you need to retire TCO2 tokens, as only they hold the reference to the carbon credit certificate. With this action, you can claim a certificate that represents your retirement. Burning an NCT would not have any effect. As it doesn’t hold a reference to a real-world asset (carbon credit certificate), burning it would not be representative of any action of retirement. So, basically, you lose money.</em></p><p>In the following, we will look at the different steps of retiring carbon credits with Toucan.</p><ol><li>Obtain a pool token, e.g., NCT (by performing a token swap on a DEX).</li><li>Redeem the pool token for a TCO2 token.</li><li>Retire the TCO2 token.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*yfovsShO07OJbJ024BsYUA.png" /></figure><h4>Swapping</h4><p>As mentioned before, in most cases, users will acquire pool tokens at an exchange, as access to traditional standards is connected to high fees and long processes. This means, you will get your pool token at a DEX like <a href="https://app.uniswap.org/">Uniswap</a> or <a href="https://ubeswap.org/">Ubeswap</a> (Ubeswap will be deprecated soon; development has been halted) for Celo and <a href="https://www.sushi.com/swap">SushiSwap</a> for Polygon. Check this <a href="https://blog.toucan.earth/how-to-buy-nct-on-sushi/">tutorial</a> to learn how to get pool tokens on Sushiswap.</p><h4>Redeeming</h4><p>The next step will be to redeem your pool token for TCO2 tokens. There you have two options:</p><ul><li>Redeem your pool token for a TCO2 linked to a specific project, which incurs a fee.</li><li>Opt forautoRedeem which doesn’t require a fee but provides you with the lowest-ranking TCO2 tokens, typically the oldest ones.</li></ul><h4>Retiring</h4><p>In the last step we retire the carbon credits. What is happening in this process? The TCO2 tokens are permanently retired by burning them. As it refers to the off-chain carbon credits, <a href="https://blog.toucan.earth/toucan-9-faqs/#doublecounting">double counting is impossible</a>. Then the user can claim an NFT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*4oImLONmRETbbUpRANNNbQ.png" /></figure><h3>Tools</h3><p>Now that you know what is possible, let&#39;s look into what tools are provided.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FSnRKLohURfkufojw5m%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FSnRKLohURfkufojw5m%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FSnRKLohURfkufojw5m%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/0659ea2159ceb69cb6d58101c304ac5c/href">https://medium.com/media/0659ea2159ceb69cb6d58101c304ac5c/href</a></iframe><p>For beginners, we would recommend to either use the SDK or the OffsetHelper</p><ul><li>the SDK can be implemented in any Java-Script project (FE and node). It offers a variety of functionalities, including automatic redeeming and retiring, but also functionalities to offset carbon credits from a specific project. It also includes many predefined queries to get data related to retirements, tokenization, etc. It also includes the OffsetHelper functions as of October 2023.</li><li>The OffsetHelper is a smart contract that facilitates the offsetting of carbon credit by abstracting the following three steps described above (all the functionality can now also be found in the SDK):</li></ul><ol><li>Obtain a pool token, e.g., <a href="https://blog.toucan.earth/announcing-nct-nature-carbon-tonne/">NCT</a> (by performing a token swap on a DEX).</li><li>Redeem the pool token for a TCO2 token.</li><li>Retire the TCO2 token.</li></ol><p>For our more advanced users, you can also check all of <a href="https://github.com/ToucanProtocol/contracts">Toucan’s contracts</a> and their <a href="https://app.toucan.earth/contracts">addresses</a> directly or reach out in our <a href="https://discord.gg/NbqGTAsSe3">discord builders channel</a> to find the perfect processes for you.</p><p>By following these steps, you can actively participate in carbon credit retirement through Toucan Protocol, contributing to a more sustainable future while leveraging the benefits of blockchain technology.</p><h3>What now?</h3><p>Well, let’s get your hands dirty and start building with Toucan</p><ul><li>Toucan’s <a href="https://docs.toucan.earth/toucan/dev-resources/toucan-developer-resources">docs</a></li><li>Toucan’s <a href="https://github.com/ToucanProtocol/toucan-sdk">SDK</a></li><li>Toucan’s <a href="https://blog.toucan.earth/">blog</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F6rdMX8uL9NaawLhX96%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F6rdMX8uL9NaawLhX96%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F6rdMX8uL9NaawLhX96%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3fffd3fd1150c3ef9158a495f20eab7/href">https://medium.com/media/e3fffd3fd1150c3ef9158a495f20eab7/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3af044a5b59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Guide to Accessing Carbon Credit Data]]></title>
            <link>https://medium.com/@hierzilena/a-comprehensive-guide-to-accessing-carbon-credit-data-3a946e54895e?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a946e54895e</guid>
            <category><![CDATA[regenerative-finance]]></category>
            <category><![CDATA[data-queries]]></category>
            <category><![CDATA[carbon-emissions]]></category>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[toucan]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Wed, 17 May 2023 23:49:59 GMT</pubDate>
            <atom:updated>2023-05-17T23:49:59.222Z</atom:updated>
            <content:encoded><![CDATA[<h3>Query data on tokenized carbon using The Graph playground.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4a64lIstF0I8sNQyZuym1Q.png" /></figure><p>Climate change is happening, and climate credits have emerged as a critical tool in our collective sustainability efforts. These credits enable organizations and individuals to offset carbon emissions by supporting projects that reduce greenhouse gas emissions elsewhere. However, accessing transparent and reliable information about these credits has been a complex task in traditional <a href="https://blog.toucan.earth/carbon-reduction-and-removal-for-net-zero/">voluntary carbon markets</a> (VCM). Entering Toucan:</p><blockquote>💡<strong>What is Toucan?</strong><br>Toucan is building technology to unlock climate action at scale. Our digital infrastructure is helping to grow the voluntary carbon market (VCM) in a transparent and high-integrity way. It increases the flow of revenue to the most effective climate impact projects, by bringing established and nascent environmental assets on the blockchain.</blockquote><p>With Toucan, users can now easily access the credits and find projects that align with their sustainability goals.</p><p>Another benefit of Toucan is that it facilitates net-zero claims by providing all the data related to retirements, including the projects and methodologies involved. This makes it much easier for organizations to verify their carbon offsetting and make credible net-zero claims.</p><p>So, in this tutorial, I will introduce the main schemas for data related to carbon credits that have been tokenized using Toucans infrastructure tools. I will walk you through querying various data points related to tokenized carbon credits. In the end, I will also quickly introduce ways to analyze this data.</p><p>The prerequisite for going through this is some technical knowledge and experience with GraphQL or similar languages and Python and JupyterNotebook or JavaScript. If you just want to get an overview of the existing data, how many retirements happened, and how many tokens have been bridged, I’ve got you!</p><p>Check out these boards:</p><ul><li>For data on Celo, check out <a href="https://www.footprint.network/@tomfutago/Toucan-NCT">footprint</a></li><li>For data on Polygon, check out <a href="https://dune.com/toucanprotocol">Dune</a></li></ul><p>For everyone else: Let’s start!</p><h3>Create a custom query</h3><p>We can get all data related to tokenized carbon credit on The Graph, a protocol that provides a comprehensive and user-friendly playground that allows developers to interact with and test their queries. You can find links to all Toucan subgraphs in the documentation and example queries in this <a href="https://docs.toucan.earth/toucan/dev-resources/subgraph">subgraph</a>.</p><p>Some of the main functionalities of the playground are:</p><ol><li>Write and execute queries using the query editor.</li><li>Filter and sort data to narrow down the data you receive from the subgraph. This allows you to retrieve specific subsets of information based on your requirements.</li><li>Explore entities and relationships to understand the available data and how different entities are interconnected.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qOBih-fo2TJ3CCE9yTRQWw.jpeg" /><figcaption>image of Toucan’s subgraph playground</figcaption></figure><p>On the right side of the playground, you’ll see the symbol marked in red in the graphic above. There you can find all of Toucans schemas. Play a bit around with them.</p><p>We now have an idea of how to get data on tokens. Let’s try it out. Let’s get all your retirements on Celo.</p><ul><li>go to the Celo <a href="https://thegraph.com/hosted-service/subgraph/toucanprotocol/celo">subgraph</a></li><li>open the sidebar and close whatever is open</li><li>open the retirements</li><li>get your wallet address. Make sure it is lowercase as the graph is case sensitive</li><li>select the where and add your wallet address at id</li><li>select the properties that you want to see like amount , id and timestamp</li><li>let’s also get more nested and choose token , inside of it choose projectVintage and inside of that choose project</li><li>now choose the properties region and methodology</li></ul><p>your query should look like this now:</p><pre>{<br>  retirements {<br>    token {<br>      projectVintage {<br>        project {<br>          methodology<br>          region<br>        }<br>      }<br>    }<br>    amount<br>    timestamp<br>    id<br>  }<br>}</pre><p>Great. Now that we understand how to create those queries, what kind of data exists related to carbon credits?</p><h3>Toucan’s Schema</h3><p>When creating queries, it’s important to understand the relations. I created some visualization of Toucan’s schemas. Each of these groups is not a complete representation of all relations but instead, all related to the different tools Toucan offers.</p><p>It is important to mention here, that understanding the quality of a project requires a lot of expertise as you cannot get that from the price or the project type. If you want to learn more about what role agencies have in supporting projects that want to retire carbon credits you should read this great article with <a href="https://www.linkedin.com/in/polly-thompson-353aa91a5/?ref=blog.toucan.earth">Polly Thompson</a> from <a href="https://www.sylvera.com/?ref=blog.toucan.earth">Sylvera</a>.</p><p><a href="https://blog.toucan.earth/sylvera/">Why carbon ratings agencies matter | Sylvera</a></p><h4>Tokenize carbon credits</h4><p>In this schema, you can see all relations for tokenized carbon credits, like who owns and created them. Important here, and you can read more about it in <a href="https://docs.toucan.earth/toucan/bridge/fractionalize">Toucans docs</a>, is that when carbon credits are being tokenized they will first be represented by a BatchToken. This needs to be approved by a trusted party to be used to mint an equivalent of TCO2 tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HReWBgJl4wDvooFZ2qE0zA.png" /><figcaption>Tokenize credits</figcaption></figure><h4>Create pool tokens</h4><blockquote>Carbon Pools bundle multiple project-specific tokenized carbon tonnes (TCO2 tokens) into more liquid carbon index tokens, enabling price discovery for different classes of carbon assets.</blockquote><p>Carbon pool tokens are for example NCT’s which you can buy on <a href="https://ubeswap.org/">Ubeswap</a> or <a href="https://www.sushi.com/">SushiSwap</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VU1n9RQYwGjU7d8L5KBuHQ.png" /><figcaption>Schema for pool tokens</figcaption></figure><h4>Retire tokens</h4><p>This schema shows you all relations you need to understand for the retirement of carbon credits, including all retirement and retirement certificate data. As you can see you can, e.g., directly access the user’s retirements and through that also the certificates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PNMDyX_f8gTqg7_eaTFQpw.png" /><figcaption>Redeem &amp; Retire tokenized carbon credits</figcaption></figure><h4>Bridge tokens from Celo to Polygon</h4><p>And finally, the data related to bridging tokens from Celo to Polygon and back. You can see here, where the bridge request was created and what tokens were bridged. Learn more about this bridge and how it works in the <a href="https://docs.toucan.earth/toucan/cross-chain/how-it-works">Toucan documentation</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8nuEls8tOgDjbsgSh_Tj5Q.png" /><figcaption>Bridge tokens from Celo to Polygon and back</figcaption></figure><h3>Querying in Python</h3><p>So now we want to start getting the data in our app and doing something with it.</p><p>To check out the data with Python, try out this amazing tutorial. There is not much to add from my side. It explains how to query the data with Jupyter Notebook and Subgrounds Python Library.</p><p><a href="https://townee.hashnode.dev/how-to-query-the-graph-protocol-for-on-chain-data-using-python">How you can use Python to Query Blockchain Data</a></p><h3>Querying with JavaScript</h3><p>To query the subgraph with JavaScript, you can use the <a href="https://github.com/ToucanProtocol/toucan-sdk">Toucan SDK</a>. There are some predefined queries but you also have the option to create a custom query. This lets you fetch your own queries and can be very powerful if you know graphQL.</p><p>Example for getting all info on a project of a Carbon Credit:</p><pre>import ToucanClient from &quot;toucan-sdk&quot;;<br>import { gql } from &quot;@urql/core&quot;;<br><br>function CustomQuery() {<br>  const toucan = new ToucanClient(&quot;alfajores&quot;);<br>  <br>  const query = gql`<br>    query ($id: String) {<br>      project(id: $id) {<br>        projectId<br>        region<br>        standard<br>        methodology<br>        vintages {<br>          id<br>        }<br>      }<br>    }<br>  `;<br>  <br>  const result = await toucan.fetchCustomQuery(query, { id: &quot;1&quot; });<br>}</pre><p>Wonderful! Now we have learned how to query data on carbon credits tokenized with Toucans infrastructure tools. To learn more about Toucan and how to build on it, check out</p><ul><li>Toucan’s <a href="https://docs.toucan.earth/toucan/dev-resources/toucan-developer-resources">docs</a></li><li>Toucan’s <a href="https://github.com/ToucanProtocol/toucan-sdk">SDK</a></li><li>Toucan’s <a href="https://blog.toucan.earth/">blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a946e54895e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retire Carbon Credits on Celo using Toucan SDK]]></title>
            <link>https://medium.com/@hierzilena/retire-carbon-credits-on-celo-using-toucan-sdk-698826c81ef7?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/698826c81ef7</guid>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[climate-action]]></category>
            <category><![CDATA[toucan]]></category>
            <category><![CDATA[refis]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Tue, 25 Apr 2023 11:14:18 GMT</pubDate>
            <atom:updated>2023-04-25T11:14:18.155Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learn how to make your dApp climate positive with a few lines of code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQrsBMIGBybIHGTSGrexKg.png" /></figure><p>Climate change is real, and thinking of our carbon footprint when building software should be part of the planning process as much as thinking about the architecture. One blockchain that is leading in this regard is Celo blockchain, and they are even offsetting more carbon than they are producing. So, if your choice of network for your application is <a href="https://celo.org/">Celo</a>, you already made a step in the right direction. But other actions can increase your or your users carbon footprint and, in this tutorial, you will learn how to account for that in a few lines of code and create a climate positive app.</p><p>If you are new to carbon credit retirements and what kind of infrastructure tools Toucan provides, make sure to read up on it in their <a href="https://blog.toucan.earth/toucan-9-faqs/#infrastructure">blog</a>.</p><p>Find the repository belonging to this Tutorial <a href="https://github.com/GigaHierz/retire-carbon-credits-celo">here</a>.</p><p><strong>Prerequisites</strong></p><p>To start building, you’ll need a basic understanding of web development, Node (v12), yarn, and Git.</p><ul><li>Node</li><li>Yarn</li><li>Git</li></ul><p><strong>Tools we will use:</strong></p><ul><li><a href="https://github.com/celo-org/celo-composer">Celo-Composer</a></li><li><a href="https://github.com/ToucanProtocol/toucan-sdk">Toucan SDK</a></li></ul><p>Okay. What will learn in this tutorial in detail? We will learn how to retire carbon credits on Celo in a React. To do that we will redeem Nature Carbon Tonnes (NCTs) for tokenized carbon credits (TCO2s) and retire those. We will also learn how to get all data related to tokens and retirements through querying the <a href="https://thegraph.com/hosted-service/subgraph/toucanprotocol/alfajores">subgraph</a>.</p><p><strong>By the end of this tutorial, you will know</strong></p><p>- how to redeem NCT for TCO2</p><p>- how to retire TCO2</p><p>- how to query the subgraph to get details on tokens, retirements and certificates</p><p>And now lets start building 🏗</p><h3><strong>Install Celo-Composer</strong></h3><p>We will use <a href="https://docs.celo.org/blog/tutorials/building-your-first-smart-contract-web-dapp-with-celo-composer">Celo-Composer</a> to quick-start our web3 application. It already comes with several wallet integrations using <a href="https://www.rainbowkit.com/">rainbow-kit</a>, <a href="https://wagmi.sh/">wagmi</a> for easy interactions with the blockchain and <a href="https://tailwindcss.com/">tailwind</a> for styling.</p><pre>npx @celo/celo-composer create</pre><p>To create a simple example project, we just chose the default, except for Choose smart-contract framework:, there we choose none as we won’t need that for this tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*6d3o0lXJsM6r_kDWaeJ28A.jpeg" /></figure><p>Great. Now let’s open the project in our favorite IDE (e.g., VS Code).</p><p>First navigate into the react-app.</p><pre>cd packages/react-app/</pre><p>Here install all dependencies with</p><pre>npm i</pre><p>or</p><pre>yarn</pre><p>And finally, let’s start the App and see if everything is running.</p><pre>npm run dev</pre><p>or</p><pre>yarn run dev</pre><h3><strong>Retire Carbon Credits</strong></h3><p>Next, we are going to retire carbon credits on Celo using the <a href="https://github.com/ToucanProtocol/toucan-sdk">Toucan SDK</a>. The Toucan SDK provides you with tools to simply implement carbon retirements into your app with just a few lines of code. It also provides some pre-defined subgraph queries but offers you the freedom to create any query your heart desires to get all the info about all retirements and tokens.</p><p><strong>Install the SDK</strong></p><p>Add the Toucan SDK.</p><pre>npm i toucan-sdk</pre><p>or</p><pre>yarn add toucan-sdk</pre><p><strong>Get Toucan Client</strong></p><p>We want to first instantiate the ToucanClient and set a signer &amp; provider to interact with our infrastructure. We can use the signer &amp; provider from the wagmi library. For interacting with The Graph, no provider or signer is needed though. But we will talk about that later.</p><p>So in the index.ts file we will add the imports to the top:</p><pre>import ToucanClient from &quot;toucan-sdk&quot;;<br>import { useProvider, useSigner } from &quot;wagmi&quot;;</pre><p>And this part into our function body. You can set the signer and provider directly or at a later point. Here we want to first check if the signer is set, meaning if the user is connected to the application with their wallet.</p><pre>const provider = useProvider();<br>const { data: signer, isError, isLoading } = useSigner();<br><br>const toucan = new ToucanClient(&quot;alfajores&quot;, provider);<br>signer &amp;&amp; toucan.setSigner(signer);</pre><p>In the end our code should look like this:</p><pre>import ToucanClient from &quot;toucan-sdk&quot;;<br>import { useProvider, useSigner } from &quot;wagmi&quot;;<br><br>export default function Home() {<br>  const provider = useProvider();<br>  const { data: signer, isError, isLoading } = useSigner();<br><br>  const toucan = new ToucanClient(&quot;alfajores&quot;, provider);<br>  signer &amp;&amp; toucan.setSigner(signer);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;div className=&quot;h1&quot;&gt;<br>        There we go... a canvas for your next Celo project!<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>Redeem Tokens form a PoolContract (e.g. NCT)</strong></p><p>To retire Carbon Credits, we need pool tokens (e.g., NCTs) or carbon reference tokens like TCO2s. We can get them from the <a href="https://faucet.toucan.earth/">Toucan Faucet</a>. In this example we will get NCT, as theses are the tokens, you can buy in an exchange like <a href="https://ubeswap.org/">Ubeswap</a>.</p><p>What is the difference between NCTs and TCO2s? Simply put, TCO2s are tokenized carbon credits. While NCT are the first carbon reference tokens created on Toucans infrastructure and are stripped of most attributes. As a user you will only have TCO2 tokens, if you tokenized carbon credits yourself or if you have already redeemed NCTs for TCO2s. So, this example will start with NCTs.</p><blockquote>🍃 Get some Nature Carbon Tonnes (NCT) form the <a href="https://faucet.toucan.earth/">Toucan Faucet</a> before you continue. Make sure you have CELO to pay the gas fee for the withdrawal, you can get some from the <a href="https://faucet.celo.org/alfajores">Celo Faucet</a>. 🍃</blockquote><p>Now, using the ToucanSDK we will auto-redeem the Pool tokens with toucan.redeemAuto2, where they are exchanged for the lowest ranking TCO2s. The function also returns the addresses of the redeemed TCO2s, which we need for the next step. As arguments for the function, we will need the pool symbol, that we want to retire, like “NCT”. We will also need to input the amount of tokens we wish to retire, use parseEther(&quot;1&quot;) from the <a href="https://docs.ethers.org/v5/api/utils/display-logic/#utils-parseEther">ethers.js</a> for that.</p><p>If we prefer to choose the TCO2s that we want to retire, we can get a list of all TCO2s with getScoredTCO2s and then select the ones we prefer. Currently scored TCO2 means, that the tokens are sorted by year with scoredTokens[0] being the lowest. Using the Toucan SDK, you can get more info on each of the tokens though querying the subgraph (as described in the next part), and decide your own criteria, based on the newly released <a href="https://blog.toucan.earth/core-carbon-principles/">Core Carbon Principals</a>. When choosing the TCO2 you want to retire, make sure that the balance of the token is not 0.</p><p>After having chosen TCO2s we want to retire, (we can choose several) we can redeem them with toucan.redeemMany. For this Toucan Protocol takes fees. We can calculate the fee beforehand with toucan.calculateRedeemFees.</p><p>But today we stay simple with toucan.redeemAuto2 . The minimum amount you can redeem is 1 NCT in one transaction:</p><pre>await toucan.redeemAuto2(&quot;NCT&quot;, parseEther(&quot;1&quot;));</pre><p>Now let’s put that code in a function and add a button to trigger it, so we can see it in action!! We also want to store the return value, the TCO2 address in a variable, as we will want to use it in the next step.</p><pre>import { parseEther } from &quot;ethers/lib/utils.js&quot;;<br>import ToucanClient from &quot;toucan-sdk&quot;;<br>import { useProvider, useSigner } from &quot;wagmi&quot;;<br><br>export default function Home() {<br>  const provider = useProvider();<br>  const { data: signer, isError, isLoading } = useSigner();<br>  const toucan = new ToucanClient(&quot;alfajores&quot;, provider);<br>  signer &amp;&amp; toucan.setSigner(signer);<br><br>  // we will store our return value here<br>  const [tco2address, setTco2address] = useState(&quot;&quot;);<br><br>  const redeemPoolToken = async (): Promise&lt;void&gt; =&gt; {<br>    const redeemedTokenAddress = await toucan.redeemAuto2(<br>      &quot;NCT&quot;,<br>      parseEther(&quot;1&quot;)<br>    );<br>    redeemedTokenAddress &amp;&amp; setTco2address(redeemedTokenAddress[0].address);<br>  };<br><br>  return (<br>    &lt;div&gt;<br>     &lt;button<br>        className=&quot;inline-flex w-full justify-center rounded-full border px-5 my-5 py-2 text-md font-medium border-wood bg-prosperity text-black hover:bg-snow&quot;<br>        onClick={() =&gt; redeemPoolToken()}<br>      &gt;<br>        {&quot;Redeem Tokens&quot;}<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>So, let’s click that Wallet Connect button and redeem the token.</p><blockquote>👓 Check the transaction on <a href="https://alfajores.celoscan.io/">Celoscan</a> 👓</blockquote><p><strong>Retire TCO2s</strong></p><p>After having <strong><em>redeemed</em></strong> our pool tokens for TCO2s, we will be able to retire them. We can only retire <strong>TCO2</strong> tokens. We can either choose to simply toucan.retire or if we would like to retire for a third party use the toucan.retireFrom function. Lastly, we can also already get a certificate created with toucan.retireAndMintCertificate.</p><p>The first thing we will have to do, will be to get the address of our TCO2 token. We will have saved that as return value form toucan.redeemAuto2. And now we can retire our token.</p><pre>await toucan.retire(parseEther(&quot;1.0&quot;), tco2Address);</pre><p>Let’s create a second function called retirePoolToken as well as a button for the retirement process.</p><pre>import { parseEther } from &quot;ethers/lib/utils.js&quot;;<br>import { useState } from &quot;react&quot;;<br>import ToucanClient from &quot;toucan-sdk&quot;;<br>import { useProvider, useSigner } from &quot;wagmi&quot;;<br><br>export default function Home() {<br>  const provider = useProvider();<br>  const { data: signer, isError, isLoading } = useSigner();<br>  const toucan = new ToucanClient(&quot;alfajores&quot;, provider);<br>  signer &amp;&amp; toucan.setSigner(signer);<br>  const [tco2address, setTco2address] = useState(&quot;&quot;);<br><br>  const redeemPoolToken = async (): Promise&lt;void&gt; =&gt; {<br>    const redeemedTokenAddress = await toucan.redeemAuto2(<br>      &quot;NCT&quot;,<br>      parseEther(&quot;1&quot;)<br>    );<br>    redeemedTokenAddress &amp;&amp; setTco2address(redeemedTokenAddress[0].address);<br>  };<br><br>  const retirePoolToken = async (): Promise&lt;void&gt; =&gt; {<br>    tco2address.length &amp;&amp; (await toucan.retire(parseEther(&quot;1.0&quot;), tco2address));<br>  };<br><br>   return (<br>    &lt;div&gt;<br>      &lt;button<br>        className=&quot;inline-flex w-full justify-center rounded-full border px-5 my-5 py-2 text-md font-medium border-wood bg-prosperity text-black hover:bg-snow&quot;<br>        onClick={() =&gt; redeemPoolToken()}<br>      &gt;<br>        {&quot;Redeem Tokens&quot;}<br>      &lt;/button&gt;<br>      &lt;button<br>        className=&quot;inline-flex w-full justify-center rounded-full border px-5 my-5 py-2 text-md font-medium border-wood bg-prosperity text-black hover:bg-snow&quot;<br>        onClick={() =&gt; retirePoolToken()}<br>      &gt;<br>        {&quot;Retire Tokens&quot;}<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Your application will now look like this. You now have the foundation to implement retirement with endless possibilities like in one function and trigger retirements based on an input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xsDb77XSyYTMeYTVxO4Wiw.png" /><figcaption>image of the app with buttons to redeem and retire</figcaption></figure><h3><strong>Creating a list of our retirements</strong></h3><p>In the last step, we are creating a list showing our retirements. First, we will create a new list.tsx page.</p><p>Here we need the Toucan Client again. This time, we won’t need a provider or signer as we are only querying the subgraph.</p><pre>const toucan = new ToucanClient(&quot;alfajores&quot;);</pre><p>The Toucan SDK has several pre-defined queries to get data from the subgraph, but we can also create our customized query with toucan.fetchCustomQuery(). We can check all schemes, create and test our query in the <a href="https://thegraph.com/hosted-service/subgraph/toucanprotocol/alfajores">playground</a> of the Toucan Subgraph.</p><p>For now, we will use one of the predefined queries, to get a list of our retirements. We will need the user address here so we will use the useAccount Hook from wagmi. Remember that an address (user, token) always needs to be lower case for querying.</p><pre>const {address} = useAccount()<br><br>await toucan.fetchUserRetirements(address?.toLowerCase());</pre><p>Now let’s add save the return value in a state, add typing for our retirement data, fetch the user retirements when the component is loading and add some code to display our retirements in a table.</p><pre>import { useEffect, useState } from &quot;react&quot;;<br>import ToucanClient, { UserRetirementsResponse } from &quot;toucan-sdk&quot;;<br>import { useAccount } from &quot;wagmi&quot;;<br><br>export default function List() {<br>  const toucan = new ToucanClient(&quot;alfajores&quot;);<br>  const { address } = useAccount();<br><br>  const [retirements, setRetirements] = useState([]);<br><br>  const getUserRetirements = async () =&gt; {<br>    const result =<br>      address &amp;&amp; (await toucan.fetchUserRetirements(address?.toLowerCase()));<br>    result &amp;&amp; setRetirements(result);<br>  };<br><br>  useEffect(() =&gt; {<br>    getUserRetirements();<br>  });<br><br>  return (<br>     &lt;div&gt;<br>      &lt;div className=&quot;mt-8 flow-root&quot;&gt;<br>        &lt;div className=&quot;-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8&quot;&gt;<br>          &lt;div className=&quot;inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8&quot;&gt;<br>            {<br>              retirements.length &amp;&amp; (<br>                &lt;div className=&quot;overflow-hidden ring-1 ring-black&quot;&gt;<br>                  &lt;table className=&quot;min-w-full divide-y divide-black&quot;&gt;<br>                    &lt;thead className=&quot;bg-prosperity&quot;&gt;<br>                      &lt;tr&gt;<br>                        &lt;th scope=&quot;col&quot; className=&quot;py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6&quot;&gt;<br>                          Token Name<br>                        &lt;/th&gt;<br>                        &lt;th scope=&quot;col&quot; className=&quot;px-3 py-3.5 text-left text-sm font-semibold text-gray-900&quot;&gt;<br>                          Token Symbol<br>                        &lt;/th&gt;<br>                        &lt;th scope=&quot;col&quot; className=&quot;px-3 py-3.5 text-left text-sm font-semibold text-gray-900&quot;&gt;<br>                          Certificate ID<br>                        &lt;/th&gt;<br>                        &lt;th scope=&quot;col&quot; className=&quot;px-3 py-3.5 text-left text-sm font-semibold text-gray-900&quot;&gt;<br>                          Creation Tx<br>                        &lt;/th&gt;<br>                      &lt;/tr&gt;<br>                    &lt;/thead&gt;<br>                    &lt;tbody className=&quot;divide-y divide-black bg-white&quot;&gt;<br>                      {retirements.map((item) =&gt; {<br>                        return (<br>                          &lt;tr key={item.id}&gt;<br>                            &lt;td className=&quot;whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6&quot;&gt;<br>                            {item.token.name}<br>                            &lt;/td&gt;<br>                            &lt;td className=&quot;whitespace-nowrap px-3 py-4 text-sm text-gray-500&quot;&gt;{item.token.symbol}&lt;/td&gt;<br>                            &lt;td className=&quot;whitespace-nowrap px-3 py-4 text-sm text-gray-500&quot;&gt;{item.certificate?.id}&lt;/td&gt;<br>                            &lt;td className=&quot;relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6&quot;&gt;<br>                              &lt;a target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot; href={`https://alfajores.celoscan.io/tx/${item.creationTx}`} className=&quot;text-forest hover:text-forest&quot;&gt;<br>                                ...{item.creationTx.substring(item.creationTx.length - 15)}<br>                              &lt;/a&gt;<br>                            &lt;/td&gt;<br>                          &lt;/tr&gt;<br>                        );<br>                      })}<br>                    &lt;/tbody&gt;<br>                  &lt;/table&gt;<br>                &lt;/div&gt;<br>              )<br>            }<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Add the list page into the header.tsx file and your “Retirement List Page” will look like this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OfkbUZayOx1NpGYLEvfdtQ.png" /><figcaption>image of the app with a list of retirements</figcaption></figure><p>Congratulations! You’ve build your first climate positive app. Now go explore more ways to build on Toucan in</p><ul><li>Toucan’s <a href="https://docs.toucan.earth/toucan/dev-resources/toucan-developer-resources">docs</a></li><li>Toucan’s <a href="https://github.com/ToucanProtocol/toucan-sdk">SDK</a></li><li>Toucan’s <a href="https://blog.toucan.earth/">blog</a></li><li><a href="https://github.com/GigaHierz/retire-carbon-credits-celo">Complete code of this Tutorial</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FnMzwfTuay8LBLRWQWN%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FnMzwfTuay8LBLRWQWN%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FnMzwfTuay8LBLRWQWN%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/4802fbb24b19705204606f615904d546/href">https://medium.com/media/4802fbb24b19705204606f615904d546/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=698826c81ef7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Discovering Toucan with GigaHierz]]></title>
            <link>https://medium.com/@hierzilena/discovering-toucan-with-gigahierz-6f3b757e1c96?source=rss-3a2a2750c335------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f3b757e1c96</guid>
            <category><![CDATA[carbon-offset]]></category>
            <category><![CDATA[carbon-credits]]></category>
            <category><![CDATA[regenerative-finance]]></category>
            <dc:creator><![CDATA[GigaHierz]]></dc:creator>
            <pubDate>Sat, 01 Apr 2023 08:12:50 GMT</pubDate>
            <atom:updated>2023-04-01T08:12:50.992Z</atom:updated>
            <content:encoded><![CDATA[<h4>Get ready to spread your wings and explore Toucan with me — And don’t worry, this read is carbon-neutral, so you won’t have to account for it. But you’ll learn how to anyways…</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6wiyRjadmkzuwy0jC_sdSA.png" /></figure><p>If you have been following my journey into Web3 in the past couple of years, you know the underlying purpose of my work has been to diversify infrastructure and enable impact-full projects, so that we avoid the array of bias that has been built into Web2. Entering the space, I loved learning about topics of governance and <a href="https://blog.toucan.earth/what-is-refi-regenerative-finance/">Regenerative Finance</a>, because they felt very tangible, and, in my experience, this makes them one of the best topics to onboard people (especially blockchain-skeptical people) into Web3. In this realm, Toucan has become one of my favorite examples.</p><p><a href="https://blog.toucan.earth/what-is-refi-regenerative-finance/">What is ReFi | Regenerative Finance explained</a></p><p>Much has been said about Blockchain, regarding the <a href="https://blog.toucan.earth/crypto-is-good-for-the-planet/">environmental impact of blockchain </a>technology due to its energy-intensive nature. Toucan has been an antagonist in this narrative, establishing a Web3 infrastructure for carbon markets, building a technology that will unlock climate action at scale. Their digital infrastructure is helping the voluntary carbon market (VCM)<a href="http://toucan-25208654.hs-sites-eu1.com/regenerate-4?ref=toucan-protocol"> grow with transparency and high integrity</a>.</p><p>Over the past month, two very good things happened that brought me to write this article. I got the opportunity to work for Toucan as a Developer Advocate (huge shoutout to my friend Doris Hernandez who introduced me to this amazing team), which brings together so many areas of interest of mine, like the environment, education, infrastructure and building. Parallel to that, I got accepted as a Scholar to the <a href="https://twitter.com/DevrelUni">DevRel University</a> program, founded by Bianca Buzea an absolute Developer Relations Hero.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fgd0Dqg6rYhttBVCZqd%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fgd0Dqg6rYhttBVCZqd%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fgd0Dqg6rYhttBVCZqd%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="362" frameborder="0" scrolling="no"><a href="https://medium.com/media/12e635f5fcb176ec2bc72164d90e918a/href">https://medium.com/media/12e635f5fcb176ec2bc72164d90e918a/href</a></iframe><p>One of our exercises is to do an overview of a protocol we like. So here you go, my sweet readers. Enjoy getting to know Toucan.</p><p>Disclaimer: In this article, I will use terms specific to ReFi and specifically decentralized voluntary carbon markets (DVCM). If you are new to Web3 and Carbon Markets check out <a href="https://blog.toucan.earth/dvcm-terms-explained/">this guide</a> provided by Toucan, where they explain the key terms.</p><p><a href="https://blog.toucan.earth/dvcm-terms-explained/">Explaining important terms of the digital VCM | Toucan</a></p><h3>What is Toucan?</h3><p>Like many great projects, Toucan was born out of a hackathon idea. (So kids, in case you never participated in a hackathon, this is your sign. Especially if you have a great idea like this). The aim of the protocol is to create infrastructure to make carbon markets more transparent and efficient. Among Toucan’s achievements, it has become a true conference hero, offsetting 1,400 tonnes of nature-based carbon on-chain for ETHAmsterdam emissions¹. And at ETH Barcelona they were offsetting the whole event, to make the conference carbon-neutral².</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*YZskHgZ0SKECmHpQegtejA.png" /><figcaption>ETH Barcelona’s announcement, being carbon neutral</figcaption></figure><p>But more on its glory and fame later. Let’s get to the nitty gritty. Toucan has three main infrastructure tools:</p><p>1. <strong>Toucan Carbon Bridge</strong></p><p>2. <strong>Open Climate Registry (OCR)</strong></p><p>3. <strong>Toucan Carbon Pools</strong>³</p><p>Apart from that, there is an emerging ecosystem of projects building on top of or with Toucan’s infrastructure, like <a href="https://blog.toucan.earth/neutral-protocol/">Neutral</a>, <a href="https://blog.toucan.earth/return-protocol/">Return</a>, <a href="https://blog.toucan.earth/spirals/">Spirals</a> and <a href="https://blog.toucan.earth/senken/">Senken</a>.</p><h4>What problems is Toucan trying to solve with these products?</h4><ul><li>prevent double counting of carbon credits: through tokenizing the carbon credits, it is transparently visible for everyone which credits have already been retired (used). This makes fraudulent double-claims or reselling of retired credits more difficult.</li><li>fragmentation, lack of price discovery, confusing standards, numerous different registries and poor liquidity in carbon markets: The innovation of Carbon Pools solves problems intrinsic to conventional carbon markets⁴.</li><li>Shortening time of credit retiring² : Toucans infrastructure tools make it easier to retire, as well as to retire small amounts (“fractional” retirements), and to automate retirement.</li></ul><h4>What chain is Toucan built on top of?</h4><p>Toucan launched on Polygon, but the goal is to create a multi-chain carbon future. Last year in April, they announced their partnership with Celo⁵, in August they deployed their protocol on Celo⁶. And since last week you can also retire carbon credits on Celo⁷. 🎊</p><p>“Celo is the carbon-negative, mobile-first, EVM-compatible blockchain ecosystem leading a thriving new digital economy for all.”</p><h3>Going deeper!</h3><p>Great. We now have an idea of what Toucan does. But how does this work in detail?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FpDWtwK7D2IlFu%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fpool-diving-synchronized-swimming-pDWtwK7D2IlFu&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNzE2ODNjMGIyMjI1Yzk3MzY2ZTEyODA1OGMzNDRjMTUxOWU3M2IyOSZjdD1n%2FpDWtwK7D2IlFu%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="288" frameborder="0" scrolling="no"><a href="https://medium.com/media/1106f4dae2a114590b55f34a46043f3a/href">https://medium.com/media/1106f4dae2a114590b55f34a46043f3a/href</a></iframe><h4>1. Tokenizing credits</h4><p>Toucan provides infrastructure to tokenize carbon credits from traditional registries onto the blockchain. This makes access to buying, selling and trading of them way easier to people that are not carbon-brokers or traders. So now it’s way easier for us to account for our carbon-footprint if we would like to. More in the section below. But tokenisation not only makes carbon credits more accessible but also more transparent and efficient in comparison to traditional VCMs⁸.</p><h4>2. Pools</h4><p>Carbon markets have had some intrinsic problems: fragmentation, lack of price discovery, and poor liquidity.Toucan’s Carbon Pools address these. Here’s how: Most carbon certificates are very specific to the project they were created for. Which means that only the ones from the same vintage &amp; project are identical. This results in poor liquidity so it’s harder to trade. As a solution Toucan introduces carbon pools, and categorizes the certificates by clustering them according to similar attributes For example, the Nature Carbon Pool only accepts carbon tokens that are created with nature-based methodologies — tokens held in this pool back NCT, the Nature Carbon Tonne⁸.</p><h4>3. Open Climate Registry</h4><p>The <a href="https://docs.toucan.earth/toucan/bridge/tco2-toucan-carbon-tokens">TCO2 contracts</a> deployed on-chain create a standardized meta-registry of carbon credits. It enables carbon markets to scale faster, standards bodies to able to monitor market activity better, credit developers to have a better basis for negotiating prices, and buyers to make informed purchase decisions³.</p><p>In a long-term vision, this opens the possibility of introducing new ways to verify carbon credits.</p><h3>And what can I do with it?</h3><p>I learn best with practical examples. So here is the simplest way you can use Toucan. For example you can calculate your carbon footprint for your last travels or your current energy consumption and then very easily retire amount of carbon certificates that is equivalent to that.</p><p>For best results and less frustration, I highly recommend having <a href="https://blog.toucan.earth/toucan-9-faqs/">this glossary</a> at hand!</p><p><a href="https://blog.toucan.earth/toucan-9-faqs/">Toucan FAQs | Tokenizing carbon credits</a></p><h4>Retiring credits on-chain has the following benefits:</h4><ul><li>Publicly verifiable</li><li>No double-counting of credits</li><li>Immediate³</li></ul><p>Learn how to purchase pool tokens, redeem and retire them in this video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8BPck0uoMIU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8BPck0uoMIU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8BPck0uoMIU%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/18a0bfafebc89af2e928d502e47067c9/href">https://medium.com/media/18a0bfafebc89af2e928d502e47067c9/href</a></iframe><p>Additionally, other projects have expanded on Toucan’s infrastructure — for example by building freely accessible carbon credit marketplaces, transparent climate impact reporting dashboards, or software that automatically compensates for a companies’ or individuals’ emissions³.</p><h3>Controversy:</h3><p>When introducing Toucan, it is important to address certain controversies that were discussed last year. Wired¹⁵ and Bloomberg¹⁶ wrote about several points that led them to question the impact of bringing carbon offset certificates on-chain.</p><h4>General Blockchain energy efficiency</h4><p>One of the blockchains, that Toucan is built on, is Polygon isn’t as carbon neutral as advertised, as it is a L2 to the Ethereum blockchain and through that would still have higher pollution. This problem has first been solved by Ethereum switching from Proof of Work (PoW) to Proof of Stake (PoS). And as mentioned earlier Toucan is now also building on Celo, a carbon-negative Blockchain.</p><h4>Cheap/old certificates</h4><p>Another topic raised in Wired¹⁵ and Bloomberg¹⁶ was that a lot of the carbon Credits that have been bridged from Verra are low quality and/or old.</p><p>It is important to highlight here that Toucan is an infrastructure provider for tokenizing carbon credits and creating carbon credit pools. And the standards for these are being developed by other entities. Through providing these infrastructure tools, Toucan supports these entities in enforcing them, like providing a filter to prevent the tokenisation of HFC-23 (link to docs) or zombie credits.</p><p>Toucan has developed a mechanism to consistently clean up the pools. When redeeming for example NCTs for TCO2 (which you need for example when you want to retire carbon credits) the user can choose between auto redeeming, in which case the lowest tokens form the pool will be redeemed or the user can choose which one they want to redeem. For the second option Toucan takes a fee out of which a percentage is used to retire the lowest quality carbon credits. You can read more on this in the <a href="https://blog.toucan.earth/toucan-nct-burn-report-vol-2/">Toucan Burn Reports</a> and <a href="https://docs.toucan.earth/toucan/pool/protocol-fees">Toucans Documentation</a>.</p><h4>Tokenization of Carbon Credits has been halted</h4><p>In April 2022, Verra prohibited tokenizing carbon credits from their registry, with one of the arguments being that buyers and sellers can remain anonymous. Another one was concerns with double-counting and price-fluctuation Over the last year, a discussion has happened around this and, in January 2023, Verra published a 170-page document outlining the results of a consultation of over 70 other organizations, with formulated opinions and questions that Toucan summarizes in <a href="https://blog.toucan.earth/verra-consultation-summary/">this article</a> the keypoints, with topics including, a focus on safety and compliance, KYC measures and “de-bridging”.</p><p>To the claim that on-chain markets have been killed through this ban, Toucan responded that while new on-chain certificates are not being issued, the use of the ones that are already on-chain has been growing. Additionally, these events have brought on-chain carbon markets into focus and kickstarted the launch of numerous working groups aiming to identify the best way forward¹².</p><p>I want to finish this blog post off with a quote from Toucan’s Blog about the current state of the carbon market which also gives a little outlook to what’s to come:</p><p><em>“In the past years, experts with the right intentions and understanding of the complexities of the market have started looking at solutions to key challenges, like lack of transparency and integrity, as well as accounting issues, such as double counting. So far, the market has been lacking technologies that can help address these issues and reduce integrity risks. But this is changing rapidly. Some organizations, like ourselves at Toucan, focus on building infrastructure for more efficient, open and transparent markets. Others are working on carbon credit integrity ratings (ie.</em><a href="https://bezerocarbon.com/?ref=toucan-protocol"> <em>BeZero</em></a><em>,</em><a href="https://www.sylvera.com/?ref=toucan-protocol"> <em>Sylvera</em></a><em>,</em><a href="https://www.gainforest.app/?ref=toucan-protocol"> <em>Gainforest</em></a><em>), or drive the implementation of digital Measurement, Verification and Reporting (DMRV) forward (ie.</em><a href="https://pachama.com/?ref=toucan-protocol"> <em>Pachama</em></a><em>). We are also excited by the growing role of claims label certifiers for well-intentioned corporates — these add extra scrutiny to net-zero claims.”</em>¹²</p><p>So looking forward, I am excited for the next month to be working with Toucan. Seeing how much is happening in the carbon credit space right now, and being part of making this crucial infrastructure accessible will be very fulfilling.</p><p>The energy used to write this article has been offset. You can find the transaction on <a href="https://celoscan.io/tx/0x136c3be360f34713219d55e4343e7e8b100833d6783eeeca7abb31710b1d228c">Celoscan</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*S8DtiaW-wNfiK8Kkl0QC-w.png" /><figcaption>retirement certificate</figcaption></figure><h3>Learn more:</h3><ul><li>Check out the <a href="https://docs.toucan.earth/toucan/introduction/readme">Toucans Docs</a></li><li>Look into <a href="https://blog.toucan.earth/tag/decarbonized/"><strong>deCarbonized</strong></a><strong>: Toucan’s blog to demistify carbon markets</strong></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3otPom9hhC5MHfBmIo%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3otPom9hhC5MHfBmIo%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3otPom9hhC5MHfBmIo%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="184" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae8e55275aa6d813eca50437097b9c42/href">https://medium.com/media/ae8e55275aa6d813eca50437097b9c42/href</a></iframe><h3>References:</h3><ol><li>Toucan |<a href="https://medium.com/@ToucanProtocol/toucan-offset-ethamsterdam-emissions-506df8223c84"> </a><a href="https://blog.toucan.earth/climate-action-for-ethamsterdam/"><strong>Climate action for ETHAmsterdam</strong></a><strong> | 29.04.2022</strong></li><li>Toucan | <a href="https://blog.toucan.earth/ethbarcelona-carbon-neutral-conference/"><strong>ETHBarcelona — How to execute an environmentally-friendly conference</strong></a> <strong>| 29.06.2022</strong></li><li>Toucan |<a href="https://blog.toucan.earth/toucan-9-faqs/"> <strong>We’re answering 9 questions about Toucan</strong></a> | <strong>17.02.2023</strong></li><li>Toucan |<a href="https://blog.toucan.earth/base-carbon-tonne-bct-a-new-web3-building-block/"> <strong>Base Carbon Tonne (BCT): a new Web3 building block</strong></a> | <strong>04.01.2022</strong></li><li>Toucan |<a href="https://blog.toucan.earth/toucans-carbon-ecosystem-celo/"> <strong>Toucan’s carbon ecosystem is coming to Celo! 🎉</strong></a> <strong>| 05.04.2022</strong></li><li>Toucan |<a href="https://blog.toucan.earth/blog-toucan-earth-toucan-live-on-celo/"> <strong>Toucan is live on Celo!</strong></a> <strong>| 10.08.2022</strong></li><li>Toucan | <a href="https://blog.toucan.earth/carbon-retirements-on-celo/"><strong>Toucans carbon retirement module launches on Celo</strong></a> | 31.03.2023</li><li>Toucan | <a href="https://blog.toucan.earth/tokenization-of-carbon-credits-explained/#vcm"><strong>Tokenization of carbon credits — an explainer</strong></a><strong> </strong>| <strong>01.12.2023</strong></li><li>Toucan |<a href="https://docs.toucan.earth/toucan/bridge/tco2-toucan-carbon-tokens"> <strong>Introducing NCT: Nature Carbon Tonne</strong></a> <strong>| 08.02.2022</strong></li><li>Toucan |<a href="https://blog.toucan.earth/toucan-nct-burn-report-vol-2/"> <strong>Toucan Burn Report Vol 2 — supporting the cleanup of the BCT pool 🌍</strong></a> <strong>| 21.09.2022</strong></li><li>Toucan |<a href="https://blog.toucan.earth/verra-consultation-summary/"> <strong>Moving forward: a look at Verra’s public consultation summary</strong></a> <strong>| 19.01.2023</strong></li><li>Toucan |<a href="https://blog.toucan.earth/dispelling-5-myths-about-tokenized-carbon/"> <strong>Dispelling 5 myths about tokenized carbon 🔮</strong></a> <strong>| 22.08.2022</strong></li><li>Toucan |<a href="https://blog.toucan.earth/how-to-retire-nature-based-carbon/"> <strong>How to retire nature-based carbon credits with Toucan</strong></a> <strong>| 12.04.2022</strong></li><li>Toucan |<a href="https://blog.toucan.earth/how-to-buy-nct-on-sushi/"> <strong>How to buy NCT on SushiSwap</strong></a> <strong>| 10.04.2022</strong></li><li>Wired |<a href="https://www.wired.co.uk/article/toucon-crypto-carbon-credits"> <strong>A Crypto Company Thinks It Can Help Fight Climate Change</strong></a> <strong>| 17.02.2022</strong></li><li>Bloomberg |<a href="https://www.bloomberg.com/news/articles/2022-04-07/the-biggest-crypto-effort-to-end-useless-carbon-offsets-is-backfiring"> <strong>The Biggest Crypto Effort to End Useless Carbon Offsets Is Backfiring</strong></a> | 07.04.2022</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f3b757e1c96" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>