Adapter

CoinMetrics - Fees, TX Count, Active Addresses

Sub-Adapters 14

Preview and test each sub adapter.

Ethereum (eth)

Bitcoin (btc)

Litecoin (ltc)

Cardano (ada)

Tezos (xtz)

Bitcoin SV (bsv)

Bitcoin Cash (bch)

Ripple (xrp)

Dogecoin (doge)

Monero (xmr)

Stellar (xlm)

Decred (dcr)

Zcash (zec)

Ethereum Classic (etc)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'CoinMetrics - Fees, TX Count, Active Addresses';
2export const version = '0.2.0';
3export const license = 'MIT';
4export const changeLog = 'Add additional metrics';
5
6export function setup(sdk: Context) {
7  const protocols = [
8    {
9      id: 'eth',
10      icon: sdk.ipfs.getDataURILoader('QmedJLPy6R7x3dDEy2cfMd8gXbZm9e3vxvgBLXp3YZEHCy', 'image/svg+xml'),
11      name: 'Ethereum',
12      description: 'Ethereum is the first blockchain for turing-complete smart contracts.',
13      feeDescription: 'Transaction fees are partially burnt and partially paid to miners.',
14      tokenTicker: 'ETH',
15      tokenCoingecko: 'ethereum',
16      website: 'https://ethereum.org',
17      blockchain: 'Ethereum',
18      source: 'CoinMetrics',
19      events: [
20        {
21          date: '2021-08-05',
22          description: 'London hard fork, including EIP-1559',
23        },
24      ],
25    },
26    {
27      id: 'btc',
28      icon: sdk.ipfs.getDataURILoader('QmerwCGnYE4DE9oe4a6hppgKRz2vvMdx1AuwvgFLgrdeh7', 'image/svg+xml'),
29      name: 'Bitcoin',
30      description: 'Bitcoin is the first decentralized cryptocurrency.',
31      feeDescription: 'Transaction fees are paid by users to miners.',
32      tokenTicker: 'BTC',
33      tokenCoingecko: 'bitcoin',
34      website: 'https://bitcoin.org',
35      source: 'CoinMetrics',
36    },
37    {
38      id: 'ltc',
39      icon: sdk.ipfs.getDataURILoader('QmQfWmmsfGDsVfgkjMwneB9MRgg8SEumgM7ZaGSP98ZsgW', 'image/svg+xml'),
40      name: 'Litecoin',
41      description: 'Litecoin is cryptocurrency based on a fork of the Bitcoin Core codebase.',
42      feeDescription: 'Transaction fees are paid by users to miners.',
43      website: 'https://litecoin.org',
44      source: 'CoinMetrics',
45      tokenTicker: 'LTC',
46      tokenCoingecko: 'litecoin',
47    },
48    {
49      id: 'ada',
50      icon: sdk.ipfs.getDataURILoader('QmbyTYm2BzcwgbRXoXXjihYT2mrwVPejFgKaJJXy6SHBRT', 'image/svg+xml'),
51      name: 'Cardano',
52      description: 'Cardano is a PoS blockchain which will support smart contracts in the future.',
53      feeDescription: 'Transaction fees are paid by users to validators.',
54      website: 'https://cardano.org',
55      source: 'CoinMetrics',
56      tokenTicker: 'ADA',
57      tokenCoingecko: 'cardano',
58      events: [
59        {
60          date: '2021-09-12',
61          description: 'Alonzo upgrade introduces smart contracts',
62        },
63      ],
64    },
65    {
66      id: 'xtz',
67      icon: sdk.ipfs.getDataURILoader('QmS1MvZJqD3CAxnos5t64HXtMsTh2SqXoWWndkL6dHVduW', 'image/svg+xml'),
68      name: 'Tezos',
69      description: 'Tezos is a PoS blockchain that supports smart contracts',
70      feeDescription: 'Transaction fees are paid by users to validators (bakers).',
71      website: 'https://tezos.com',
72      source: 'CoinMetrics',
73      tokenTicker: 'XTZ',
74      tokenCoingecko: 'tezos',
75    },
76    {
77      id: 'bsv',
78      icon: sdk.ipfs.getDataURILoader('QmPLRz1dZCbm2T5DeXrqULuqZU35TxcwYnbQFfN9GNiCf5', 'image/svg+xml'),
79      name: 'Bitcoin SV',
80      description: 'Bitcoin SV is a fork of the Bitcoin Cash blockchain',
81      feeDescription: 'Transaction fees are paid by users to miners.',
82      website: 'https://bitcoinsv.com',
83      source: 'CoinMetrics',
84      tokenTicker: 'BSV',
85      tokenCoingecko: 'bitcoin-cash-sv',
86    },
87    {
88      id: 'bch',
89      icon: sdk.ipfs.getDataURILoader('QmT1RaaEdJiJnyGMWLpHxamk3mhjrqoodAkjpD2wCxHeyS', 'image/svg+xml'),
90      name: 'Bitcoin Cash',
91      description: 'Bitcoin Cash is a fork of the Bitcoin blockchain',
92      feeDescription: 'Transaction fees are paid by users to miners.',
93      website: 'https://bitcoincash.org',
94      source: 'CoinMetrics',
95      tokenTicker: 'BCH',
96      tokenCoingecko: 'bitcoin-cash',
97    },
98    {
99      id: 'xrp',
100      icon: sdk.ipfs.getDataURILoader('QmYU37p3av9QDNLpG6sY2hiDDsVXewbovs9KtTzZAocasm', 'image/svg+xml'),
101      name: 'Ripple',
102      description: 'Ripple is a payment & settlment platform.',
103      feeDescription: 'Transaction fees are paid by users and burned.',
104      website: 'https://ripple.com',
105      source: 'CoinMetrics',
106      tokenTicker: 'XRP',
107      tokenCoingecko: 'ripple',
108    },
109    {
110      id: 'doge',
111      icon: sdk.ipfs.getDataURILoader('QmRpogZjZEKLX33245zT6QSiDENMb26fS922Ds6pp3VzE3', 'image/svg+xml'),
112      name: 'Dogecoin',
113      description: 'Dogecoin is a cryptocurrency based on the "Doge" meme.',
114      feeDescription: 'Transaction fees are paid by users to miners.',
115      website: 'https://dogecoin.com',
116      source: 'CoinMetrics',
117      tokenTicker: 'DOGE',
118      tokenCoingecko: 'dogecoin',
119    },
120    {
121      id: 'xmr',
122      icon: sdk.ipfs.getDataURILoader('QmWVPtKiQYo2up8ewEzGWLWRZHRNcQLn5U38NFBGm7X6cd', 'image/svg+xml'),
123      name: 'Monero',
124      description: 'Monero is a privacy-focused cryptocurrency.',
125      feeDescription: 'Transaction fees are paid by users to miners.',
126      website: 'https://getmonero.org',
127      source: 'CoinMetrics',
128      tokenTicker: 'XMR',
129      tokenCoingecko: 'monero',
130    },
131    {
132      id: 'xlm',
133      icon: sdk.ipfs.getDataURILoader('QmZJAgQbxghu7c47wnY7eqPhFBHcwZedp5ZqA99wEm92UK', 'image/svg+xml'),
134      name: 'Stellar',
135      description: 'Stellar is global payment network.',
136      feeDescription: 'Transaction fees are paid by users into a pool.',
137      website: 'https://stellar.org',
138      source: 'CoinMetrics',
139      tokenTicker: 'XLM',
140      tokenCoingecko: 'stellar',
141    },
142    {
143      id: 'dcr',
144      icon: sdk.ipfs.getDataURILoader('QmTSz4gXBzNeLPQKdEJTVaAjcH68E39uvkgTUCKwcK44VT', 'image/webp'),
145      name: 'Decred',
146      description: 'Decred aims to build a community-directed digital currency.',
147      feeDescription: 'Transaction fees are paid by users to miners.',
148      website: 'https://www.decred.org/',
149      source: 'CoinMetrics',
150      tokenTicker: 'DCR',
151      tokenCoingecko: 'decred',
152    },
153    {
154      id: 'zec',
155      icon: sdk.ipfs.getDataURILoader('QmXmNpmiDTrAWxJq3ZQmVS3BJkb2WLiaLp1VYs4pWGwRD1', 'image/webp'),
156      name: 'Zcash',
157      description: 'Zcash is a decentralized and open-source cryptocurrency that offers privacy and selective transparency of transactions.',
158      feeDescription: 'Transaction fees are paid by users to miners.',
159      website: 'https://z.cash/',
160      source: 'CoinMetrics',
161      tokenTicker: 'ZEC',
162      tokenCoingecko: 'zcash',
163    },
164    {
165      id: 'etc',
166      icon: sdk.ipfs.getDataURILoader('QmNywrrDCXW76wbhG75jAiDWBpEb15riAscadrzxtMrrjn', 'image/svg+xml'),
167      name: 'Ethereum Classic',
168      description: 'Ethereum Classic is an open source, blockchain-based distributed computing platform featuring smart contract functionality. It supports a modified version of Nakamoto consensus via transaction-based state transitions executed on a public Ethereum Virtual Machine.',
169      feeDescription: 'Transaction fees are paid by users to miners',
170      website: 'https://ethereumclassic.org/',
171      source: "CoinMetrics",
172      tokenTicker: 'ETC',
173      tokenCoingecko: 'ethereum-classic',
174    }
175  ];
176
177
178  const getOneDayMetricCount = (metric: string, id: string) => async (date: string) => {
179    const result = await sdk.http.get(`https://community-api.coinmetrics.io/v4/timeseries/asset-metrics?page_size=10000&metrics=${metric}&assets=${id}&start_time=${date}&end_time=${date}`);
180
181    if (!result.data[0]) {
182      throw new Error(`Failed to fetch CoinMetrics data for ${id} on ${date}`);
183    }
184
185    return parseFloat(result.data[0][metric]);
186  }
187
188  const getFeeRangeQuery = (id: string) => async (startDate: string, endDate: string) => {
189    const result = await sdk.http.get(`https://community-api.coinmetrics.io/v4/timeseries/asset-metrics?page_size=10000&metrics=FeeTotUSD&assets=${id}&start_time=${startDate}&end_time=${endDate}`);
190
191    if (!result.data[0]) {
192      throw new Error(`Failed to fetch CoinMetrics data for ${id} on ${startDate}`);
193    }
194
195    let totalFees = 0;
196    // return endDate
197    // We skip the last value, since CoinMetrics date queries include the
198    // last date, but CryptoStats skips it
199    for (let i = 0; i < result.data.length - 1; i += 1) {
200      totalFees += parseFloat(result.data[i].FeeTotUSD);
201    }
202
203    return totalFees;
204  }
205
206  for (const protocol of protocols) {
207    const { id, ...metadata } = protocol;
208    sdk.register({
209      id,
210      queries: {
211        oneDayTotalFees: getOneDayMetricCount('FeeTotUSD', id),
212        dateRangeTotalFees: getFeeRangeQuery(id),
213        txCountOneDay: getOneDayMetricCount('TxCnt', id),
214        activeAddressesOneDay: getOneDayMetricCount('AdrActCnt', id),
215      },
216      metadata: {
217        category: 'l1',
218        ...metadata,
219      },
220    });
221  }
222}
223

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.2.0

License

MIT

IPFS CID

QmddHyDF6FJEvVqrCmJX6hJp8z7PLWfbb8aREnp1MZjy9e

CID (source)

QmSrsT5ShEqTjg63hDm3HP3bnMrA64JNhrHjJqczmgXwio

Author

mihal.eth