RNS JS Library - Operations

Available operations

addr

Get the address of a given domain and chain. If chainId is not provided, it resolves current blockchain address.

Signature

async addr(domain: string, chainId?: ChainId): Promise<string>

Parameters

  • domain: Domain to be resolved.
  • chainId: Chain identifier listed in SLIP44

Returns

  • string: the address resolution

Throws

Examples

Get an address:

rns.addr('testing.rsk').then(console.log)

Get Bitcoin address:

rns.addr('testing.rsk', '0x80000000').then(console.log)

reverse

Reverse lookup: Get the name of a given address.

Signature

async reverse(address: string): Promise<string>

Parameters

  • address: address to be resolved.

Returns

  • string: Domain or subdomain associated to the given address.

Throws

Example

rns.reverse('0x0000000000000000000000000000000123456789').then(console.log)

setAddr

Set address resolution of a given domain using the AbstractAddrResolver interface.

Signature

async setAddr(domain: string, addr: string): Promise<void>

Parameters

  • domain: Domain to set resolution.
  • addr: Address to be set as the resolution of the given domain

Returns

  • TransactionReceipt

Throws

Examples

Set an address:

rns.setAddr('testing.rsk', '0x0000000000000000000000000000000123456789').then(() => console.log('Done!'))

setResolver

Set resolver of a given domain.

Signature

async setResolver(domain: string, resolver: string): Promise<void>

Parameters

  • domain: Domain to set resolver.
  • resolver: Address to be set as the resolver of the given domain

Returns

  • TransactionReceipt

Throws

available

Check if given domain is available or if there is any availability for the given label.

Signature

async available(domain: string): Promise<boolean | string[]>

Parameters

  • domain: Domain or label to check availability.

Returns

  • true if the domain is available, false if not, or an array of available domains under possible TLDs if the parameter is a label

Throws

Examples

rns.available('testing.rsk').then(console.log) // will print true or false
rns.available('testing').then(console.log) // will print [ 'testing.rsk' ] if is available or [ ] if not.

subdomains

available (for subdomains)

Checks if the given label subdomain is available under the given domain tree.

Signature

async available(domain: string, label: string): Promise<boolean>

Parameters

  • domain: Parent .rsk domain. For example, wallet.rsk
  • label: Subdomain whose availability should be checked. For example, alice

Returns

  • boolean: true if available, false if not

Throws

Example

Check if example.testing.rsk subdomain is available:

rns.subdomains.available('testing.rsk', 'example').then(console.log)

setOwner

Creates a new subdomain under the given domain tree if it is available.

Precondition: the sender should be the owner of the parent domain.

Signature

async setOwner(domain: string, label: string, owner: string): Promise<void>

Parameters

  • domain: Parent .rsk domain. For example, wallet.rsk
  • label: Subdomain to register. For example, alice
  • owner: The new owner’s address

Returns

  • TransactionReceipt

Throws

Example

Register example.testing.rsk and give ownership to 0x0000000000000000000000000000000000000001:

const newOwnerAddress = '0x0000000000000000000000000000000000000001';
await rns.subdomains.setOwner('testing.rsk', 'example', newOwnerAddress);

create

Creates a new subdomain under the given domain tree if it is available, and sets its resolution if addr is provided.

Precondition: the sender should be the owner of the parent domain.

Signature

async create(domain: string, label: string, owner: string, addr: string): Promise<void>

Parameters

  • domain: Parent .rsk domain. For example, wallet.rsk
  • label: Subdomain to register. For example, alice
  • owner: The owner of the new subdomain. If not provided, the address who executes the tx will be the owner
  • addr: The address to be set as resolution of the new subdomain

If addr is not provided, no resolution will be set

If owner is not provided, the sender will be set as the new owner

If owner and addr are provided and owner is equals to the sender, two txs will be sent.

If owner and addr are provided but owner is different from the sender, then three txs will be sent.

Returns

  • TransactionReceipt of the latest transaction

Throws

Example

Register example.testing.rsk, give ownership to 0x0000000000000000000000000000000000000001 and set resolution to 0x0000000000000000000000000000000000000002:

const newOwnerAddress = '0x0000000000000000000000000000000000000001';
const resolution = '0x0000000000000000000000000000000000000002';
await rns.subdomains.create('testing.rsk', 'example', newOwnerAddress, resolution);

Advanced operations

Use Web3 Contracts directly, find instructions here.