sol-gasless-adapter
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

Sol-Gasless-Adapter

A Solana adapter for Gasless Relayer, providing a simple and consistent interface for interacting with Solana wallets and the Solana blockchain.

Features

  • 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

Installation

npm install sol-gasless-adapter
# or
yarn add sol-gasless-adapter

Usage

Basic Usage

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');
}

React Integration

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>
  );
}

Project ID for Transaction Tracking

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:

  1. Transaction tracking: Monitor all transactions originating from your application
  2. Usage analytics: Get insights into user behavior and transaction patterns
  3. Quota management: Track your relayer usage against your allocated quota
  4. 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.

Package Sidebar

Install

npm i sol-gasless-adapter

Weekly Downloads

93

Version

1.3.0

License

MIT

Unpacked Size

59.4 kB

Total Files

33

Last publish

Collaborators

  • 0xmusashi