Got a cool example to share? Get listed here! Submit it now.

useChainlinkFunctions()

Collection of community submitted examples for Chainlink Functions

Get inspired from quick examples

Chainlink Functions, a new self-service platform that allows anyone to write serverless code to fetch any data from any API and run custom compute on Chainlink's network. Learn from examples created by the community or contribute your own!
Learn more about Chainlink Functions

Financial metric data for dApps and blockchains sourced from Token Terminal

Submitted by:
ChainLinkGod
This Function fetches metric data from the Token Terminal API for a specific project. Supported metrics include revenue, fees, earnings, active users, TVL, volume, supply, and more. Projects includes both dApps and blockchains. Optional parameter for specific date. Requires Token Terminal Pro subscription to obtain API key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 const metric = args[0] // valid metric id that can be found on https://api.tokenterminal.com/v2/metrics const project = args[1] // project id const date = args[2] // optional date. format YYYY-MM-DD. For example 2023-02-10 const apiKey = secrets.API_KEY; if (!apiKey) { throw Error("Tokenterminal API Key is required") } const config = { url: `https://api.tokenterminal.com/v2/metrics/${metric}?project_ids=${project}`, headers: { 'Authorization': `Bearer ${apiKey}` } } const response = await Functions.makeHttpRequest(config) if (response.error) { throw new Error(response.response.data.message) } let data; if (date) { data = response.data.data.find(d => d.timestamp.includes(date)) }else { data = response.data.data[0] } const result = Math.round(data.value * 100) return Functions.encodeUint256(result)