Blockchain event synchronization script for syncing event data from Oasis Network to Supabase database.
- ✅ Supports event synchronization for multiple contracts (TruthBox, TruthNFT, Exchange, FundManager, UserId)
- ✅ Incremental synchronization with automatic progress tracking
- ✅ Automatic IPFS metadata fetching
- ✅ Supports proxy mode (local development) and direct connection mode (GitHub Actions)
- ✅ Complete error handling and logging
-
Install Dependencies
cd eventSyncScript npm install -
Configure Environment Variables
# Copy public configuration template cp .env.example .env # Create local configuration file (contains sensitive information) cp .env.example .env.local # Edit .env.local file and fill in Supabase configuration: # - SUPABASE_URL # - SUPABASE_ANON_KEY # - SUPABASE_SERVICE_ROLE_KEY
Note:
.envfile contains public configuration and can be committed to the repository.env.localfile contains sensitive information (Supabase configuration) and will not be committed- Configuration in
.env.localwill override same-named configuration in.env
-
Run Script
npm start
-
Configure GitHub Secrets
- Go to repository settings:
Settings>Secrets and variables>Actions - Add the following Secrets:
SUPABASE_URL: Supabase project URLSUPABASE_SERVICE_ROLE_KEY: Supabase Service Role Key
- Go to repository settings:
-
Workflow Runs Automatically
- Scheduled trigger: Every 5 minutes
- Manual trigger: Click "Run workflow" on the GitHub Actions page
The project supports two types of environment variable files:
-
.env- Public configuration, can be committed to repository- Contains public configuration for event sync script
- Does not contain sensitive information
- Example:
.env.example(template file)
-
.env.local- Local configuration, not committed to repository- Contains sensitive information such as Supabase credentials
- Overrides same-named configuration in
.env - Already added to
.gitignore
Environment variable loading priority (from highest to lowest):
.env.localfile (local configuration, overrides other configurations).envfile (public configuration)- System environment variables
SUPABASE_URL: Supabase project URLSUPABASE_SERVICE_ROLE_KEY: Supabase Service Role Key
EVENT_SYNC_USE_PROXY: Whether to use proxy (true/1to enable, disabled by default)EVENT_SYNC_SAVE_JSON: Whether to save JSON files (true/1to enable, disabled by default)EVENT_SYNC_FROM_BLOCK: Specify starting block heightEVENT_SYNC_LIMIT: Limit on number of events per queryEVENT_SYNC_BATCH_SIZE: Batch size
Located in src/local/ directory:
decodeEventsExample.ts- Event decoding exampledownloadIpfsFile.ts- IPFS file download tool
Run with:
npm run decode:events
npm run download:ipfs-
Proxy Connection Failed
- Check
EVENT_SYNC_USE_PROXYsetting
- Check
-
Supabase Connection Failed
- Check if
SUPABASE_URLandSUPABASE_SERVICE_ROLE_KEYare correct - Verify Supabase project status is normal
- Check if
-
Sync Progress Not Updating
- Check if
sync_statustable is updated correctly - Check logs to confirm if there are any errors
- Check if
[According to project license]