> ## 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.

# Signing and Sending Transactions with Solana

There are four functions to sign and send transactions with Solana:

* `signAndSendTransaction`: Sign and send a transaction. Sponsors gas automatically when [SVM Gas Sponsorship](/javascript/reference/solana/svm-gas-sponsorship) is enabled in project settings and the wallet supports it; otherwise sends a regular transaction.
* `signAndSendSponsoredTransaction`: Sign and send a sponsored transaction. Throws if sponsorship is not available.
* `signTransaction`: Sign a transaction
* `signAllTransactions`: Sign multiple transactions

## Usage

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={"system"}
    import {
      signAndSendTransaction,
      signAndSendSponsoredTransaction,
      signTransaction,
      signAllTransactions,
    } from '@dynamic-labs-sdk/solana';

    const sendTransaction = async (walletAccount, transaction) => {
      const { signature } = await signAndSendTransaction({ transaction, walletAccount });
      console.log('Transaction sent successfully.', signature);
    };

    const sendSponsoredTransaction = async (walletAccount, transaction) => {
      const { signature } = await signAndSendSponsoredTransaction({ transaction, walletAccount });
      console.log('Sponsored transaction sent successfully.', signature);
    };

    const signTx = async (walletAccount, transaction) => {
      const { signedTransaction } = await signTransaction({ transaction, walletAccount });
      console.log('Transaction signed successfully.', signedTransaction);
    };

    const signTransactions = async (walletAccount, transactions) => {
      const { signedTransactions } = await signAllTransactions({ transactions, walletAccount });
      console.log('Transactions signed successfully.', signedTransactions);
    };
    ```
  </Tab>

  <Tab title="React">
    Use `useGetWalletAccounts` from `@dynamic-labs-sdk/react-hooks` to reactively get the active wallet, then call transaction functions inside button handlers:

    ```tsx theme={"system"}
    import { signAndSendTransaction } from '@dynamic-labs-sdk/solana';
    import { useGetWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
    import { useState } from 'react';

    function SendSolanaButton({ transaction }) {
      const { data: walletAccounts = [] } = useGetWalletAccounts();
      const walletAccount = walletAccounts[0];
      const [signature, setSignature] = useState('');

      const handleSend = async () => {
        if (!walletAccount) return;
        const { signature } = await signAndSendTransaction({ transaction, walletAccount });
        setSignature(signature);
        console.log('Transaction sent:', signature);
      };

      return (
        <div>
          <button onClick={handleSend} disabled={!walletAccount}>
            Send Transaction
          </button>
          {signature && <p>Signature: {signature}</p>}
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

## Gas Sponsorship

`signAndSendTransaction` honors the project's SVM gas sponsorship setting by default. When sponsorship is enabled in the dashboard and the wallet provider supports it (embedded V3 MPC wallets), the transaction is sponsored automatically. Otherwise, it sends a regular transaction.

Use the `sponsorshipMode` option to control this behavior on a per-call basis:

* `'auto'` (default): sponsor when project settings and the wallet support it, otherwise send a regular transaction.
* `'off'`: never sponsor, regardless of project settings.

```javascript theme={"system"}
// Explicitly skip sponsorship for this call.
const { signature } = await signAndSendTransaction({
  sponsorshipMode: 'off',
  transaction,
  walletAccount,
});
```

To **require** sponsorship (and throw if it isn't available), use [`signAndSendSponsoredTransaction`](/javascript/reference/solana/svm-gas-sponsorship) instead. See [SVM Gas Sponsorship](/javascript/reference/solana/svm-gas-sponsorship) for details.

## Error Handling

* If the specified wallet account is not a `SolanaWalletAccount`, it will throw a `NotSolanaProviderError` error.

* If the specified wallet account is not available for signing (e.g. wallet is an external wallet and the specific account is not the active one in the wallet app, or not connected to your app),
  it will throw a `WalletAccountNotSelectedError` error, stating what is the expected account address to be used, and the active account address in the wallet app (if available).

* If `signAndSendSponsoredTransaction` is called on a wallet that does not support sponsorship (e.g. an external wallet), it will throw a `SponsorTransactionError`.

## Related functions

* [SVM Gas Sponsorship](/javascript/reference/solana/svm-gas-sponsorship)
* [Getting Solana connection](/javascript/reference/solana/getting-solana-connection)
* [Adding Solana extensions](/javascript/reference/solana/adding-solana-extensions)
