This discord bot is intended to disburse a HTS tokens to holders of a specific NFT. Owners of the NFT are entitled to a fetch of the faucet every 24 hours. This faucet employs sybil checks, so a user cannot send the same NFT to themselves and fetch from the faucet multiple times. If you purchase an NFT that has already been used to fetch from the faucet today, wait until the faucet reset for fetches to resume normally.
The bot is an interaction of three technologies: Hedera, Discord, and Supabase. Interacting with these three technologies requires a hedera private key, a discord client secret key, and your Supabase key. Keep all three secret. To minimize costs, it will be deployed on DigitalOcean as a Droplet (Ubuntu version 22.04) and utilizes Supabase for its database.
- DigitalOcean: https://www.digitalocean.com
- Supabase: https://supabase.com/
Using the two platforms should minimize the cost of running the bot. The keys and token details need to be saved into an environment file ( .env). Once the .env file is ready, the bot is ready to deploy on the Droplet. I recommending pasting the .env.example into a text editor like notepad and filling out the lines in it as you set up all the services.
The best practice is to set up a dedicated wallet to fund your faucet. Create a new Hedera account, and note its token ID and private key. Fund the wallet with your HTS token and some HBAR to cover gas. As of 2024, an HTS transfer costs $0.002 .
Add the following information to your env file:
HEDERA_OPERATOR_ID = your faucet wallet's account ID
HEDERA_OPERATOR_PRIVATE_LEY = the private key of the faucet wallet (keep secret)
HEDERA_TOKEN_ID = the token ID of the HTS token you wish to distribute with the faucet
HEDERA_TOKEN_DECIMALS = the decimal precision of your token
HEDERA_TOKEN_DRIP_RATE = how many tokens the faucet should distribute to each user per 24 hours
NFT_ID = the ID of the NFT that gates access to the faucet
Navigate to https://discord.com/developers/applications and create a new application Under the "Bot" tab, give it Presence Intent, Server Message Intent, and Message Content Intent. Click "Reset token", and copy its value into DISCORD_TOKEN. Give your bot a name and icon.
Navigate to the Oath 2 tab, and copy the CLIENT ID. Store it in your file under DISCORD_CLIENT_ID. Go to your discord server. Discord URLs take the form of discord.com/channels/{SERVER_ID}/{CHANNEL_ID} Copy the Server ID into DISCORD_SERVER_ID Copy the Channel ID into DISCORD_CHANNEL_ID
Go to "URL Generator" and give the bot the "bot" scope".
Refer to the tutorial here
- Supabase: https://supabase.com/
Create a new account and start a new project. Under "Project Configuration", copy the URL into SUPABASE_URL Locate the key labeled service_role secret Copy the service key into SUPABASE_SERVICE_KEY
Create a table named fetches
, and create a column called accountId
of type text
.
Create a second table named serials
, and create a column called serial
of type text
.
These tables can be viewed daily to see which accounts have used the faucet, and which NFTs were used.
DO NOT SHARE YOUR SERVICE KEY AND KEEP IT ONLY TO THE BACKEND!!!
At this point every field in your env file should be filled. Here is a recap of all the data that should be in your env file:
DISCORD_CLIENT_ID
Your Discord bot's ID from the Discord Developer Portal
DISCORD_CHANNEL_ID
Your Discord Channel's ID obtained after enabling Developer Mode
DISCORD_SERVER_ID
Your Discord Server's ID obtained after enabling Developer Mode
DISCORD_TOKEN
Your Discord bot's token given upon bot creation
HEDERA_NETWORK
Testnet, Mainnet, and Previewnet are all valid choices here
HEDERA_OPERATOR_ID
Your Hedera Account ID that will be paying for all TX fees
HEDERA_OPERATOR_PRIVATE_KEY
Your Hedera Private Key associated to the account ID above
REMEMBER NOT TO SHARE THIS, AND KEEP IT TO THE BACKEND TO NOT LEAK OF THIS CRUCIAL SECRET
HEDERA_TOKEN_DECIMALS
The decimals of the HTS token that will be disbursed
HEDERA_TOKEN_DRIP_RATE
Can be a float or integer, depends on how much of the token you want to be disbursed
HEDERA_TOKEN_ID
The token of the HTS token that will be disbursed
HEDERA_REST_API_VERSION
Set this to v1, as Hedera does not have any other versions of the rest api at this time
SUPABASE_SERVICE_KEY
Obtained from your Supabase settings after starting a new project
REMEMBER NOT TO SHARE THIS, AND KEEP IT TO THE BACKEND TO NOT LEAK OF THIS CRUCIAL SECRET
SUPABASE_URL
Obtained from your Supabase settings after starting a new project
https://www.digitalocean.com Create an account , create a Project, and deploy a Droplet. The cheapest droplet at 4/mo should be sufficient. Navigate to your droplet. The setup will be completed within the Console. The following commands you should be able to copy, then right click inside the console and "Paste as plain text"
-
Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
-
Close the console, and then open it again.
-
Run the last of the installs below: Note your node version
nvm install node
node -e "console.log('Running Node.js ' + process.version)"
sudo apt install git
git clone https://github.com/jbuildsdev/sauceinubot.git
cd sauceinubot
npm install
-
Create the .env file
sudo nano .env
Paste your env values into the file. Press ctrl+o to save, and hit enter. Press ctrl+x to exit.Note: If this is a redeployment of the bot to use !fetch instead of /fetch, you need to clear the registered commands from Discords server. To do so run the following commands:
cd src
node clearCommands
-
Create the service
sudo nano /etc/systemd/system/sauceinubot.service
[Unit]
Description=sauceinubot
After=multi-user.target
[Service]
ExecStart=/root/.nvm/versions/node/v21.6.2/bin/node /root/sauceinubot/src/main.js
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sauceinubot
User=root
[Install]
WantedBy=multi-user.target
Be sure to replace the node version in ExecStart with your current node version, if it is no longer 21.6.2. Press crtl+o to save, and ctrl+x to exit.
- Start the service
sudo systemctl start sauceinubot
Check if it worked. Run the command systemctl status sauceinubot
You should see Active: active (running)
- Join Bot to server
Return to the discord developer page. Go to URL generator, and paste the URL into the brower. Join your bot to your Discord server.
You can now begin fetching tokens from your faucet using the command /fetch accountID