πŸ’ΈToken Transfers

Learn how to recommend users based on token transfers

Token transfers between two parties are a good indication that the parties involved know each other. Therefore, you can also use token transfers to build your recommendation engine.

To build such a recommendation engine, Airstack provides a TokenTransfers API for you to fetch the users involved in a given user's all ERC20/721/1155 token transfers across Ethereum, Base, Degen Chain, and other Airstack-supported chains.

The list of users, then can be compiled and returned to your application as recommendations.

Table Of Contents

In this guide you will learn how to use Airstack to:

Pre-requisites

  • An Airstack account

  • Basic knowledge of GraphQL

Get Started

JavaScript/TypeScript/Python

If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:

React

npm install @airstack/airstack-react

Node

npm install @airstack/node

Then, add the following snippets to your code:

import { init, useQuery } from "@airstack/airstack-react";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const Component = () => {
  const { data, loading, error } = useQuery(query);

  if (data) {
    return <p>Data: {JSON.stringify(data)}</p>;
  }

  if (loading) {
    return <p>Loading...</p>;
  }

  if (error) {
    return <p>Error: {error.message}</p>;
  }
};

Other Programming Languages

To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.

πŸ€– AI Natural Language​

Airstack provides an AI solution for you to build GraphQL queries to fulfill your use case easily. You can find the AI prompt of each query in the demo's caption or title for yourself to try.

Get Token Transfers Sent From A User on Ethereum

You can fetch all token transfers sent from a given user, e.g. betashop.eth, on Ethereum by using the TokenTransfers API:

Try Demo

Code

query GetTokenTransfers {
  TokenTransfers(
    input: {
      filter: {
        # Only get token transfers from betashop.eth
        from: {_eq: "betashop.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "betashop.eth"]}
        }
      },
      blockchain: ethereum,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      to {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
}

All the users returned from the to response field can be compiled and returned as a recommendation in your application.

Get Token Transfers Received By A User on Ethereum

You can fetch all token transfers received by a given user, e.g. betashop.eth, on Ethereum by using the TokenTransfers API:

Try Demo

Show me token transfers received by betashop.eth on Ethereum

Code

query GetTokenTransfers {
  TokenTransfers(
    input: {
      filter: {
        # Only get token transfers to betashop.eth
        to: {_eq: "betashop.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "betashop.eth"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]}
        }
      },
      blockchain: ethereum,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      from {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
}

All the users returned from the from response field can be compiled and returned as a recommendation in your application.

Get Token Transfers Sent From A User on Base

You can fetch all token transfers sent from a given user, e.g. jessepollak.eth, on Base by using the TokenTransfers API:

Try Demo

Code

query GetTokenTransfers {
  TokenTransfers(
    input: {
      filter: {
        # Only get token transfers from jessepollak.eth
        from: {_eq: "jessepollak.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "jessepollak.eth"]}
        }
      },
      blockchain: base,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      to {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
}

All the users returned from the to response field can be compiled and returned as a recommendation in your application.

Get Token Transfers Received By A User on Base

You can fetch all token transfers received by a given user, e.g. barmstrong.eth, on Base by using the TokenTransfers API:

Try Demo

Code

query GetTokenTransfers {
  TokenTransfers(
    input: {
      filter: {
        # Only get token transfers to barmstrong.eth
        to: {_eq: "barmstrong.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "barmstrong.eth"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]}
        }
      },
      blockchain: base,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      from {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
}

All the users returned from the from response field can be compiled and returned as a recommendation in your application.

Get Token Transfers Sent From A User on Multiple Chains

You can fetch all token transfers sent from a given user, e.g. betashop.eth, across multiple chains, such as Ethereum, Base, Degen Chain, and other Airstack-supported chains, by using the TokenTransfers API:

Try Demo

Code

query GetTokenTransfers {
  # first query on Ethereum
  Ethereum: TokenTransfers(
    input: {
      filter: {
        # Only get token transfers from betashop.eth
        from: {_eq: "betashop.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "betashop.eth"]}
        }
      },
      blockchain: ethereum,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      to {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
  # second query on Base
  Base: TokenTransfers(
    input: {
      filter: {
        # Only get token transfers from betashop.eth
        from: {_eq: "betashop.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "betashop.eth"]}
        }
      },
      blockchain: base,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      to {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
}

All the users returned from the to response field can be compiled and returned as a recommendation in your application.

Get Token Transfers Received By A User on Multiple Chains

You can fetch all token transfers received by a given user, e.g. betashop.eth, across multiple chains, such as Ethereum, Gold, Zora, and Base, by using the TokenTransfers API:

Try Demo

Code

query GetTokenTransfers {
  # first query on Ethereum
  Ethereum: TokenTransfers(
    input: {
      filter: {
        # Only get token transfers to betashop.eth
        to: {_eq: "betashop.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "betashop.eth"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]}
        }
      },
      blockchain: ethereum,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      from {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
  # second query on Base
  Base: TokenTransfers(
    input: {
      filter: {
        # Only get token transfers to betashop.eth
        to: {_eq: "betashop.eth"},
        # Only get token transfers with non-zero amount
        formattedAmount: {_gt: 0},
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD", "betashop.eth"]},
          to: {_in: ["0x0000000000000000000000000000000000000000", "0x000000000000000000000000000000000000dEaD"]}
        }
      },
      blockchain: base,
      limit: 50
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      from {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
}

All the users returned from the from response field can be compiled and returned as a recommendation in your application.

Get The Most Recent Token Transfers Sent From A User(s)

You can fetch all most recent token transfers sent from a given user, e.g. betashop.eth, across multiple chains, such as Ethereum, Gold, Zora, and Base, by using the TokenTransfers API:

Try Demo

Code

query GetTokenTransfers {
  # first query on Ethereum
  Ethereum: TokenTransfers(
    input: {
      filter: {
        # Only get token transfers from betashop.eth
        from: { _eq: "betashop.eth" }
        # Only get token transfers with non-zero amount
        formattedAmount: { _gt: 0 }
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {
            _in: [
              "0x0000000000000000000000000000000000000000"
              "0x000000000000000000000000000000000000dEaD"
            ]
          }
          to: {
            _in: [
              "0x0000000000000000000000000000000000000000"
              "0x000000000000000000000000000000000000dEaD"
              "betashop.eth"
            ]
          }
        }
      }
      blockchain: ethereum
      limit: 50
      order: { blockTimestamp: DESC } # Order transfers by blocktimestamp in descending order
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      to {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
        }
        xmtp {
          isXMTPEnabled
        }
      }
    }
  }
  # second query on Base
  Base: TokenTransfers(
    input: {
      filter: {
        # Only get token transfers from betashop.eth
        from: { _eq: "betashop.eth" }
        # Only get token transfers with non-zero amount
        formattedAmount: { _gt: 0 }
        # Remove all minting/burning + self-transfer
        _nor: {
          from: {
            _in: [
              "0x0000000000000000000000000000000000000000"
              "0x000000000000000000000000000000000000dEaD"
            ]
          }
          to: {
            _in: [
              "0x0000000000000000000000000000000000000000"
              "0x000000000000000000000000000000000000dEaD"
              "betashop.eth"
            ]
          }
        }
      }
      blockchain: base
      limit: 50
      order: { blockTimestamp: DESC } # Order transfers by blocktimestamp in descending order
    }
  ) {
    TokenTransfer {
      formattedAmount
      tokenType
      token {
        name
      }
      to {
        addresses
        domains {
          name
        }