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

# isGasSponsorshipError

# isGasSponsorshipError

A type guard function that checks if an error is related to gas sponsorship policies. This is useful for handling cases where a transaction was expected to be sponsored but didn't match any sponsorship policies.

## Usage

```javascript theme={"system"}
import {
  createKernelClientForWalletAccount,
  isGasSponsorshipError
} from "@dynamic-labs-sdk/zerodev";
import { isEvmWalletAccount } from "@dynamic-labs-sdk/evm";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";
import { parseEther } from "viem";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isEvmWalletAccount(walletAccount)) {
  const kernelClient = await createKernelClientForWalletAccount({
    smartWalletAccount: walletAccount,
  });

  try {
    await kernelClient.sendTransaction({
      to: recipientAddress,
      value: parseEther("0.01"),
    });
  } catch (error) {
    if (isGasSponsorshipError(error)) {
      console.log("Transaction not sponsored - user needs to pay gas");
      // Handle by retrying without sponsorship or showing user a message
    } else {
      throw error;
    }
  }
}
```

## Parameters

| Parameter | Type      | Description        |
| --------- | --------- | ------------------ |
| `err`     | `unknown` | The error to check |

## Returns

`boolean` - Returns `true` if the error is a gas sponsorship error, `false` otherwise.

## React

Use `isGasSponsorshipError` inside a button handler's catch block to show appropriate UI when sponsorship fails:

```tsx theme={"system"}
import { createKernelClientForWalletAccount, isGasSponsorshipError } from '@dynamic-labs-sdk/zerodev';
import { isEvmWalletAccount } from '@dynamic-labs-sdk/evm';
import { useGetWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';
import { parseEther } from 'viem';

function SendButton({ recipientAddress }) {
  const { data: walletAccounts = [] } = useGetWalletAccounts();
  const walletAccount = walletAccounts.find(isEvmWalletAccount);
  const [error, setError] = useState('');

  const handleSend = async () => {
    if (!walletAccount) return;
    setError('');
    try {
      const kernelClient = await createKernelClientForWalletAccount({ smartWalletAccount: walletAccount });
      await kernelClient.sendTransaction({ to: recipientAddress, value: parseEther('0.01') });
    } catch (err) {
      if (isGasSponsorshipError(err)) {
        setError('This transaction cannot be sponsored. The user must pay gas.');
      } else {
        throw err;
      }
    }
  };

  return (
    <div>
      <button onClick={handleSend} disabled={!walletAccount}>Send</button>
      {error && <p style={{ color: 'orange' }}>{error}</p>}
    </div>
  );
}
```

## Related functions

* [canSponsorTransaction](/javascript/reference/zerodev/can-sponsor-user-operation) - Check if a transaction can be sponsored before sending
* [createKernelClientForWalletAccount](/javascript/reference/zerodev/create-kernel-client-for-wallet-account) - Create a ZeroDev Kernel client
