Digital Asset Movement & Blockchain Events

Transactions are one of the fundamental building blocks to the modern financial system. Every action, value transfer, or application change that occurs on the blockchain is facilitated by a transaction. That's why it's imperative to be able to easily obtain this data in an easy to understand format.

You can leverage the wealth of data available in our API for each use case. Build applications that watch for new transactions and execute actions based on a given criteria. Or perhaps as an investor you're looking for insight into the health of a network. As a wallet developer, you may be interested in updating balances or give users a view of their asset holdings over time. You could also be trying to trace value as it's transacted through the network, across multiple networks, to discover patterns or anomalies. All this is made possible with this simple and intuitive API.

In order to accomplish this we'll need a few things:

  • Historical/Real-time Transactions
  • Transaction Pricing Data
  • Asset Transfers

We'll walk through a few quick examples of what is possible.

Historical/Real-time Transactions

To start, we'll get the transactions of an account/address over the past 7 days then watch for any new transaction that occurs.

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 = '0x06012c8cf97bead5deae237070f9587f8e7a266d'

// Get date from 7 days ago
const startDate = new Date()
startDate.setDate(startDate.getDate() - 7)

// Get the transactions of the address starting from 7 days ago
const transactions = await w3d.address.getTransactions(ADDRESS, {startDate: startDate.toISOString()})
console.log({transactions})

// Listen for new transactions to arrive
w3d.connect()
w3d.on({eventName: 'address:transaction', filters: {address: ADDRESS}}, (txn) => {

Transaction Pricing Data

That's great! We're able to see a historical view of all this account's transactions with details like value and data transferred. What if we wanted to see these values in USD or EUR? All we need to do is specify the currency or add a boolean to include pricing data with transactions.

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 = '0x06012c8cf97bead5deae237070f9587f8e7a266d'


// Get the transactions of the address and include the value of the transaction in usd
const transactions = await w3d.address.getTransactions(ADDRESS, {includePrice: true, currency: 'usd'})
console.log({transactions})

Asset Transfers

Asset transfers such as ERC-20 tokens, also occur within transactions. If you have a transaction, it requires some extra logic to derive meaningful token transfer data. We’ve made it a lot easier by providing these digital asset transfers out of the box. You can choose to include token transfers when retrieving transactions.

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)

// Token transfers by token address
const BAT_CONTRACT = '0x0d8775f648430679a709e98d2b0cb6250d2887ef'

// Get historical token transfers of the BAT contract
const batTokenTransfers = w3d.token.getTransfers(BAT_CONTRACT)

// Init websocket connection
w3d.connect()

// Watch for all BAT transfer events and log the transfer details
w3d.on({eventName:'token_transfers', filters: {BAT_CONTRACT} }, transfer => {
    console.log(`${transfer.amount} DAI transfered at ${transfer.timestamp}`)
})

// Token transfers by account - Get metrics on specific account token transfers
const address = '0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be' // 🐋

// Get historical token transfers of an account
const tokenTransfers = w3d.address.getTokenTransfers(address)

// Watch for all token transfer events by address
w3d.on({eventName:'address:token_transfers', filters: {address} }, transfer => {
    console.log(`${transfer.tokenAddress.slice(0,10)} transfered at ${transfer.timestamp}`)
})

With Amberdata’s API we give you the complete picture of what’s really going on within transactions.