A Solana adapter for Gasless Relayer, providing a simple and consistent interface for interacting with Solana wallets and the Solana blockchain.
- Connect to Solana wallets (Phantom, etc.)
- Send transactions
- Sign messages
- Get account balances
- React components and hooks for easy integration
- TypeScript support
- Error handling
- Event handling
- Gasless transactions: Submit transactions through a relayer that sponsors gas fees
- Automatic fallback: If relayer is unavailable, transactions fall back to regular transactions
- Project tracking: Add your project ID for tracking and monitoring transaction activity
npm install sol-gasless-adapter
# or
yarn add sol-gasless-adapter
import { SolanaAdapter } from 'sol-gasless-adapter';
const adapter = new SolanaAdapter({
connectionSettings: 'confirmed',
// Optional: For project tracking and monitoring
projectId: 'your-project-id',
// Optional: Custom relayer URL (defaults to https://sol-relayer.fly.dev/api)
relayerApiUrl: 'https://your-custom-relayer-endpoint.com/api',
});
// Connect to a wallet
const result = await adapter.connect({
provider: window.solana,
providerType: 'solana',
});
// Get balance
const balance = await adapter.getBalance({
address: result.address,
currency: 'SOL',
});
// Sign message
const signResult = await adapter.signMessage({
message: 'Hello, Solana!',
provider: result.provider,
providerType: 'solana',
});
// Send regular transaction
const txResult = await adapter.sendTransaction({
to: 'recipient-address',
value: '1.5',
provider: result.provider,
providerType: 'solana',
});
// Send gasless transaction (sponsored by relayer)
const gaslessTxResult = await adapter.sendTransaction({
to: 'recipient-address',
value: '1.5',
provider: result.provider,
useRelayer: true,
metadata: {
purpose: 'Donation',
referenceId: '12345',
},
});
// Check if a fallback was used
if (gaslessTxResult.usedFallback) {
console.log('Relayer was unavailable, used regular transaction as fallback');
}
The package includes React components and hooks for easy integration into your React application.
First, wrap your application with the SolanaAdapterProvider
:
import {
SolanaAdapterProvider,
ConnectWallet,
WalletBalance,
SignMessage,
SendTransaction,
} from 'sol-gasless-adapter';
function App() {
return (
<SolanaAdapterProvider
connectionSettings="confirmed"
projectId="your-project-id"
// The adapter now uses a default relayer URL (https://sol-relayer.fly.dev/api)
// so you don't need to specify it unless you're using a custom relayer
>
<ConnectWallet />
<WalletBalance />
<SignMessage />
<SendTransaction useRelayer={true} />
</SolanaAdapterProvider>
);
}
When you register your project with our relayer service, you'll receive a unique projectId
that you should include when initializing the adapter. This enables:
- Transaction tracking: Monitor all transactions originating from your application
- Usage analytics: Get insights into user behavior and transaction patterns
- Quota management: Track your relayer usage against your allocated quota
- Error reporting: Receive detailed error reports for failed transactions
To register for a project ID, visit the relayer service dashboard at https://sol-relayer.fly.dev/dashboard and create an account.