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
query GetTokenTransfers($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
query GetTokenTransfers($address: [Identity!]) {
# first query on Ethereum
ethereum: 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 Polygon
polygon: 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
}
}
}
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.
query GetTokenTransfers($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
}
}
}