查询示例 - OpenZeppelin 文档

本文档提供了一系列使用 GraphQL 查询 OpenZeppelin Subgraphs 的示例,涵盖了 ERC20、ERC721、ERC1155、Ownable、AccessControl 和 Timelock 等常见合约标准。每个示例都展示了如何通过特定合约地址和用户地址来查询相关数据,例如代币总量、持有人、交易历史、NFT 元数据、权限角色以及定时锁定的操作等。

查询示例

ERC20

总供应量和最大的代币持有者

{
  erc20Contract(id: "<token-address-in-lowercase>") { # id 是小写的 token 地址
    totalSupply {
      value
    }
    balances(orderBy: valueExact, orderDirection: desc, where: { account_not: null }) { # 按照 valueExact 降序排列,且 account 不为空
      account {
        id
      }
      value
    }
  }
}

最近的交易,包含交易 ID

{
  erc20Contract(id: "<token-address-in-lowercase>") { # id 是小写的 token 地址
    transfers(orderBy: timestamp, orderDirection: desc) { # 按照时间戳降序排列
      from { id }
      to { id }
      value
      transaction { id }
    }
  }
}

用户的所有已索引的 ERC20 余额

{
  account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
    ERC20balances {
      contract{ name, symbol, decimals }
        value
    }
  }
}

ERC721

用户的全部 ERC721 代币,带有元数据

{
  account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
    ERC721tokens {
      contract { id }
      identifier
      uri
    }
  }
}

合约上的全部 ERC721 代币,带有当前所有者

{
  erc721Contract(id: "<registry-address-in-lowercase>") { # id 是小写的注册表地址
    tokens {
      identifier
      owner { id }
    }
  }
}

给定代币的所有转移历史

{
  erc721Tokens(where: {
    contract: "<registry-address-in-lowercase>", # 注册表地址(小写)
    identifier: "<token-identifier-in-decimal>", # 代币标识符(十进制)
  }) {
    transfers {
      timestamp
      from { id }
      to { id }
    }
  }
}

ERC1155

注册表的所有代币,带有相应的 totalSupply 和余额

{
  erc1155Contract(id: "<registry-address-in-lowercase>") { # id 是小写的注册表地址
    tokens {
    identifier
      totalSupply { value }
      balances(where: { account_not: null }) { # account 不为空
        account { id }
        value
      }
  }
  }
}

Ownable

Ownable 合约的转移历史

{
  ownable(id : "<ownable-address-in-lowercase>") { # id 是小写的 ownable 地址
    ownershipTransferred(orderBy: timestamp, orderDirection: asc) { # 按照时间戳升序排列
      timestamp
      owner { id }
    }
  }
}

账户持有的所有 ownable 合约

{
  account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
    ownerOf {
      id
    }
  }
}

AccessControl

所有角色,带有详细信息以及 AccessControl 驱动的合约的当前成员

{
  accessControl(id: "<accesscontrol-contract-in-lowercase>") { # id 是小写的 accesscontrol 合约
    roles {
      role { id }
      admin { role { id } }
      adminOf { role { id } }
      members { account { id } }
    }
  }
}

账户持有的所有 AccessControl 角色

{
  account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
    membership {
      accesscontrolrole {
        contract { id }
        role { id }
      }
    }
  }
}

Timelock

Timelock 上等待执行的操作,带有子调用和截止日期的详细信息

{
  timelock(id: "<timelock-address-in-lowercase>") { # id 是小写的 timelock 地址
    id
    operations(where: { status: "SCHEDULED"}) { # 状态为 "SCHEDULED"
      calls {
        target { id }
        value
        data
      }
      timestamp
    }
  }
}

到某个地址的所有时间锁定的操作,带有调用状态和详细信息

{
  account(id: "<address-of-the-target-in-lowercase>") { # id 是小写的 目标地址
    timelockedCalls {
      operation {
        contract { id }
        timestamp
        status
      }
      value
      data
    }
  }
}

← Subgraph examples

  • 原文链接: docs.openzeppelin.com/su...
  • 登链社区 AI 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
OpenZeppelin
OpenZeppelin
江湖只有他的大名,没有他的介绍。