What is a Paymaster?
A paymaster is a service that pays transaction fees on behalf of users. Instead of requiring users to hold SOL for gas fees, the paymaster covers these costs, creating a seamless onboarding experience. Benefits:- Users don’t need SOL for transaction fees
- Lower barrier to entry for new users
- Better user experience for dApps
Prerequisites
Before using the paymaster SDK:- Create a paymaster in the Developer Portal
- Fund your paymaster with SOL
- Get your API key from the Developer Portal
Paymasters require a paid subscription (PRO, ULTRA, or ENTERPRISE). See Subscriptions & Billing for details.
Installation
Choose the package that matches your Solana SDK version:- Classic (web3.js 1.x)
- Kit (web3.js 2.0)
@solana/web3.js version 1.x (the traditional Solana SDK).Configuration
Create a paymaster client with your credentials:- Classic (web3.js 1.x)
- Kit (web3.js 2.0)
Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | API key from Developer Portal |
paymasterPubkey | string | Yes | Paymaster public key |
baseUrl | string | Yes | Paymaster API URL (https://api.onswig.com) |
network | 'mainnet' | 'devnet' | Yes | Solana network |
customRpcUrl | string | No | Custom RPC endpoint (overrides default) |
retryOptions | object | No | Retry configuration for failed requests |
Retry Options
Configure automatic retries for transient failures:Quick Start
Here’s a minimal example to sponsor a transaction:- Classic (web3.js 1.x)
- Kit (web3.js 2.0)
Transaction Flow
The paymaster transaction flow works as follows:- Create Transaction: Build the transaction with the paymaster set as the fee payer
- User Signs: User signs to authorize the transaction
- Paymaster Signs: Paymaster validates and signs (covering the fee)
- Submit: Transaction is sent to the Solana network
Next Steps
- Sponsoring Transactions - Detailed examples and methods
- Advanced Usage - Error handling, retries, versioned transactions
- Create a Paymaster - Set up your paymaster in the Developer Portal

