Sui.

Post

Share your knowledge.

Pluto Dev👽.
Jan 05, 2025
Discussion

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
0
2
Share
Comments
.

Answers

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

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

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