OpenMonero Web Wallet Setup

Started by asymptotically, Aug 06, 2020, 07:22 AM

Previous topic - Next topic

asymptotically

**WIP: Don't follow yet or your computer and WOWs might go kaboom.**

https://funding.wownero.com/proposal/36

## 1. System Requirements

The only real requirement is a server that you have root access to, but I would recommend at least two cores, 4 GiB of RAM, and 20 GiB of disk space (on an SSD) even if you're going to be the only person using the server, otherwise it will be painfully slow to setup and use.

You will also want a domain name so that you can get a shiny new certificate from LetsEncrypt.

## 2. Build Wownero

Firstly, we need to build Wownero from source. We can't use the release binaries because OpenMonero depends on some libraries and headers not present in them.

### 2.1. Install dependencies



Debian and derivatives


```bash
sudo apt update
sudo apt install \
  gcc \
  g++ \
  cmake \
  ninja \
  git \
  libboost-all-dev \
  libssl-dev \
  libzmq3-dev \
  libpgm-dev \
  libunbound-dev \
  libsodium-dev
```




Gentoo


```bash
echo 'dev-libs/boost nls threads' | sudo tee -a /etc/portage/package.use/monero
echo 'net-dns/unbound threads' | sudo tee -a /etc/portage/package.use/monero
sudo emerge --changed-use --deep @world
sudo emerge \
  dev-libs/boost \
  dev-libs/libsodium \
  dev-libs/openssl \
  net-dns/unbound \
  net-libs/czmq \
  virtual/pkgconfig
```


### 2.2. Clone, configure, and build

```bash
cd
git clone https://git.wownero.com/wownero/wownero.git
cd wownero
git checkout v0.8.0.2
git submodule update --init --recursive
mkdir -p build/release
cd $_
cmake ../.. \
  -GNinja \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_TESTS=OFF \
  -DUSE_DEVICE_TREZOR=OFF
ninja
```

## 3. Build OpenMonero

Next we need to compile the OpenMonero server that people will connect to. The repo also contains a web frontend that you can modify to wowify.

### 3.1. Install dependencies



Debian and derivatives


```bash
sudo apt install \
  libcurl4-gnutls-dev \
  libmysql++-dev \
  libunwind-dev
```




Gentoo


```bash
sudo emerge \
  dev-db/mysql++ \
  sys-libs/libunwind
```


### 3.2 Clone, configure, and build

```bash
cd
git clone https://github.com/moneroexamples/openmonero.git
cd openmonero
git submodule update --init --recursive
sed '/"\/external\/easylogging++\/"/a "\/external\/RandomWOW\/"' src/xmregcore/cmake/FindMonero.cmake
cmake -Bbuild \
  -DCMAKE_BUILD_TYPE=Release \
  -DMONERO_DIR=~/wownero
cd build
make # use -jN at your own peril...
```

## 4. Database setup

You can run the database however you want, including in a Docker container or something managed from your host. It needs to be MySQL or a compatible fork like MariaDB, though.

This guide will assume that you are installing the database on the same machine that runs everything else.

### 4.1. Install MariaDB



Debian and derivatives


```bash
sudo apt install \
  mariadb-client \
  mariadb-server
```




Gentoo


```bash
sudo emerge mariadb
```


### 4.2. Configure MariaDB

1. Run the provided security script:
   
    ```bash
    sudo mysql_secure_installation
    ```

2. Leave the initial password blank (we have not set one yet) and just press return.

3. Say **no** to setting a root password. Setting one will break some automated maintenence scripts.

4. Say **yes** to the other questions, to remove anonymous users and the test database, and to disable remote root logins.

### 4.3. Create a database user

1. Open an SQL shell:
   
    ```bash
    sudo mysql
    ```

2.  Create a database:
   
    ```sql
    CREATE DATABASE openmonero;
    ```

3. Create a user that can do anything to the new database:
   
    ```sql
    GRANT ALL ON openmonero.* TO 'openmonero'@'localhost' IDENTIFIED BY 'GoodShibe123' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    ```

4. Exit the shell:
   
    ```sql
    exit
    ```

### 4.4. Import database schema

Firstly open `~/openmonero/sql/openmonero.sql` in your favourite editor and change `VARCHAR(95)` to `VARCHAR(100)`.

```bash
mysql -u openmonero -p openmonero < ~/openmonero/sql/openmonero.sql
```

Enter the password `GoodShibe123` (or whatever you set) when prompted.

## 5. Wownero daemon setup

1. Copy daemon executable to PATH:
   
    ```bash
    sudo cp ~/wownero/build/release/bin/wownerod /usr/local/bin/
    ```

2. Create a user:
   
    ```bash
    adduser \
      --system \
      --no-create-home \
      --group \
      wownero
    ```

3. Create a config file:

    ```bash
    cat << EOF | sudo tee /etc/wownerod.conf
    data-dir=/var/lib/wownero
    log-file=/var/log/wownero/wownerod.log
    log-level=0
    EOF
    ```

