zerocarbon-nodejs-sdk
v2.0.0
Published
Official Node.js SDK for ZeroCarbon.codes API
Maintainers
Readme
ZeroCarbon Node.js SDK
Official Node.js/TypeScript client for ZeroCarbon.codes - India's leading Carbon Accounting & Offsetting API.
Installation
npm install @zerocarbon/sdk
# or
yarn add @zerocarbon/sdkQuick Start
const { ZeroCarbon } = require('@zerocarbon/sdk');
// Initialize client
const client = new ZeroCarbon({ apiKey: 'YOUR_API_KEY' });
// Calculate flight emissions
const emissions = await client.calculate.flight({
origin: 'DEL',
destination: 'BOM',
cabinClass: 'economy'
});
console.log(`Emissions: ${emissions.emissions_kg_co2e} kg CO2e`);
// Get offset recommendations
const offsets = await client.offsets.getRecommendations({
emissionsKgCo2e: emissions.emissions_kg_co2e,
preferredRegion: 'India'
});
console.log(`Top project: ${offsets.recommendations[0].name}`);
// Purchase and retire credits
const transaction = await client.offsets.purchase({
projectId: offsets.recommendations[0].project_id,
quantityKgCo2e: emissions.emissions_kg_co2e,
retirementReason: 'Business flight offsetting'
});
console.log(`Certificate: ${transaction.certificate_url}`);TypeScript Support
Full TypeScript support with type definitions included:
import { ZeroCarbon, FlightEmissions } from '@zerocarbon/sdk';
const client = new ZeroCarbon({ apiKey: 'YOUR_API_KEY' });
const emissions: FlightEmissions = await client.calculate.flight({
origin: 'DEL',
destination: 'BOM'
});Features
- ✅ Calculate emissions from flights, electricity, fuel, and more
- ✅ AI-powered spend-based emission matching
- ✅ Carbon offset recommendations
- ✅ Purchase and retire carbon credits
- ✅ Generate BRSR-compliant reports
- ✅ Webhook support
- ✅ Test mode for development
- ✅ Full TypeScript support
Examples
Calculate Electricity Emissions
const emissions = await client.calculate.electricity({
amountKwh: 1000,
country: 'IN',
state: 'Maharashtra'
});
// Returns: 820 kg CO2eSmart Spend Matching
const emissions = await client.calculate.spend({
amount: 100000,
currency: 'INR',
category: 'electricity',
description: 'Monthly office electricity bill'
});
// AI automatically matches to emission factorsGenerate BRSR Report
const report = await client.brsr.generateReport({
companyId: 'comp_123',
financialYear: '2024-25',
format: 'pdf'
});
console.log(report.download_url);Register Webhook
const webhook = await client.webhooks.register({
url: 'https://your-app.com/webhooks/carbon',
events: ['offset.completed', 'offset.failed']
});
console.log(`Webhook secret: ${webhook.secret}`);Test Mode
Enable test mode to avoid real charges:
const client = new ZeroCarbon({
apiKey: 'test_YOUR_API_KEY',
testMode: true
});Error Handling
try {
const emissions = await client.calculate.flight({
origin: 'DEL',
destination: 'BOM'
});
} catch (error) {
console.error('API Error:', error.message);
}License
MIT License - see LICENSE file for details.
Support
- Email: [email protected]
- Docs: https://docs.zerocarbon.codes
- GitHub: https://github.com/zerocarbon/nodejs-sdk
