Demo: How to create a Faucet

From Garlicoin Wiki
Jump to navigation Jump to search

Understand the Structure

Garlicoin-faucet2.png

(Blue square indicates this work is happening in a single Virtual Machine)


The Faucet contains one customer feature: put in a catchpha, and we will send a random amount of Garlicoin to the relevant wallet. In the following image:

1. Customer browser contacts DNS service to get the IP address of the Faucet.

2. The Apache Web Server checks the validity of the catchpha by calling Google's HTTP API.

3. Apache Web Server determines source IP.

4. Using a free web service (for Faucet 2: https://getipintel.net/), check that the IP is not part of a VPN list or part of a locally set banlist.

5. Check the valid IP address to see if it has used the Faucet in the cooldown period. This prevents spam.

6. We know that the request is valid, so call the RPC client and trigger a transaction of a random number of Garlicoin.

7. Request is sent to mainnet.

Create Virtual Machine

Use AWS, GCP, Azure, or a on-prem hardware. For this tutorial, I will use an Ubuntu system.

Host Garlicoin Core full node

https://garlic.wiki/index.php/How_To_Host_A_Garlicoin_Full_Node

Create MySQL Table

Download Mysql:

 sudo apt update
 sudo apt install mysql-server

Install:

 sudo mysql_secure_installation

This should install mysql with access through root.

Run:

 sudo mysql

Then:

 CREATE DATABASE IF NOT EXISTS `faucet`;
 USE `faucet`;

Creates Faucet Database

 CREATE TABLE IF NOT EXISTS `users` (
   `address` varchar(35) NOT NULL,
   `time` int(11) unsigned NOT NULL,
   `ip` varchar(17) NOT NULL,
   `amount` varchar(7) NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Create Users table with fields address, lastAccessTime, ip, amount.

Host Apache Web Server

Use Googl => https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04


Write index.php

Then host an index.php as seen here https://github.com/smiba/CryptoFaucet/blob/master/index.php

The code manages:

- Finding the source IP

- Checking the MySQL database and adding entries on events

- Catchpha verification

- RPC commands sent to Garlicoin node