Out of box integrations help you build custom processors faster
Remember custom processors are fully-fledged Javascript runtime, so you can build any integration to any third-party with no limits. Sometimes you need an even easier way to integrate with a service; that's why we're going to add more ready-made integrations continuously.
🤑 Token Prices
Get current or historical USD value of any ERC20 token amount of any contract address on any chain, powered by CoinGecko, CoinMarketCap and Moralis.
You don't need an API Key from these providers, but if you need you can set your own API Key; for example if you have a larger plan with these providers.
1️⃣ prices.getUsdAmountByAddress(...)
This method tries to get the USD value of any token amount of a ERC20, if price data is available on any of the providers mentioned above.
It can optionally accept a block number (and/or timestamp) if you need historical data. It is highly recommended to provide these values based on the event data so that during backfills you get accurate data when loading historical data for the first time.
import { integrations } from'flair-sdk';awaitintegrations.prices.getUsdAmountByAddress({// Chain ID of the ERC20 token chainId: number,// Address of ERC20 token (must have decimals() method)// If not provided or zero-address provided then it will consider// the native token e.g. ETH if chainId is 1 tokenAddress?: string,// Raw (big number) representation of the amount you want to convert// For example 10000000000000000000 (which could mean 10 $ETH or $WBTC)// Default value is "1" meaning price of this token in USD. tokenAmount?: string,// Ideally try to get the price on this block number// Recommended to set it as "transaction.blockNumber" idealBlockNumber?: number,// Ideally try to get the price on this block timestamp// Recommended to set it as "transaction.blockTimestamp" idealTimestamp?: number,})//// This method returns://typePriceData= { isNativeToken:boolean; // If token is native (i.e. 0x000000) amountUsd:number; // USD value of the tokenAmount passed above. timestamp:number; // Exact timestamp where this price was captured granularity:'minute'|'hour'|'day'; timeBucket:string; // e.g. 2023-05-13T20:00 or 2023-05-13 based on granularity source:'coingecko'|'coinmarketcap'|'moralis';}
💫 Example Usage:
This example assumes each event has a token argument that has the ERC20 address and a feeAmount argument that is raw amount.