How to Build a Standalone and Decentralized dApp Infrastructure to Couple with the Elrond Blockchain -
Part 1

BH Network
6 min readAug 29, 2021

Set Up Your Own WalletConnect Bridge for Elrond dApps

In this series of technical articles, we’ll cover some technical points around the need to build a standalone and decentralized dApp infrastructure coupled with the Elrond blockchain. Blockchain, by default, is decentralized software. However, it is important to have a standalone and decentralized infrastructure for your dApp management to couple to the blockchain. That will allow for the best throughput and load balancing for the traffic going through dApp and collateral services (e.g.: Maiar WalletConnect, Elasticsearch, Nodes Observers, etc.).

In this article, we’ll cover the setup of your own standalone WalletConnect bridge used by Maiar WalletConnect to have a more reliable and user-friendly interface for a full non-custodial login.

Why Use Your Own Bridge?

To answer the question, we must first understand what WalletConnect is. WalletConnect is an open-source protocol that lets dApps (decentralized Applications) connect to cryptocurrency wallet apps. That connection allows for transaction authentication from the app without ever entering the private key in the dApp itself. Elrond’s Maiar app uses this technology to authenticate its users.

The protocol works by generating a QR code on the dApp side, which you scan with your wallet app on your mobile device. Walletconnect manages all the complexity behind the scenes and provides a clean and seamless interaction with the dApp through your mobile device.

Using the default Elrond bridge can be problematic if you need the maximum possible traffic throughput or not get blocked if your traffic reaches the maximum allowed threshold (all the dApps built on Elrond with Maiar login by default are using the Elrond bridge).

However, thanks to the open-source nature of the WalletConnect protocol, it is effortless to have your own bridge instead of using the default one.

Before you can install your own WalletConnect bridge, make sure you have the following:

  1. A server with public IP (for example, an AWS EC2 container) having the latest Ubuntu/Debian OS installed (other distros should work too, but we tested with Ubuntu 21.04).
  2. Root SSH access to the server.
  3. Server RAM should at least be 2GB. Recommended RAM for the server is 4GB+.
  4. Server disk space should be at least 40GB, preferably SSD, for faster response time.
  5. Cloudflare account with admin access. This method requires you to have an API Token (Not API key) ready before installing the bridge.

We recommend using a completely new server for the bridge and not use the server for anything other than the bridge.

Setting up Cloudflare for your Domain

Once you have the server ready, the first step would be to point your server to Cloudflare. To do that, log into your Cloudflare account and add the root domain (not, e.g., bridge.yourdomain.com, but yourdomain.com. We will work on the sub-domains at a later stage). Then follow the instructions, which in most cases would be to change the nameservers of the domain to point to Cloudflare. Once that is ready, let’s add a few A records. Go to the DNS menu from your Cloudflare Dashboard, and add the following records:

Type: A, name: @, Content: your.server.ip.address, TTL: Auto.
Set the proxy status to DNS only.
Type: A, name: www, Content: your.server.ip.address, TTL: Auto.
Set the proxy status to DNS only.
Type: A, name: bridge, Content: your.server.ip.address, TTL: Auto.
Set the proxy status to DNS only.

The third record can be different depending on the sub-domain you chose (for our case, we have bridge.domain.com), or it can be omitted altogether if you want to install the bridge on the root domain.

Setting up Cloudflare API Token

1. Go to my profile by clicking on the user icon on the top right corner of your Cloudflare dashboard. Alternatively, go to https://dash.cloudflare.com/profile while logged in.

2. Click on the API Tokens tab, and click on Create API Token.
3. Click the Use Template button beside the Edit zone DNS.
4. In Zone Resources, make sure Include is selected in the first select-box, Specific Zone is selected in the second select-box, and select your domain from the third select-box. Leave everything else as default. Then click on Continue to Summary.
5. Click on Create Token.

Copy the token value from the next page. Keep this somewhere secure, as this would be the only time the token would be visible.

Setting up the server

  1. First, log in to the SSH as a root user, and type in the following:
    sudo apt-get update && sudo apt-get upgrade -y

That will update the operating system with the latest patches.

2. Next, we need to install git, curl and make. To do that, type the following:
sudo apt-get install git -y && sudo apt-get install make -y && sudo apt-get install curl -y

Once done, we are finally ready to install docker. For this tutorial, we will be using the convenience script provided by docker. For a more detailed guide about installing docker, visit https://docs.docker.com/engine/install/ubuntu/.

3. To download the script, type the following:
curl -fsSL https://get.docker.com -o get-docker.sh

4. Now, let’s run the script we just downloaded by typing:
sudo sh ./get-docker.sh

That will install all the dependencies needed.

5. Let’s now start the docker daemon by typing:
sudo service docker start

6. Now, let’s enable swarm mode in docker by typing the following:
sudo docker swarm init

If everything went well, we are now ready to install WalletConnect on the server.

7. Clone the WalletConnect mono repo project from Github by typing the following:
git clone https://github.com/WalletConnect/walletconnect-monorepo

8. After git is done cloning the project, let’s go to the folder itself by typing:
cd walletconnect-monorepo/

9. Now type the following for deploying the WalletConnect bridge:
sudo make deploy

10. It will ask you a few questions — make sure they are answered correctly.

10.1 The first question would be the relay URL domain. Enter your bridge domain without http/https — for example, bridge.mydomain.com (this should be the same domain as setup earlier in Cloudflare). Press enter after entering the domain name.
10.2 The second question would be the email for the SSL certificate. Enter your email there and press enter.

11. Finally, it will ask for the CloudflareAPI token generated earlier. Enter that token, and press enter. Now let the bridge do its setup. Depending on your server, it generally takes 5–10 minutes, so it is good to be patient.

12. Once it’s done installing, try browsing to the following URL from your browser:
https://bridge.yourdomain.com/hello

If everything went well, you would see a message resembling:
Hello World, this is Relay Server v1.0.0@xyz

If you see the message, congratulations! You have successfully installed the bridge. In your dApp, you can now enter https://bridge.yourdomain.com as the bridge URL.

Upgrading and Maintenance

  1. It is always a good idea to update your server from time to time by running the following command:
    sudo apt-get update && sudo apt-get upgrade -y

That will ensure that the server always stays updated with the latest patches.

2. For updating the mono-repo itself, login to your server via ssh, then type the following to switch to the installation folder (depends on where you installed it in the first place):
cd walletconnect-monorepo
3. Then type:
sudo git pull && sudo make redeploy

That will pull the latest changes and do a re-deployment of the bridge.

Enjoy a more reliable Maiar WalletConnect flow :)
If you need technical assistance around this topic, please join the public Elrond Developers Telegram Group https://t.me/ElrondDevelopers.

Team BH Network

Find us on: https://linktr.ee/blackhatnetwork

--

--