Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

Use isSolanaGasSponsorshipEnabled to check if SVM gas sponsorship is enabled in your project settings before attempting to send sponsored transactions.

Usage

import { isSolanaGasSponsorshipEnabled } from '@dynamic-labs-sdk/solana';

const sendTransaction = async (walletAccount, transaction) => {
  if (isSolanaGasSponsorshipEnabled()) {
    // Use sponsored transaction
    const { signature } = await signAndSendSponsoredTransaction({
      transaction,
      walletAccount,
    });
    return signature;
  }

  // Fall back to regular transaction
  const { signature } = await signAndSendTransaction({
    transaction,
    walletAccount,
  });
  return signature;
};

Return value

TypeDescription
booleantrue if SVM gas sponsorship is enabled, false otherwise

Requirements

  • A Dynamic Client must be initialized before calling this function
  • SVM gas sponsorship must be enabled in the Dynamic Dashboard under Settings > Embedded Wallets

React

isSolanaGasSponsorshipEnabled is synchronous and works the same in React. Use it inside a button handler to decide which send function to call:
import { isSolanaGasSponsorshipEnabled } from '@dynamic-labs-sdk/solana';
import { signAndSendSponsoredTransaction, signAndSendTransaction, isSolanaWalletAccount } from '@dynamic-labs-sdk/solana';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';

function SendButton({ transaction }) {
  const walletAccounts = useWalletAccounts();
  const walletAccount = walletAccounts.find(isSolanaWalletAccount);

  const handleSend = async () => {
    if (!walletAccount) return;

    if (isSolanaGasSponsorshipEnabled()) {
      await signAndSendSponsoredTransaction({ transaction, walletAccount });
    } else {
      await signAndSendTransaction({ transaction, walletAccount });
    }
  };

  return (
    <button onClick={handleSend} disabled={!walletAccount}>
      Send {isSolanaGasSponsorshipEnabled() ? '(Sponsored)' : ''}
    </button>
  );
}