A library that fetches the amount of ETH (and USD) transferred using the Ethereum Alarm Clock.
npm install eac-counter
import EacCounter from 'eac-counter';
const eacCounter = new EacCounter({
// Needed for fetching amount of USD transferred, get an API key from https://nomics.com/
nomicsApiKey: '<nomics_api_key>',
// Needed for fetching amount of ETH transferred, get an API key from https://etherscan.io/
etherscanApiKey: '<etherscan_api_key>',
});
// Optional: Needed to fetch the amount of USD transferred
await eacCounter.enableUSDFetching();
const { eth, usd } = await eacCounter.getTotalTransferred();
console.log(eth);
console.log(usd); // This will be null if enableUSDFetching() is not called
To use this library in the browser, download and import the browser-compatible file into your HTML file.
<script src="eac-counter.browser.js"></script>
This will expose the EacCounter
to the window object. You can then use the following code to fetch the counter:
const eacCounter = new EacCounter({
nomicsApiKey: '<nomics_api_key>',
etherscanApiKey: '<etherscan_api_key>',
});
eacCounter.enableUSDFetching().then(function () {
eacCounter.getTotalTransferred().then(function (value) {
console.log(value.eth);
console.log(value.usd);
});
});