4. Create a systemd unit:

    ```bash
    cat << EOF | sudo tee /etc/systemd/system/wownerod.service
    [Unit]
    Description=Wownero Full Node
    After=network-online.target
    Wants=network-online.target
   
    [Service]
    User=wownero
    Group=wownero
    StateDirectory=wownero
    LogsDirectory=wownero
    Type=simple
    ExecStart=/usr/local/bin/wownerod --config-file /etc/wownerod.conf \
      --non-interactive
   
    [Install]
    WantedBy=multi-user.target
    ```

5. Start wownerod and enable it to start on boot:

    ```bash
    systemctl enable --now wownerod.service
    ```

6. Make sure that wownerod is working properly with `tail /var/log/wownero/wownerod.log`. You should be able to watch as you get synced up to the network.

## 6. API server setup

1. Copy daemon executable to PATH:
   
    ```bash
    sudo cp ~/openmonero/build/openmonero /usr/local/bin/
    ```

2. Create a user:
   
    ```bash
    adduser \
      --system \
      --no-create-home \
      --group \
      openmonero
    ```

3. Copy the default config:

   ```bash
   sudo cp ~/openmonero/config/config.json /etc/openmonero.json
   ```

4. Open the `/etc/openmonero.json` file in your favourite editor and change:

    * `daemon-url.mainnet` to `"http://127.0.0.1:34568"`
    * `blockchain-path.mainnet` to `"/var/lib/wownero/lmdb"`
    * `database.user` to `"openmonero"`
    * `database.password` to `"GoodShibe123"` (or whatever you picked)
    * `wallet_import.mainnet.address` to `"Wo3MWeKwtA918DU4c69hVSNgejdWFCRCuWjShRY66mJkU2Hv58eygJWDJS1MNa2Ge5M1WjUkGHuLqHkweDxwZZU42d16v94mP"`
    * `wallet_import.mainnet.viewkey` to `"e62e40bfd5ca7e3a7f199602a3c97df511780489e1c1861884b00c28abaea406"`

5. Create a systemd unit:

    ```bash
    cat << EOF | sudo tee /etc/systemd/system/openmonero.service
    [Unit]
    Description=Wownero Full Node
    After=wownero.service
    Wants=wownero.service
   
    [Service]
    User=openmonero
    Group=openmonero
    LogsDirectory=openmonero
    Type=simple
    ExecStart=/usr/local/bin/openmonero --config-file /etc/openmonero.json \
      --log-file /var/log/openmonero/openmonero.log
   
    [Install]
    WantedBy=multi-user.target
    ```

6. Start openmonero and enable it to start on boot:

    ```bash
    systemctl enable --now openmonero.service
    ```

## 6. Web server setup

We need a web server to serve our spicy frontend and to proxy requests to the API. You can use any web server that you want, but this guide will use NGINX.

### 6.1. Install NGINX



Debian and derivatives


```bash
sudo apt install nginx
```




Gentoo


```bash
sudo emerge www-servers/nginx
```


### 6.2. Serve frontend

1. Copy the frontend assets somewhere nice:
   
    ```bash
    sudo cp -rv ~/openmonero/html /var/www/openmonero
    ```

2. Open up `/etc/nginx/sites-enabled/default` in your favourite editor and make it look like this:

    ```conf
    server {
        listen 80;
   
        server_name wowllet.biz; # replace with your domain
   
        index index.html;
        root /var/www/openmonero;
   
        location / {
            try_files $uri $uri/ =404;
        }
   
        location /api/ {
            proxy_pass http://localhost:1984/;
        }
    }
    ```

### 6.3. Configure the frontend

Open up `/var/www/openmonero/js/config.js` up in your favourite text editor as we need to WOWify some things.

* Change `apiUrl` to `"https://yourdomain.com/api/"`
* Change `mainnetExplorerUrl` to the address of your favourite compatible block explorer, like `"https://explore.wownero.com/"`
* Change `nettype` to `0`
* Change `coinUnitPlaces` to `11`
* Change `txMinConfirms` to `4`
* Change `coinSymbol` to `"WOW"`
* Change `openAliasPrefix` to `"wow"`
* Change `coinName` to `"Wownero"`
* Change `coinUriPrefix` to `"wownero:"`
* Change `addressPrefix` to `4146`
* Change `integratedAddressPrefix` to `6810`
* Change `subAddressPrefix` to `12208`
* Change `defaultMixin` to `20`
* Change `avgBlockTime` to `300`

Edit the HTML and stylesheets however you want :dog2: :hotdog:

### 6.4. Set up HTTPS

#### 6.4.1. Install certbot



Debian and derivatives


```bash
sudo apt install \
  python3-certbot \
  python3-certbot-nginx
```




Gentoo


```bash
sudo emerge \
  app-crypt/certbot \
  app-crypt/certbot-nginx
```


#### 6.4.2. Run certbot

```bash
sudo certbot --nginx -d wowwlet.biz # replace with your domain
```

Follow the prompts, agree to the ToS, sign away your first born children, etc. When asked if you want a redirect, say yes (option 2).

## 7. Finishing up

* Set up automated updates.
* Configure a firewall to only allow traffic in to port 80 and 443, and to rate limit port 22 (or to only allow connections to port 22 from your IP address).
* Monitor resource usage like disk space and memory to make sure that your server isn't dying.

***

Thanks to @qvqc for going through and making sure that the guide was correct :)