如何查询RNS域的有效期?



除了直接查询,我还想订阅事件,以便在到期日期更改时侦听(例如,当它更新时)

我发现NodeOwner.sol有一个available函数的实施有望:

function available(uint256 tokenId) public view returns(bool) {
return expirationTime[tokenId] < now;
}

,该文件还定义了ExpirationChanged事件:

event ExpirationChanged(uint256 tokenId, uint expirationTime);

我不明白的是:

  • 如何获取NodeOwner-应该查询哪个合同/地址?
  • 如果NodeOwner有多个可能的地址/实例,或者只有一个。

要获得单个域的过期时间,可以使用RSKOwner合约和expirationTime方法。您可以用您感兴趣的域名查询此合同。

在主网上,合同的地址是0x45d3E4fB311982a06ba52359d44cB4f5980e0ef1,可以在RSK浏览器上验证。本合同的ABI可以在这里找到。

使用Web3库,您可以查询单个域(比如testing.rsk)是这样的:

const rskOwner = new web3.eth.Contract(rskOwnerAbi, rskOwnerAddress);
const hash = `0x${sha3('testing')}`;
rskOwner.methods.expirationTime(hash).call((error, result) => {
console.log('expires at: ', result)
})

您可以在RNS Manager上看到一个工作示例。

最新更新