Sign In

eth-co2

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eth-co2

Carbon offsetting on Ethereum via web3

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

eth-co2

eth-co2.js is a JavaScript library to enable offsetting of CO2 emissions via the Ethereum blockchain. It is part of the CO2ken project. More information is available in our introductory blog post. You can also follow us on Twitter.

N.B. This library is currently pre-alpha, and currently only usable on the Rinkeby network! If you are interested in using it, please let us know.

Building

npm run build

Example usage

Calculating the cost of offsetting CO2 emissions

For example, to calculate the cost of offsetting a flight from London to New York:

import "babel-polyfill";
import { ethers } from "ethers";

import { getCO2kenPrice } from "eth-co2";

const dapp = async () => {
  let provider = new ethers.providers.Web3Provider(web3.currentProvider);
  window.price = await getCO2kenPrice(provider);
  let flightEmissions = 500;  // approx kg CO2 emissions from LON -> NYC flight
  let co2kenPrice = await getCO2kenPrice(web3);  // Cost in DAI to offset 1 ton of CO2
  let offsetCost = flightEmissions / 1000 * co2kenPrice;
};

dapp().catch(e => { console.error(e) });

Check total supply of CO2kens

import { getCo2kenSupply } from "eth-co2";

let supply = await getCo2kenSupply(provider);

Check total balance of payments to CO2ken contract

import { getCo2kenPaymentsBalance } from "eth-co2";

let balance = await getCo2kenPaymentsBalance(provider);

Pay DAI to offset carbon emissions

import { offsetCarbon } from "eth-co2";

await offsetCarbon(provider, dai);

Obtain gas footprint

import { getFootprint } from "eth-co2";

let gasFootprint = await getFootprint(provider);  // CO2 emissions per gas

Estimate emissions from a transaction

let emissions = gasUsed * gasFootprint;
let offsetCost = emissions * co2kenPrice;

Wrap it all up for convenience

import { estimateEmissions } from "eth-co2";

let emissions = await estimateEmissions(provider, contractName, functionName);

Keywords

carbon

FAQs

Package last updated on 31 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts