Web3

To use web3 and interact with the contracts, we must instance web3 with a provider. To do so we can use Rootstock (RSK) public nodes:

var Web3 = require('web3')

var web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider(config.node))

RNS Registry

Instance the RNS Registry contract:

const rnsAbi = []
const rnsAddress = ''
var rnsInstance = web3.eth.contract(rnsAbi)
var rns = registryInstance.at(rnsAddress)

And include namehash library:

var namehash = require('eth-ens-namehash').hash

domain field does include .rsk suffix

Further reading: RNS Registry contract.

Change the resolver

function setResolver(domain, newResolver) {
    var hash = namehash(domain)
    rns.setResolver(hash, newResolver)
}

Further reading: setResolver.

Change the node owner

function setOwner(domain, owner) {
    var hash = namehash(domain)
    rns.setOwner(hash, owner)
}

Further reading: setOwner.

Change the TTL

function setTTL(domain, ttl) {
    var hash = namehash(domain)
    rns.setTTL(hash, ttl)
}

Further reading: setTTL.

Create a subdomain

This is also used to change the subdomain owner.

The name field is the subdomain inherited from the domain.

function subdomain(domain, name, owner) {
    var domainHash = namehash(domain)
    var hash = web3.sha3(name)
    rns.setSubnodeOwner(domainHash, hash, owner)
}

Further reading: setSubnodeOwner.

Resolver

Have a look at the Resolve a name and Public Resolver Contract section for further information.

Receive updates

Get the latest updates from the Rootstock ecosystem

Loading...