|
| 1 | +import { MessariClient } from "@messari-kit/api"; |
| 2 | +import { printTable } from "console-table-printer"; |
| 3 | +import type { getExchangeRecapParameters, getProjectRecapParameters } from "@messari-kit/types"; |
| 4 | +import dotenv from "dotenv"; |
| 5 | + |
| 6 | +// Load environment variables from .env file |
| 7 | +dotenv.config(); |
| 8 | + |
| 9 | +// Get API key from environment variable |
| 10 | +const API_KEY = process.env.MESSARI_API_KEY; |
| 11 | + |
| 12 | +// Check if API key is available |
| 13 | +if (!API_KEY) { |
| 14 | + console.error("Error: MESSARI_API_KEY environment variable is not set."); |
| 15 | + console.error("Please create a .env file with your API key or set it in your environment."); |
| 16 | + process.exit(1); |
| 17 | +} |
| 18 | + |
| 19 | +// Initialize the Messari client |
| 20 | +const client = new MessariClient({ |
| 21 | + apiKey: API_KEY, |
| 22 | + // Optional: Override the base URL if needed |
| 23 | + // baseUrl: "https://api.messari.io", |
| 24 | +}); |
| 25 | + |
| 26 | +async function main() { |
| 27 | + // Get preview of available reports |
| 28 | + try { |
| 29 | + const previews = await client.diligence.getDiligencePreview(); |
| 30 | + console.log("\n--------------------------------"); |
| 31 | + console.log("Diligence Previews"); |
| 32 | + console.log("--------------------------------"); |
| 33 | + const rows = []; |
| 34 | + for (const preview of previews) { |
| 35 | + if (rows.length > 5) break; |
| 36 | + rows.push({ |
| 37 | + "AssetId": preview.assetId, |
| 38 | + "LastUpdated": preview.lastRevisedAt, |
| 39 | + "Project": preview.projectName, |
| 40 | + "Sector": preview.sector, |
| 41 | + }); |
| 42 | + } |
| 43 | + printTable(rows); |
| 44 | + } catch (error) { |
| 45 | + console.error("Error calling getDiligencePreview:", error); |
| 46 | + } |
| 47 | + |
| 48 | + // Get a report by asset ID |
| 49 | + try { |
| 50 | + const virtualsAssetId = "4eb07099-9d91-4318-a63f-6672e191ef43"; |
| 51 | + const report = await client.diligence.getDiligenceReport({ assetId: virtualsAssetId }); |
| 52 | + console.log("\n--------------------------------"); |
| 53 | + console.log("Diligence Report"); |
| 54 | + console.log("--------------------------------"); |
| 55 | + |
| 56 | + let excerpt = report.sections?.general_information?.markdown ?? ""; |
| 57 | + excerpt = excerpt.length > 100 ? `${excerpt.substring(0, 100)}...` : excerpt; |
| 58 | + printTable([ |
| 59 | + { |
| 60 | + "AssetId": report.assetId, |
| 61 | + "Project": report.projectName, |
| 62 | + "LastUpdated": report.lastRevisedAt, |
| 63 | + }, |
| 64 | + ]); |
| 65 | + console.log(excerpt); |
| 66 | + } catch (error) { |
| 67 | + console.error("Error calling getDiligenceReport:", error); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +main().catch(console.error); |
0 commit comments