This is a service to sponsor Stacks transactions on users' behalf.
The service provides an API /execute
that accepts a serialized sponsored Stacks transaction hex string. It will verify the transaction, and submit it to the Stacks blockchain using one of the sponsor accounts configured.
The service tracks the status of all pending and submitted transactions in a PostgreSQL database, and handles re-submitting transactions using replace-by-fee (RBF) if they are not settled after certain blocks.
src/main.ts
- Starts up the Express server, worker process and health/status check endpointssrc/execute.ts
- Handles/execute
API requestssrc/submit-transactions.ts
- Submits pending transactions from DBsrc/sync-transactions.ts
- Syncs status of submitted transactionssrc/rbf-transactions.ts
- Replaces submitted transactions using RBF if neededsrc/worker.ts
- Background worker that runs the sync and RBF transactions process
The service is configured via environment variables:
STACKS_API_URL
- Stacks API endpointSTACKS_NETWORK_TYPE
- Eithermainnet
ormocknet
SPONSOR_ACCOUNT_ADDRESS
- Sponsor account addressSPONSOR_ACCOUNT_SECRETKEY
- Sponsor account secret keyPOSTGRES_*
- PostgreSQL connection config
The user_operations
table tracks pending and submitted user transactions.
The sponsor_records
table tracks info about all sponsored transactions submitted.
- Node.js
- PostgreSQL
Configure environment variables:
cp .env.example .env
Start service:
npm run dev