Post
Share your knowledge.
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
Answers
3You 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.
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.
The rate limit for public GraphQL requests is throttled at any source making more than 2000 requests in a 10-second window.
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.