Sui.

帖子

分享您的知识。

Pluto Dev👽.
Jan 05, 2025
专家问答

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
2
分享
评论
.

答案

2
LargeCappWithTwo.
Jan 5 2025, 12:10

通过在查询中加入owner字段,您可以使用 GraphQL 在 Sui 中查询对象所有者. 以下是 devnet 和 testnet 的示例,您可能需要一个新所有者变体的片段:

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
}

如果所有者是另一个人__typename,你应该像这里一样为它添加一个片段. 对于主网,复制此设置并替换为主网对象地址,并根据需要添加任何其他片段.

2
最佳答案
评论
.
andreweth..
Jan 6 2025, 02:10

此外,要查询不同类型的所有权,例如不可变、共享、父或地址所有者,可以参考 ObjectOwner 联合类型文档. 这将有所帮助,因为该owner字段可以返回不同类型的所有权. 有关更多详细信息,请查看 ObjectOwner 文档.

0
评论
.

你知道答案吗?

请登录并分享。

Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.

609帖子1280答案
Sui.X.Peera.

赚取你的 1000 Sui 份额

获取声誉积分,并因帮助 Sui 社区成长而获得奖励。

奖励活动七月