Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GraphQL] How to filter transaction list by token? #20777

Open
mahnunchik opened this issue Jan 3, 2025 · 2 comments
Open

[GraphQL] How to filter transaction list by token? #20777

mahnunchik opened this issue Jan 3, 2025 · 2 comments
Assignees
Labels
doc-issue Issue submitted using the Doc issue template graphql

Comments

@mahnunchik
Copy link

The list of transactions by address can be obtained by the following query:

query fff($affectedAddress: SuiAddress) {
  transactionBlocks(
    filter: {
      affectedAddress: $affectedAddress
    }
    last: 10
  ) {
    nodes {
      digest,
      sender {
        address
      }
      effects {
        status
        balanceChanges {
          nodes {
            amount
            coinType {
              repr
            }
            owner {
              address
            }
          }
        }
      }
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}

Now the question: is it possible to filter transactions of a specific token that are received or sent from an address?

Will the filter help function: ?? - ?

@mahnunchik mahnunchik added the doc-issue Issue submitted using the Doc issue template label Jan 3, 2025
@stefan-mysten stefan-mysten assigned wlmyng and unassigned ronny-mysten Jan 3, 2025
@Emadalshamery
Copy link

Yes

@wlmyng
Copy link
Contributor

wlmyng commented Jan 6, 2025

Appreciate you giving graphql a try!

is it possible to filter transactions of a specific token that are received or sent from an address?

This is not supported out of the box unfortunately, because our base implementation is meant to be generic enough to extend upon, without privileging a particular app or protocol. This becomes problematic in light of the feature above. We would need a feature table that maps a token type to a transaction, similar to existing tables that map transactions to affected addresses. However, because every transaction uses at least SUI tokens for gas, this would be a very large table that doesn't do much to help optimize read queries.

Instead, someone can start their own custom indexing solution, perhaps by modifying the indexer to commit to a dedicated table that maps a particular token of interest to txs. You can then add a custom graphql resolver to expose this.

But if you can approximate this functionality using the transaction's function field, or some other available filter, that could also work. For example, if there is a specific function that interacts with a specific token, then you can just filter on that function + address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-issue Issue submitted using the Doc issue template graphql
Projects
None yet
Development

No branches or pull requests

6 participants
@mahnunchik @ronny-mysten @wlmyng @stefan-mysten @Emadalshamery and others