View Your Digital Asset Holdings

Each blockchain is vast, and can be difficult to get an accurate picture of what assets you own. You might have multiple accounts across different blockchains. Maybe you even have an account just for your NFT collection. As a user, you'll want to be able to track all of these assets and get a full view of what you own. How can we get a multichain portfolio? You could run 8 different blockchain nodes and create an infrastructure to support ETL from each one of these nodes. Although this can be very time consuming and financially costly. Another way would be to combine endpoints from multiple API providers. That is if you don't mind trying to build a data model to handle the different shapes of data returned from these endpoints, not to mention handling API Keys and different rate limits. Why not get all of your data from a single API? We’ve made our APIs powerful, enabling digital assets & portfolios across blockchains.

Let's walk through what we'll need to accomplish this:

  • Latest and historical balances
  • Pricing data
  • Real-time activity feeds

Latest and historical balances

The most basic function of our portfolio is to provide a current and historical view of balances in a users account. This should encompassing all types of tokens, and addresses from different blockchains.

Try out the example on runkit!

const Web3Data = require("web3data-js")

// Create the Web3Data instances passing in  your API Key (Get one! -> amberdata.io/onboarding)
const w3d = new Web3Data(process.env.API_KEY)

const ETH_ADDRESS = '0x0681d8db095565fe8a346fa0277bffde9c0edbbf'
const BTC_ADDRESS = '1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY'
const LTC_ADDRESS = 'Lbuzsisqmp8KyxuotRa8QUz5owr2cVMJGL'
const ZEC_ADDRESS = 't1M5GSbdVpPA1XFkuzi12sJyqGkrEEfGwLJ'

// Specify endDate to get historical data
const endDate = (new Date()).getTime()

// Get the current balances for each address
const [ ethBalance, btcBalance, ltcBalance, zecBalance ] = await Promise.all([
    w3d.btc.address.getBalance(BTC_ADDRESS, { includePrice: true }),
    w3d.ltc.address.getBalance(LTC_ADDRESS, { includePrice: true }),
    w3d.zec.address.getBalance(ZEC_ADDRESS, { includePrice: true })
])


/* Uncomment if using Professional plan to run.
// For ethereum we can get Eth balance and token balances like so:
const balances = await w3d.address.getBalances(ETH_ADDRESS,  { includePrice: true })
*/

/* Uncomment if using Professional plan to run.
// Gets the historical balances for each address
const [ ethBalance, btcBalance, ltcBalance, zecBalance ] = await Promise.all([
    w3d.address.getBalance(ETH_ADDRESS,  { includePrice: true, endDate }).then(data => data.data),
    w3d.btc.address.getBalance(BTC_ADDRESS, { includePrice: true, endDate }).then(data => data.data),
    w3d.ltc.address.getBalance(LTC_ADDRESS, { includePrice: true, endDate }).then(data => data.data),
    w3d.zec.address.getBalance(ZEC_ADDRESS, { includePrice: true, endDate }).then(data => data.data)
])
*/

// This will return an array of the last 100 historical balances for each address
console.log({ethBalance, btcBalance, ltcBalance, zecBalance})

Pricing data

We'll also want to track these balances overtime and watch our gains/losses based on market values. In order to do this, we'll need the price data associated with each asset that the user is holding. You'll notice in the previous example the includePrice: true option which gives us all the necessary pricing data.

Real-time activity feeds

Finally, our users want to be informed when a value transfer occurs and have their balance updated to match the current state of their holdings. It might also be that they want to set alerts when transactions occur. Again, this must incorporate more than a single blockchain. All of this is possible with our single API.

Try out the example on runkit!

const Web3Data = require("web3data-js")

// Create the Web3Data instances passing in  your API Key (Get one! -> amberdata.io/onboarding)
const w3d = new Web3Data(process.env.API_KEY)

const ADDRESS = '0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be'
// Initialize the connection
w3d.connect()

// Subscribes to all transactions events
w3d.on({eventName: 'address:transactions', filters: {address: ADDRESS}}, transaction => {

  // Log the transaction data
  console.log(transaction)
})

// Subscribes to all token transfer events
w3d.on({eventName: 'address:token_transfer', filters: {address: ADDRESS}}, tokenTransfer => {

  // Log the token transfer data
  console.log(tokenTransfer)
})