Search code examples
solidityrsk

How to query the expiry date for an RNS domain?


In addition to direct queries, I'd also like to subscribe to events to listen for whenever the expiry date changes (e.g. when it is renewed)

I've found that NodeOwner.sol has an available function whose implementation looks promising:

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

and that same file also defines an ExpirationChanged event:

    event ExpirationChanged(uint256 tokenId, uint expirationTime);

What I haven't been able to figure out is:

  • How to get the NodeOwner - which contract/ address should be queried?
  • If there are multiple possible addresses/ instances of NodeOwner, or there's only one of them.

Solution

  • To get the expiration time of a single domain, you can use the RSKOwner contract with the expirationTime method. You can query this contract to with the domain you are interested in.

    On Mainnet, the contract’s address is 0x45d3E4fB311982a06ba52359d44cB4f5980e0ef1, which can be verified on the RSK explorer. The ABI for this contract can be found here.

    Using Web3 library, you can query a single domain (such as testing.rsk) like this:

    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)
    })
    

    You can see a working example of this on the RNS Manager.