Join the Rootstock Discord Community to get the latest updates from the Rootstock Ecosystem!

Use domains instead of long hexa addresses

This is a demonstration of how to get the address of a domain. We are going to do it in a React app.



  1. Create a new react app

    create-react-app rns-addr-sample-app
    cd rns-addr-sample-app
  2. Install @rsksmart/rns and web3.

    yarn add web3 @rsksmart/rns
  3. Update your App.js file

    import React, { Component } from 'react';
    import Web3 from 'web3';
    import RNS from '@rsksmart/rns';
    export default class extends Component {
    constructor(props) {
        this.state = {
            domain: '',
            getting: false,
            addr: null,
            error: null,
        this.handleDomainChange = this.handleDomainChange.bind(this);
        this.getAddress = this.getAddress.bind(this);
    handleDomainChange(event) {
        this.setState({ domain:, addr: null, error: null });
    getAddress() {
        const { domain } = this.state;
        this.setState({ getting: true, addr: null, error: null  });
        const web3 = new Web3('')
        const rns = new RNS(web3);
        .then(addr => this.setState({ addr, getting: false }))
        .catch(error => this.setState({ error, getting: false }));
    render() {
        const { domain, getting, addr, error } = this.state;
        return (
            <input type="text" onChange={this.handleDomainChange} value={domain} />
            <button onClick={this.getAddress}>get address</button>
            {getting && '...'}
            {addr && <label>{addr}</label>}
            {error && <label>Error: {error.message} - Read more on {error.ref}</label>}
  4. Start the app

    yarn start


Try the app in


{% include rns-integrate-dapp-wallet.html %}

Receive updates

Get the latest updates from the Rootstock ecosystem