When I tried out Hathor for the first time, I was immediately impressed with the speed and zero transaction fees. If you've used other blockchains before, you know there are almost always transactions fees and it can take a while before a transaction is confirmed. That's why I think everybody should at least try out Hathor, because once you experience Hathor you are convinced of it's capabilities.

When Hathor announced it's grant program, I submitted my grant proposal for a Hathor Faucet. The faucet gives out a tiny bit of Hathor, so you can try out the network without the need to buy Hathor on an exchange. My proposal to develop a Hathor Faucet was selected for a Hathor Grant.

In this blog post I will write about developing the faucet.

What is a cryptocurrency faucet?

Many blockchain projects have a faucet. It gives away a small amount of tokens so you can try out the network. Most networks also have a testnet and a testnet faucet. Tokens on the testnet have no value, so testnet faucets are more generous and more focused on developers building integrations.

Programmable Wallet

Most Hathor users use the mobile or desktop wallet. But the faucet needs a programmable wallet, so we can programmatically send Hathor tokens (HTR) to users who submit their wallet address. Luckily, a great programmable wallet is supplied by the team. It's available on GitHub and runs in a Docker image.

Hathor Headless Wallet on GitHub

It's very easy to setup using Docker:

docker pull hathornetwork/hathor-wallet-headless
docker run -p 8000:8000 hathornetwork/hathor-wallet-headless --seed_default "YOUR 24 SEED WORDS"

The programmable wallet has JSON APIs developers can use. They are documented using a Swagger endpoint. For example to get the balance of the wallet:

$ curl -H "X-Wallet-Id: {wallet-id}" http://localhost:8000/wallet/balance

Why not use a full Hathor node on Ankr?

A Hathor full node also has a JSON API developers can use. But it's a bit more complex. The full node downloads the full blockchain and needs more storage and compute power than the headless wallet. The full node can manage multiple wallets, but we only need to manage one wallet. So we pick the easier solution and use the programmable wallet docker image. This docker image connects to a full node. So a full node is needed. In this case we make use of a full node that is run by the Hathor team.

Documentation of the APIs on a Hathor full node can be found on: https://docs.hathor.network/

C# Client library

I'm developing the Hathor Faucet with ASP.Net Core in C#. So I need a way to easily communicate with the JSON APIs. Therefore I've created a C# wallet library. This makes it easy to send requests to the headless wallet. I've also made it open source, so other developers can use it to integrate their apps with Hathor.

Hathor.Client on GitHub

The library needs some setup, like URL of the wallet and an API key:

IHathorWalletApi client = HathorClient.GetWalletClient("http://localhost:8000", "my-wallet", "api-key");

Sending Hathor to an address can then be done in just one or two lines of code:

var transaction = new SendTransactionSimpleRequest("ADDRESS", 1);
var response = await client.SendTransaction(transaction);

Of course, we can also check how much tokens there are left:

var balance = await client.GetBalance();

With this library, building on Hathor got even easier!

Protecting the faucet

Now that we have a programmable wallet running and we can communicate with it using C#, we only need a website with a simple form where users can submit their Hathor address to send them some Hathor tokens.
The biggest challenge of the faucet is to protect is from abuse. It's giving away free Hathor (free money!). So there will be people that try to cheat. It's meant for new users, to try it out once. Not to accumulate more Hathor for yourself.

There are multiple layers of protection implemented, like a Captcha and IP block. It also checks the balance of your Hathor address. Did you already use Hathor before? Then you won't get any new Hathor, because it's meant for new users.
There's also a possibility to block IP ranges. Because even though it's only giving away a few cents and you need a new address and new IP every time, there are still people who use it multiple times. In that case I can block a whole IP-range.

Try out the Hathor Faucet and get some free HTR, or send some HTR to the faucet. Because if it's empty, no one can use it. https://www.gethathor.com/

What's next?

Development with Hathor was very smooth and a lot of fun. It's great to be able to send out so many free HTR to the community that's also provided by the community.
I can't wait to try out NANO contracts when they will be available and see what's possible.
And I might add support for custom tokens in the future? So the faucet can also give away free custom tokens.
You can stay up to date with Hathor developments on their official website: https://hathor.network

Do you want to develop with Hathor?

Check out the client library, it's open source and available on GitHub.

The full Hathor faucet website is also open source! Check it out on GitHub.