Sui.

Post

Share your knowledge.

Pluto Dev👽.
Jan 05, 2025
Expert Q&A

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
1
5
Share
Comments
.

Answers

5
LargeCappWithTwo.
Jan 5 2025, 12:10

You 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.

2
Best Answer
Comments
.
fomo on Sui.
Sep 7 2025, 11:54

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.

3
Comments
.
andreweth..
Jan 6 2025, 02:10

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.

0
Comments
.

Do you know the answer?

Please log in and share it.