本文档提供了一系列使用 GraphQL 查询 OpenZeppelin Subgraphs 的示例,涵盖了 ERC20、ERC721、ERC1155、Ownable、AccessControl 和 Timelock 等常见合约标准。每个示例都展示了如何通过特定合约地址和用户地址来查询相关数据,例如代币总量、持有人、交易历史、NFT 元数据、权限角色以及定时锁定的操作等。
{
erc20Contract(id: "<token-address-in-lowercase>") { # id 是小写的 token 地址
totalSupply {
value
}
balances(orderBy: valueExact, orderDirection: desc, where: { account_not: null }) { # 按照 valueExact 降序排列,且 account 不为空
account {
id
}
value
}
}
}
{
erc20Contract(id: "<token-address-in-lowercase>") { # id 是小写的 token 地址
transfers(orderBy: timestamp, orderDirection: desc) { # 按照时间戳降序排列
from { id }
to { id }
value
transaction { id }
}
}
}
{
account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
ERC20balances {
contract{ name, symbol, decimals }
value
}
}
}
{
account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
ERC721tokens {
contract { id }
identifier
uri
}
}
}
{
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 }
}
}
}
{
erc1155Contract(id: "<registry-address-in-lowercase>") { # id 是小写的注册表地址
tokens {
identifier
totalSupply { value }
balances(where: { account_not: null }) { # account 不为空
account { id }
value
}
}
}
}
{
ownable(id : "<ownable-address-in-lowercase>") { # id 是小写的 ownable 地址
ownershipTransferred(orderBy: timestamp, orderDirection: asc) { # 按照时间戳升序排列
timestamp
owner { id }
}
}
}
{
account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
ownerOf {
id
}
}
}
{
accessControl(id: "<accesscontrol-contract-in-lowercase>") { # id 是小写的 accesscontrol 合约
roles {
role { id }
admin { role { id } }
adminOf { role { id } }
members { account { id } }
}
}
}
{
account(id: "<user-address-in-lowercase>") { # id 是小写的用户地址
membership {
accesscontrolrole {
contract { id }
role { id }
}
}
}
}
{
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
}
}
}
- 原文链接: docs.openzeppelin.com/su...
- 登链社区 AI 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!