🟒
Filecoin Green Documentation
  • πŸ“—Filecoin Green Documentation
  • ♻️Storage Providers Green Guidance Documentation
    • 🌐Introduction
    • 🌍Filecoin Green
      • πŸ”±Filecoin Green Pledge
    • πŸ“‘Storage Provider’s Tiered Sustainability Claims
    • πŸ“‹Storage Providers Sustainability Criteria
      • GHG Emissions Accounting
        • How Storage Providers should Calculate Emissions
      • Renewable Energy Procurement
        • How Storage Providers should Procure Renewable Energy
          • Renewable Electricity Sourcing Methods
            • Spotlight: DCENT
          • Additional methods for procuring renewable energy
            • Spotlight: Zero Labs
          • Credible Claims Requirements
          • Energy Sources and Technologies
      • Additional Reporting Criteria and Reporting Cadence
        • Water Use
        • Hardware Waste
        • Reporting Periods and Cadence
    • πŸ”†Conclusion
    • πŸ—ƒοΈAdditional Resources
      • Annex 1: Carbon Accounting Methodologies Hierarchy
      • Annex 2: Details on Storage Provider’s Tiered Sustainability Claims
      • Annex 3: Filecoin Green Reporting Portal
      • Annex 4: Treatment of Carbon Credits
  • βš™οΈFilecoin Green API Docs
    • πŸ”§List of APIs
      • ⚑Energy Consumption API
      • 🌿Green Scores API
      • πŸ“ˆRenewable Energy Certificates API
      • ↔️Filecoin Miner ID <-> Peer ID relation API
  • πŸ–₯️Filecoin Green UI Tools
    • πŸ”CID.place
    • πŸ“ƒREC Browser
    • πŸ“ˆMetered Energy Consumption
    • πŸ“©CSV Export utility
    • πŸ‘ΎCO2.Storage
  • πŸ“šAdditional Resources
  • πŸ‘ΎCO2.Storage Docs
    • 🧐About
    • βš™οΈData Model
    • βš’οΈUI: Getting Started
    • πŸ—οΈSetting Up the CLI
    • ✍️Template Author's Guide
    • πŸ’₯Examples
    • 🌱Build a Web UI
    • πŸ–₯️UI Functionality
    • ⌨️API Functionality
    • πŸŽ†Configuring IPFS Nodes
    • ‼️FAQ
    • πŸ—ΊοΈDevelopment Roadmap
    • πŸ—»Decarbonize Your Travel
    • πŸ’‘Energy Validation Process (EVP) Schema
Powered by GitBook
On this page
  1. CO2.Storage Docs

Build a Web UI

PreviousExamplesNextUI Functionality

Last updated 2 years ago

In this tutorial, we walk through how to set up a React app incorporating CO2.storage. Unlike in the previous tutorial, where you set up your credentials in a .env file, in this case the user will authenticate with their own browser extension wallet.

1) In the folder where you want the project, run:

npm init react-app demo-app

This will make a new demo-app subfolder with React installed.

2) Navigate to that folder using cd demo-app and check that React is working by starting the web app:

npm run start

You should see your app when you go to

3) In the app folder, install the latest co2-storage javascript package by running:

npm install @co2-storage/js-api@latest --save

Now in demo-app/package.json you should see co2-storage/js-api listed under dependencies:

...
"dependencies": {
    "@co2-storage/js-api": "^X.Y.Z",
    ...

Where X.Y.Z is the version installed (at time of writing, 1.2.2).

4) We can now copy code from the in order to bring CO2.Storage functionality to our web app!

Open demo-app/src/App.js and near the top add this import statement and these constants:

import { FGStorage } from '@co2-storage/js-api';

const authType = "metamask"
const ipfsNodeType = "browser"
const ipfsNodeAddr = "/dns4/web2.co2.storage/tcp/5002/https"
const fgApiUrl = "https://web2.co2.storage"

const fgStorage = new FGStorage({authType: authType, ipfsNodeType: ipfsNodeType, ipfsNodeAddr: ipfsNodeAddr, fgApiHost: fgApiUrl})

Here, we are:

  • Importing the package

  • Using the metamask browser plugin for authentication

  • Running an ipfs node locally in the web browser and using this to pin and retrieve files

  • Connecting to other ipfs nodes running co2-storage

  • Instantiating a FGStorage object

5) For example, if we want to add a button that searches templates we can add this to the HTML in App.js:

<button onClick={SearchTemplates}>search</button>
async function SearchTemplates(){

  /**
   * Search templates
   * parameters: (chainName, phrases, cid, name, base, account, offset, limit, sortBy, sortDir)
   * // default data_chain: 'sandbox', phrases: null, cid: null, name: null, base: null, account: null, offset: 0, limit: 10
   */

  let searchTemplatesResponse = await fgStorage.searchTemplates('sandbox')    // ('SP Audits', 'Water')
  if(searchTemplatesResponse.error != null) {
      console.error(searchTemplatesResponse.error)
      // await new Promise(reject => setTimeout(reject, 300));
      // process.exit()
  }

  console.log(searchTemplatesResponse.result)

}

When you go to your browser console, this should cause the results of the search to be returned.

And add the SearchTemplates function below, copying from the example:

πŸ‘Ύ
🌱
http://localhost:3000/
examples repo folder
search_templates.js