Move.

Post

Share your knowledge.

1 Luca.
Jan 11, 2025
Expert Q&A

How to query Swap_Event without specifying phantom types?

I'm trying to query all Swap_Event instances without specifying phantom types for the struct like Swap_Event<phantom Ty0, phantom Ty1>. What are some alternative methods to achieve this? Also, if I upgrade the contract, how does it affect my queries? Additionally, is there a rate limit on public GraphQL queries?

  • Move CLI
  • Move
3
3
Share
Comments
.

Answers

3
farshad.
Jan 11 2025, 10:18

You can use the queryEvents API with a filter that targets the MoveEventModule like this:

"params": [
  {
    "MoveEventModule": {
      "package": "<PACKAGE_ID>",
      "module": "<MODULE_NAME>",
      "event": "Swap_Event"
    }
  }
]

However, be aware that this applies to all events in the module and not just Swap_Event. For filtering specific event names when phantom types aren't specified, you can use a GraphQL query such as:

https://sui-<devnet|testnet|mainnet>.mystenlabs.com/
{
  events(
    filter: {
      eventType: "<PACKAGE_ID>::<MODULE_NAME>::Swap_Event"
    }
  ) {
    edges {
      node {
        timestamp
        type {
          repr
        }
        data
        json
      }
    }
  }
}

This method allows for more granular control.

2
Best Answer
Comments
.
Theoremus.
Jan 11 2025, 07:00

Regarding contract upgrades, your queries will work with any package version. Although it's recommended to use the new package for new queries, the old package can still be utilized for historical data lookup.

2
Comments
.
deriss.
Jan 12 2025, 01:45

The rate limit for public GraphQL requests is throttled at any source making more than 2000 requests in a 10-second window.

0
Comments
.

Do you know the answer?

Please log in and share it.

We use cookies to ensure you get the best experience on our website.
More info