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
2You 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.
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.
- yhant3235How to access and manage nested structs and dynamic fields in Move?56
- deriss82How to convert private key to new format via CLI33
- elfDani176Can you export an official Sui wallet to Razor or other Sui wallets?32
- Xavier.eth223'DataClone Failed to execute' error33
- yhant3235How can I claim Deep tokens if I have a DeepBook NFT?32