Subgraph是ENS在The Graph上托管的ENS合约的索引和结构化数据访问服务。比起ENS的JavaScript库,它可以用来更加灵活的访问ENS数据,比如以下的使用场景:
查询设置了某个TEXTS字段的用户,如设置了头像avatar的用户, 设置了email的用户, 或者其他更特殊的字段,如carrierId。 我们可以通过carrierId来判断使用了beagle chat手机客户端的用户。查询方法如下:
{
domains(where: {resolver_:{texts_contains:["carrierId"]}}) {
name
labelName
resolver{
texts
}
resolvedAddress{id}
}
}
返回结果为:
{
"data": {
"domains": [
{
"name": "tomas.eth",
"labelName": "tomas",
"resolver": {
"texts": [
"email",
"carrierId"
]
},
"resolvedAddress": {
"id": "0x2259c79c85141a59b9117c789a5ae09774b7572f"
}
},
{
"name": "liwei.beagles.eth",
"labelName": "liwei",
"resolver": {
"texts": [
"carrierId"
]
},
"resolvedAddress": {
"id": "0xa37f4be5106ec699488e21e5412956f765e32b6e"
}
},
{
"name": "zeliang.beagle.eth",
"labelName": "zeliang",
"resolver": {
"texts": [
"carrierId",
"avatar",
"nickName"
]
},
"resolvedAddress": {
"id": "0x2259c79c85141a59b9117c789a5ae09774b7572f"
}
}
]
}
}
查询某个地址是否有ENS名字
注意id的字符串为小写字母。
query getDomainForAccount {
account(id: "0xc461d56919d1957692eb98dbb15ae23a3567d1bb") {
registrations(first: 10, orderBy: expiryDate, orderDirection: desc) {
domain {
name
}
}
id
}
}
返回值为:
{
"data": {
"account": {
"registrations": [
{
"domain": {
"name": "beagles.eth"
}
},
{
"domain": {
"name": "lenspace.eth"
}
}
],
"id": "0xc461d56919d1957692eb98dbb15ae23a3567d1bb"
}
}
}
subgprah的查询地址为:
rinkeby testnet
https://thegraph.com/hosted-service/subgraph/ensdomains/ensrinkeby
Ethereum Mainnet
https://thegraph.com/hosted-service/subgraph/ensdomains/ens
Graph的使用文档:
特别注意递归条件(nested entity filtering)的使用。