Socket
Socket
Sign inDemoInstall

ethereum-emissions-calculator

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereum-emissions-calculator - npm Package Compare versions

Comparing version 3.0.2-beta to 3.0.2

8

lib/data/emissionsFactorTable.json

@@ -747,9 +747,9 @@ [

{
"timestamp": 1661990400,
"emissionsFactor": 0.0002473976222064128
"timestamp": 1663200000,
"emissionsFactor": 0.0002522790155063084
},
{
"timestamp": 1663259101,
"emissionsFactor": 0.0000001
"timestamp": 1663286400,
"emissionsFactor": 0.0
}
]
import { EmissionsFactor, TransactionData } from "../types";
/** returns [emissionsInKGCO2, gasUsed] */
/**
* for each txn, finds the entry in emissions factor table
* (where the timestamp is greater than or equal to txn timestamp)
* @returns [emissionsInKGCO2, gasUsed]
*/
export declare const getTransactionEmissions: (txns: TransactionData[], emissionsFactorTable: EmissionsFactor[]) => [number, number];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTransactionEmissions = void 0;
/** returns [emissionsInKGCO2, gasUsed] */
/**
* for each txn, finds the entry in emissions factor table
* (where the timestamp is greater than or equal to txn timestamp)
* @returns [emissionsInKGCO2, gasUsed]
*/
const getTransactionEmissions = (txns, emissionsFactorTable) => {
let datePointer = 0;
return txns.reduce((prev, tx) => {
const txnIsOlder = parseInt(tx.timeStamp) > emissionsFactorTable[datePointer].timestamp;
while (txnIsOlder) {
// if the timestamp is older, try the next entry
while (parseInt(tx.timeStamp) > emissionsFactorTable[datePointer].timestamp) {
if (datePointer === emissionsFactorTable.length - 1) {

@@ -15,9 +19,9 @@ break;

}
const txnEmissions = parseInt(tx.gasUsed) *
emissionsFactorTable[datePointer].emissionsFactor;
const sum = prev[0] + txnEmissions; // danger, floating point errors 0.30000000000000004
const val = [
prev[0] +
parseInt(tx.gasUsed) *
emissionsFactorTable[datePointer].emissionsFactor,
Number(sum.toFixed(3)),
prev[1] + parseInt(tx.gasUsed),
];
console.log("fetched value", val, tx.timeStamp, emissionsFactorTable[datePointer].timestamp, emissionsFactorTable[datePointer].emissionsFactor);
return val;

@@ -24,0 +28,0 @@ }, [0, 0]);

{
"name": "ethereum-emissions-calculator",
"version": "3.0.2-beta",
"version": "3.0.2",
"description": "TypeScript utils to calculate the CO2 emissions of an Ethereum wallet. Powered by the Etherscan.io API.",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc