Learn how to construct queries to build a recommendation engine based on token transfers.
Frequent token transfers between two parties could be a good indication that the parties involved know each other. Therefore, you can also use token transfers to build your contact recommendation feature.
To build such a contact recommendation feature, Airstack provides a TokenTransfers API for you to fetch all ERC20 token transfer data from either a user or multiple users on both Ethereum on Polygon.
Get Token Transfers Of A User(s) on Ethereum
queryGetTokenTransfers($address: [Identity!]) { TokenTransfers( input: {filter: {_or: {from: {_in: $address}, to: {_in: $address}}}, blockchain: ethereum, limit: 50} ) { TokenTransfer { amount formattedAmount blockTimestamp token { symbol name decimals } from { addresses socials { dappName profileName } domains { dappName } } to { addresses socials { dappName profileName } domains { name dappName } } type } }}
{"address": ["dwr.eth","fc_fname:vbuterin"]}
Get Token Transfers Of A User(s) on Multiple Chains
queryGetTokenTransfers($address: [Identity!]) { # first query on Ethereumethereum: TokenTransfers( input: {filter: {_or: {from: {_in: $address}, to: {_in: $address}}}, blockchain: ethereum, limit: 50} ) { TokenTransfer { amount formattedAmount blockTimestamp token { symbol name decimals } from { addresses socials { dappName profileName } domains { dappName } } to { addresses socials { dappName profileName } domains { name dappName } } type blockchain } } # second query on Polygonpolygon: TokenTransfers( input: {filter: {_or: {from: {_in: $address}, to: {_in: $address}}}, blockchain: polygon, limit: 50} ) { TokenTransfer { amount formattedAmount blockTimestamp token { symbol name decimals } from { addresses socials { dappName profileName } domains { dappName } } to { addresses socials { dappName profileName } domains { name dappName } } type blockchain } }}
{"address": ["prxshant.eth","fc_fname:vbuterin"]}
Get The Most Recent Token Transfers Of A User(s)
This query is similar to the basic Get Token Transfers Of A User(s) query shown above with the addition of a new variable $blocktimestamp that will filter and return the token transfers that occur prior to the given timestamp value in the variable.
queryGetTokenTransfers($address: [Identity!], $blocktimestamp: Time) { TokenTransfers( input: {filter: {_or: {from: {_in: $address}, to: {_in: $address}, blockTimestamp: {_lt: $blocktimestamp}}}, blockchain: ethereum, limit: 50} ) { TokenTransfer { amount blockTimestamp token { symbol name decimals } from { addresses socials { dappName profileName } domains { dappName } } to { addresses socials { dappName profileName } domains { name dappName } } type } }}