A discord bot which distributes GoErli Test Token to the members of a server and keeps track of the amount distributed.
-
Head over to https://discord.com/developers/applications/
-
Create a new application
- Give your Bot a name
- Get your bot's token and add it to your .env file (details below)
- Add the bot to your server
- Authorize the bot and it will appear in your server!
Note: The bot will stay offline until you run the bot's backend
-
Clone this repo
-
cp .env.example .env
and fill out the required variables, including the bot token from above -
Implement any custom checks you want your bot to run in the
receiverIsEligible
function insrc/goerliBot.js
- If you implement custom checks, make sure to pass in
true
when callingbot.commands.get('goerliBot').execute(message, args, 1, true);
- The bot is currently configured to send 33 goerli eth, and if the address already has 33 goerli eth it will not send
-
Add discord user id's to the maintainers command if you would like to
-
Run the bot with the following commands
npm install
node main.js
All values, constants and variables related to ETH, are standardized to 10^18.
FAUCET_ADDRESS
: You have to provide the faucet address here; the address of the wallet holding the goerli eth you will distributeFAUCET_PRIVATE_KEY
: You have to provide the faucet private key here; the private key of the wallet holding the goerli eth you will distributeDISCORD_BOT_TOKEN
: Bot token generated here.INFURA_HTTPS_ENDPOINT
: https://goerli.infura.io/v3/1cc5a78e2e72446880dee3ff4b82cae1. Infura HTTPS endpoint from settings on infura.ioETHERSCAN_API_KEY
ETHERSCAN_API_URL
: https://api.etherscan.io/apiDB_USERNAME
: Database usernameDB_HOST
: Database hostDB_PASS
: Database passwordDB_PORT
: Database port
api.js
util file for dealing with the Etherscan API to fetch latest block and transactions data.
getBlockNumber(time)
helper function uses the Etherescan API to get a specific block by time. This is a helper function for it. Please refer to this link to read more aboutget-block-number-by-timestamp
get requestgetTransactions(address, fromBlock)
helper function uses the Etherscan API to get an address's transactions array.fromBlock
parameter is the starting block. This function will return all the transactions from starting block till now.getBalance(address)
helper function returns the current balance of an addresscheckDeposit(address)
function returns an array containing all the transactions related toFAUCET_ADDRESS
in the last 48 hours. The array contains objects which have the structure:{hash: transactionHash, amount: amountSentToFaucet}
db.js
util file for updating and confirming transactions.
depositAmount
: Total ETH user should send to theFAUCET_ADDRESS
. In our case,32000000000000000000
.dailyLimit
: The max daily amount an address can haveweeklyLimit
: The max weekly amount an address can haveconfirmTransaction(addressDetails, topUpAmount)
: It is the main function where all helper functions come together to validate the transactions of a certain address. It deals with several edge cases.addressDetails
param is stored and fetched from the database viacheckAddressExists(address)
.validateTransaction(addressDetails, topUpAmount)
: Helper function used byconfirmTransaction
to validate whether or not an address has sent a new transaction of the required amount of ETH to the faucet address. Returnstrue
if such a transaction exists otherwisefalse
. The transactions of a certain address over the last 48 hours, are fetched viacheckDeposit(address)
helper function.
goErliBot.js
file where all the exports in db.js
, api.js
, and utils.js
, come together and then exported to main.js
file in a single function runGoerliFaucet(message, address, amount, runCustomChecks)
.
maxDepositAmount
: You have to set its value. It's the max amountFAUCET_ADDRESS
can send (32000000000000000000
in our case)runCustomEligibilityChecks(address)
:topUpAmount
is calculated like so:maxDepositAmount - currentBalance
, wheremaxDepositAmount
is the limit set by us which is32000000000000000000
in our case andcurrentBalance
is the current GoErli GoETH balance of an address.runGoerliFaucet(message, address, amount, runCustomChecks)
: Contains several checks to ensure that the address provided by a user is eligible and valid.message
param is the original message sent by the user on Discord.address
is the address provided by the user.amount
is the amount requested by the user.runCustomChecks
bool value to decide if custom checks are to be run or not.
utils.js
util file containing the necessary methods to conduct GoErli ETH transactions.
main.js
file which deals with Discord API via discord.js
module. Recieves the command of a discord member, processes their request and dispatches the appropriate message in response.
- Take a look at "Test Zone", at the bottom of
src/goerliBot.js
and write the appropriate function calls for the tests you want to run (you can bypass the actual bot here and test the underlying functions) - Use
npm install
thennode src/goerliBot.js
to run the tests
This bot is forked from Stake-house/GoErli-Eth-Bot