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

Zerion wallet account $USD balance

Submitted by:
Benjamin
This function returns the USD balance of an account using the Zerion wallet tracker.
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 33 if (!secrets.zerionApiKey) { throw Error('API_KEY'); } async function fetchBalanceFromZerion(address) { const config = { method: 'GET', headers: { accept: 'application/json', authorization: `Basic ${secrets.zerionApiKey}` }, url: `https://api.zerion.io/v1/wallets/${address}/portfolio/?currency=usd` }; const response = await Functions.makeHttpRequest(config); if (response.error) { throw new Error(response.response.data.message); } const upscaledUSDValue = response.data.data.attributes.total.positions * 10 ** 18; return upscaledUSDValue; } const address = args[0]; const balance = await fetchBalanceFromZerion(address); return Functions.encodeUint256(balance); // Gas usage can be reduced by using a minified version. Please remove the code above this line and uncomment the code below. // if(!secrets.zerionApiKey)throw Error("API_KEY");async function fetchBalanceFromZerion(e){let t={method:"GET",headers:{accept:"application/json",authorization:`Basic ${secrets.zerionApiKey}`},url:`https://api.zerion.io/v1/wallets/${e}/portfolio/?currency=usd`},a=await Functions.makeHttpRequest(t);if(a.error)throw Error(a.response.data.message);let o=1e18*a.data.data.attributes.total.positions;return o}const address=args[0],balance=await fetchBalanceFromZerion(address);return Functions.encodeUint256(balance);