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.
npm run build
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) });
import { getCo2kenSupply } from "eth-co2";
let supply = await getCo2kenSupply(provider);
import { getCo2kenPaymentsBalance } from "eth-co2";
let balance = await getCo2kenPaymentsBalance(provider);
import { offsetCarbon } from "eth-co2";
await offsetCarbon(provider, dai);
import { getFootprint } from "eth-co2";
let gasFootprint = await getFootprint(provider); // CO2 emissions per gas
let emissions = gasUsed * gasFootprint;
let offsetCost = emissions * co2kenPrice;
import { estimateEmissions } from "eth-co2";
let emissions = await estimateEmissions(provider, contractName, functionName);