Post
Share your knowledge.
How do I query object owners using GraphQL in Sui?
I’m working on a project using GraphQL for the Sui blockchain and I'm trying to query for objects to get the owners of those objects. However, I'm stuck on what to include inside the owner {} field. I’m testing it with mainnet IDE but not sure if I’m using fragments correctly. What steps should I take to correctly query for object owners?
- Sui
- Architecture
Answers
5You can query for object owners in Sui using GraphQL by including the owner field within your query. Here is an example for devnet and testnet where you might need a fragment for the new owner variants:
query Object {
object(address:"0xfb2ac160804b61c8649628f78f7e1fcd8bd67be7b03191c689cd6ac8555476ad") {
version
owner {
__typename
... theAddressOwner
}
status
digest
previousTransactionBlock {
digest
}
dynamicFields {
nodes {
name {
json
}
value {
__typename
... TheMoveObject
... TheMoveValue
}
}
}
}
}
fragment theAddressOwner on AddressOwner {
owner {
address
}
}
fragment TheMoveObject on MoveObject {
address
contents {
json
}
}
fragment TheMoveValue on MoveValue {
json
}
If the owner is a different __typename, you should add a fragment for it just like done here. For mainnet, copy this setup and replace with a mainnet object address, and include any additional fragments as necessary.
Hey! To query for object owners in Sui GraphQL, inside the owner {} field, you'll need to use inline fragments (... on TypeName { field }) to access the specific fields of the owner type. The most common is ... on AddressOwner { address } to get the owner's Sui address. You should also include __typename to see the exact owner type, and potentially other fragments for SharedOwner (to get initialSharedVersion), ImmutableOwner, or ParentOwner if you need to handle those cases. So, a good starting point would be owner { __typename ... on AddressOwner { address } ... on SharedOwner { initialSharedVersion } }. This setup will correctly pull the owner's address for individually owned objects.
Additionally, to query for different types of ownership like Immutable, Shared, Parent, or AddressOwner, you can refer to the ObjectOwner union type documentation. This will help as the owner field can return different types of ownership. For more details, check the ObjectOwner documentation.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking616
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction410