This service monitors username changes in the Supabase database and provides gas funds to new user wallets on the Arbitrum network.
- Monitors username changes in Supabase (using realtime subscriptions)
- Sends gas to new wallets (configurable amount)
- Whitelist mode for testing
- Automatic gas funding on username changes
- RPC resilience with retry mechanism
- Detailed logging
- Database tracking of funded wallets
- Configure your environment variables in
.env:
# Server
PORT=3001
LOG_LEVEL=debug # options: debug, info, warn, error
# Supabase
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
# Arbitrum RPC URL
ARBITRUM_RPC_URL=https://rpc.ankr.com/arbitrum
# Funder wallet details
FUNDER_PRIVATE_KEY=your-private-key
FUNDER_ADDRESS=your-address
GAS_AMOUNT_TO_SEND=0.001
MAX_TX_PER_MINUTE=10
# Whitelist (optional, for testing)
WHITELIST_ENABLED=true
WHITELISTED_ADDRESSES=0x123...,0x456...
- Enable realtime for your tables in Supabase:
-- Run this in Supabase SQL Editor
DROP PUBLICATION IF EXISTS supabase_realtime;
CREATE PUBLICATION supabase_realtime FOR TABLE users, gas_tracking;
ALTER PUBLICATION supabase_realtime SET TABLE users, gas_tracking;- Install dependencies and build:
npm install
npm run buildnpm startTo test gas funding for a specific wallet:
cd gas-service
npx ts-node src/test-manual-trigger.ts <WALLET_ADDRESS>This will:
- Check the target wallet's balance
- Send gas from the funder wallet
- Update the gas_tracking table
- Log detailed information about the process
To verify realtime events are working:
cd gas-service
npx ts-node src/test-realtime.tsThis will set up a subscription to the users table and log all events it receives.
The service exposes a health check endpoint:
GET http://localhost:3001/health
If you encounter RLS errors when updating the gas_tracking table:
- Add your SUPABASE_SERVICE_ROLE_KEY to the .env file
- The service will automatically retry with the service role key
If realtime events aren't being received:
- Verify you've run the SQL to enable realtime for your tables
- Check the Supabase dashboard > Database > Replication to ensure your tables are listed
- Look at the debug logs to see if the subscription has been established
If you get an "Insufficient funder balance" error, add more ETH to your funder wallet.
Set LOG_LEVEL to control logging verbosity:
- debug: All logs (best for development)
- info: Normal operation logs (good for production)
- warn: Only warnings and errors
- error: Only errors