Earn Brave Rewards With Hugo
How to earn crypto by configuring your site for Brave Rewards. Also a true story on how a few minutes of debugging can save you seconds of reading the documentation.

Brave is a Chromium-based browser that claims itself to be privacy focused. It also has this Brave Rewards system where it pays user money (actually a cryptocurrency called Basic Attention Token, or BAT) for viewing ads (spoiler: you are not going to get rich in this way). If users don’t want this money, they can donate to support content creators like website owners, YouTubers, etc. Never mind their claims are true or not. This post explains how you can earn some BAT with a Hugo built site like this one hosted anywhere, or any static site on GitLab pages.

If you are here just to copy some quick commands, jump to the end section.

Why

I’m not a fan of Brave but I installed it on an old laptop to try out. Over a few months of using I accumulated 2 units of BAT, which is worth of slightly more than $1 at the time of writing. Hosting this site costed me 0 in terms of money, so if I donate the BATs to myself, I can claim myself with a profitable website! Also you get to learn a very tiny detail on how static site generators work, and what you can do with GitLab CI/CD. Last by not least, the whole thing demonstrated a popular programmer meme.

How

Go to the Brave Rewards for publishers page, sign up with your email. Add a website channel, enter your website domain (<username>.gitlab.io), choose Download a trusted file. Brave wants you to download a simple text file and put it to the .well-known folder on your domain. For example, just have a look of the verification file of this site.

So the real ’technical’ question is: how to put a specific file to a specific path to a Hugo / GitLab Pages site?

The GitLab Way

This should actually work with any static site hosted by GitLab. Actually you should be able to build a site that the only purpose it to host the Brave verification file so that you can do some online begging by asking people to send BAT there.

Unnecessary Background Story

By the time I first did this, I have no idea how Hugo actually works, but the .gitlab-ci.yml file from GitLab’s Hugo example seemed very straightforward: there was a script section, which had one single command hugo.

From my experiences with Dockerfile and docker-compose.yml files, I learned that all these yaml files are suspicious. They pretended to be configurations but also include pieces of codes here and there. So I guessed that, what actually happens with GitLab CI/CD was that, they pretended that my repo was their current working directory, ran the command in script section, then copied everything from the resulted public directory to the final site for hosting. All I need to do is to tell GitLab to copy one more file! And the command for copying files is cp.

So I committed the file at .well-known/brave-rewards-verification.txt, then added another command under the script section: cp .well-known/brave-rewards-verification.txt public/.well-known/brave-rewards-verification.txt.

Immediately I got email-notified that my CI/CD pipeline failed. By checking the failure logs I found:

$ cp .well-known/brave-rewards-verification.txt public/.well-known/brave-rewards-verification.txt
cp: can't create 'public/.well-known/brave-rewards-verification.txt': No such file or directory
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

OK, so cp doesn’t work if the directory in its path doesn’t already exist. A little Google confirmed this. All I need to do was add another command before cp: mkdir -p public/.well-known/, which creates the directory (-p makes sure all parent directories will also be created as needed).

The Resulted Ugly Solution

Commit the file at .well-known/brave-rewards-verification.txt under the repo. Then edit the specific part of .gitlab-ci.yml to this:

pages:
  script:
  - hugo
  - mkdir -p public/.well-known/
  - cp .well-known/brave-rewards-verification.txt public/.well-known/brave-rewards-verification.txt

The Hugo Way

This, on the other hand, should work with any Hugo generated site, be it GitLab, GitHub, or others. Actually Hugo documented this use clearly. Things under the static directory will be copied to public when the site is served.

Just commit the file at static/.well-known/brave-rewards-verification.txt. No need for other changes. You know what they say? A few hours of debugging saves you 5 minutes of documentation reading! While it actually took me a few minutes but it happened somewhere else before.

Meme

Just List the Commands

There really isn’t much commands. Let’s say you’ve downloaded the brave-rewards-verification.txt file from the Brave Rewards for publishers page to ~/downloads/. Just go to your repository root directory:

# make sure the dir exists
mkdir -p static/.well-known/

# copy the downloaded file 
cp ~/downloads/brave-rewards-verification.txt static/.well-known/brave-rewards-verification.txt

# git stuff
git add .
git commit -m 'brave rewards'
git push

You also need to wait for about 1 day for it to take effect. Then you can earn a few pennies every month by donating to yourself!

Updates (Caveats)

After more than a year 1 of using Brave (only on some of my devices), I have stopped completely. As a browser it worked as expected, but the system around BAT didn’t work very well for me.

First of all, seeing ads is annoying. In order to earn BATs, you have to enable ads. Brave send you ads as system notifications (at least on Windows and Android), which is even more annoying than the usual banners or pop-ups from normal websites.

Secondly, I wasn’t able to collect the BATs for at least 3 months in a row. What typically happens is that you see ads for a month, and there is a counter that estimates your earnings (typically 4 or 5 BATs). Then you can collect these BATs in the next month. What actually happened to me for quite a few months was that while the earning estimates were normal, no BATs were collected after I solve the CAPTCHA.

Thirdly, actually using BAT outside of Brave’s system (i.e., withdraw and trade) requires KYC verification from their partner exchanges. I’m not a fan of KYC so I prefer not becoming a verified creator for Brave. After all, I only earned 33.96 BAT by seeing all those ads.

In conclusion, the experiment is ended now.


  1. The post was first made on 2021-09-27, and now I’m updating it on 2023-01-07. ↩︎


Last modified on 2023-01-07